You are here

function pathauto_update_8001 in Pathauto 8

Updates pathauto widgets to use the path widget ID.

File

./pathauto.install, line 24
Install, update, and uninstall functions for Pathauto.

Code

function pathauto_update_8001() {

  // Replace values in the 'entity.definitions.installed' keyvalue collection.
  $collection = \Drupal::service('keyvalue')
    ->get('entity.definitions.installed');
  foreach ($collection
    ->getAll() as $key => $definitions) {
    if (!is_array($definitions) || empty($definitions['path'])) {
      continue;
    }

    // Retrieve and change path base field definition.
    $path_definition = $definitions['path'];
    if (($options = $path_definition
      ->getDisplayOptions('form')) && ($options['type'] = 'pathauto')) {
      $options['type'] = 'path';
      $path_definition
        ->setDisplayOptions('form', $options);

      // Save the new value.
      $collection
        ->set($key, $definitions);
    }
  }
  foreach (EntityFormDisplay::loadMultiple() as $form_display) {
    if ($component = $form_display
      ->getComponent('path')) {
      if (isset($component['type']) && $component['type'] == 'pathauto') {
        $component['type'] = 'path';
        $form_display
          ->setComponent('path', $component);
        $form_display
          ->save();
      }
    }
  }
}