You are here

function ds_update_8005 in Display Suite 8.4

Same name and namespace in other branches
  1. 8.3 ds.install \ds_update_8005()

Fix scrambled fields in the UI

File

./ds.install, line 75
Display Suite install file.

Code

function ds_update_8005() {

  // Fix scrambled fields
  $entity_storage = \Drupal::service('entity_type.manager')
    ->getStorage('entity_view_display');

  /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $entity_display */
  foreach ($entity_storage
    ->loadMultiple() as $entity_display) {
    if ($ds_config = $entity_display
      ->getThirdPartySettings('ds')) {
      $components = $entity_display
        ->getComponents();
      if (empty($ds_config['regions'])) {
        continue;
      }
      foreach ($ds_config['regions'] as $region_name => $fields) {
        foreach ($fields as $field_name) {
          if (isset($components[$field_name])) {
            $options = $components[$field_name];
            $options['region'] = $region_name;
            $entity_display
              ->setComponent($field_name, $options);
          }
        }
      }
      $entity_display
        ->save();
    }
  }
}