32c5b1d27023a1235f2798ef7bf43b8df357fd79
[yaffs-website] / web / core / modules / rest / rest.install
1 <?php
2
3 /**
4  * @file
5  * Install, update and uninstall functions for the rest module.
6  */
7
8 use Drupal\Core\Config\Entity\ConfigEntityType;
9 use Drupal\Core\StringTranslation\TranslatableMarkup;
10
11 /**
12  * Implements hook_requirements().
13  */
14 function rest_requirements($phase) {
15   $requirements = [];
16
17   if (version_compare(PHP_VERSION, '5.6.0', '>=') && version_compare(PHP_VERSION, '7', '<') && ini_get('always_populate_raw_post_data') != -1) {
18     $requirements['always_populate_raw_post_data'] = [
19       'title' => t('always_populate_raw_post_data PHP setting'),
20       'value' => t('Not set to -1.'),
21       'severity' => REQUIREMENT_ERROR,
22       'description' => t('The always_populate_raw_post_data PHP setting should be set to -1 in PHP version 5.6. Please check the <a href="https://php.net/manual/en/ini.core.php#ini.always-populate-raw-post-data">PHP manual</a> for information on how to correct this.'),
23     ];
24   }
25   return $requirements;
26 }
27
28 /**
29  * Install the REST config entity type and fix old settings-based config.
30  *
31  * @see rest_post_update_create_rest_resource_config_entities()
32  */
33 function rest_update_8201() {
34   \Drupal::entityDefinitionUpdateManager()->installEntityType(new ConfigEntityType([
35     'id' => 'rest_resource_config',
36     'label' => new TranslatableMarkup('REST resource configuration'),
37     'config_prefix' => 'resource',
38     'admin_permission' => 'administer rest resources',
39     'label_callback' => 'getLabelFromPlugin',
40     'entity_keys' => ['id' => 'id'],
41     'config_export' => [
42       'id',
43       'plugin_id',
44       'granularity',
45       'configuration',
46     ],
47   ]));
48   \Drupal::state()->set('rest_update_8201_resources', \Drupal::config('rest.settings')->get('resources'));
49   \Drupal::configFactory()->getEditable('rest.settings')
50     ->clear('resources')
51     ->save();
52 }
53
54 /**
55  * Re-save all views with a REST display to add new auth defaults.
56  */
57 function rest_update_8202() {
58   $config_factory = \Drupal::configFactory();
59   foreach ($config_factory->listAll('views.view.') as $view_config_name) {
60     $save = FALSE;
61     $view = $config_factory->getEditable($view_config_name);
62     $displays = $view->get('display');
63     foreach ($displays as $display_name => &$display) {
64       if ($display['display_plugin'] == 'rest_export') {
65         if (!isset($display['display_options']['auth'])) {
66           $display['display_options']['auth'] = [];
67           $save = TRUE;
68         }
69       }
70     }
71     if ($save) {
72       $view->set('display', $displays);
73       $view->save(TRUE);
74     }
75   }
76 }
77
78 /**
79  * Enable BC for EntityResource: continue to use permissions.
80  */
81 function rest_update_8203() {
82   $config_factory = \Drupal::configFactory();
83   $rest_settings = $config_factory->getEditable('rest.settings');
84   $rest_settings->set('bc_entity_resource_permissions', TRUE)
85     ->save(TRUE);
86 }