summaryrefslogtreecommitdiffstats
path: root/core/modules/serialization/serialization.install
blob: f5a11b88052faafff4b4ef043da0d69938598a89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php

/**
 * @file
 * Update functions for the Serialization module.
 */

/**
 * Implements hook_requirements().
 */
function serialization_requirements($phase) {
  $requirements = [];

  if ($phase == 'runtime') {
    $requirements['serialization_as_strings'] = [
      'title' => t('Serialized data types'),
      'severity' => REQUIREMENT_INFO,
    ];

    if (\Drupal::config('serialization.settings')->get('bc_primitives_as_strings')) {
      $requirements['serialization_as_strings']['value'] = t('Enabled');
      $requirements['serialization_as_strings']['description'] = t('The Serialization API is configured to output only string values for REST and other applications (instead of integers or Booleans when appropriate). <a href="https://www.drupal.org/node/2837696">Disabling this backwards compatibility mode</a> is recommended unless your sites or applications require string output.');
    }
    else {
      $requirements['serialization_as_strings']['value'] = t('Not enabled');
      $requirements['serialization_as_strings']['description'] = t('The Serialization API is configured with the recommended default and outputs typed values (integers, Booleans, or strings as appropriate) for REST and other applications. If your site or applications require string output, you can <a href="https://www.drupal.org/node/2837696">enable backwards compatibility mode</a>.');
    }
  }

  return $requirements;
}

/**
 * @see hal_update_8301()
 */
function serialization_update_8301() {
}

/**
 * Add serialization.settings::bc_primitives_as_strings configuration.
 */
function serialization_update_8302() {
  $config_factory = \Drupal::configFactory();
  $config_factory->getEditable('serialization.settings')
    ->set('bc_primitives_as_strings', FALSE)
    ->save(TRUE);

  return t('The REST API will no longer output all values as strings. Integers/booleans will be used where appropriate. If your site depends on these value being strings, <a href="https://www.drupal.org/node/2837696">read the change record to learn how to enable the BC mode.</a>');
}

/**
 * Enable BC for timestamp formatting: continue to return UNIX timestamps.
 */
function serialization_update_8401() {
  $config_factory = \Drupal::configFactory();
  $serialization_settings = $config_factory->getEditable('serialization.settings');
  $serialization_settings->set('bc_timestamp_normalizer_unix', TRUE)->save(TRUE);
}