You are here

function name_update_8001 in Name Field 8

Upgrade from Drupal 7 to Drupal 8.

File

./name.install, line 20
Standard installation functions for name.

Code

function name_update_8001() {
  $database = \Drupal::database();
  $query = $database
    ->query("SELECT * FROM {name_custom_format} ORDER BY name ASC");
  $result = $query
    ->fetchAll();
  foreach ($result as $row) {
    \Drupal::config('name_format.' . $row->machine_name)
      ->set('id', $row->machine_name)
      ->set('label', $row->name)
      ->set('pattern', $row->format)
      ->save();
  }
  $settings = update_variable_get('name_settings', [
    'default_format' => '((((t+ig)+im)+if)+is)+jc',
    'sep1' => ' ',
    'sep2' => ', ',
    'sep3' => '',
  ]);
  \Drupal::config('name_format.default')
    ->set('id', 'default')
    ->set('label', 'default')
    ->set('pattern', $settings['default_format'])
    ->set('locked', 1)
    ->save();
  \Drupal::config('name.settings')
    ->set('sep1', $settings['sep1'])
    ->set('sep2', $settings['sep2'])
    ->set('sep3', $settings['sep3'])
    ->save();

  // @todo: migrate these.
  variable_del('name_settings');
  variable_del('name_user_preferred');

  // There is no UI for this setting.
  variable_del('name_example_names');
  variable_del('name_inline_styles');
  variable_del('name_inline_styles_rtl');
  variable_del('name_element_wrapper');
  variable_del('name_component_required_marker');
  $database
    ->schema()
    ->dropTable('name_custom_format');
}