function contact_update_8001

Migrate contact categories into configuration.

Related topics

File

drupal/core/modules/contact/contact.install, line 56
Install, update and uninstall functions for the contact module.

Code

function contact_update_8001() {
  $uuid = new Uuid();
  $result = db_query('SELECT * FROM {contact}');
  foreach ($result as $category) {

    // Take over the category's serial ID as new machine name.
    $category->id = $category->cid;

    // Save default category setting.
    if ($category->selected) {
      config('contact.settings')
        ->set('default_category', $category->id)
        ->save();
    }

    // Save the config object.
    config('contact.category.' . $category->id)
      ->set('id', $category->id)
      ->set('uuid', $uuid
      ->generate())
      ->set('label', $category->category)
      ->set('recipients', explode(',', $category->recipients))
      ->set('reply', $category->reply)
      ->set('weight', $category->weight)
      ->set('langcode', Language::LANGCODE_NOT_SPECIFIED)
      ->save();
  }
}