Commit 0355b4a9 authored by Kristof De Jaeger's avatar Kristof De Jaeger Committed by Nils Destoop
Browse files

Issue #3075264 by swentel, JasonSafro, anacolautti, Mike Lewis, jcalais,...

Issue #3075264 by swentel, JasonSafro, anacolautti, Mike Lewis, jcalais, daniel.nitsche: Fix upgrade path to account for DS regions
parent ba42e002
Loading
Loading
Loading
Loading
+54 −0
Original line number Diff line number Diff line
@@ -2,22 +2,45 @@

/**
 * @file
 * Update hooks for the Field Group module.
 * Post update functions for Field Group.
 */

/**
 * Set the `region` portion of each field group.
 * Assign a region to Field Groups.
 */
function field_group_update_8301() {
function field_group_post_update_0001() {
  foreach (['entity_form_display', 'entity_view_display'] as $entity_type) {
    foreach (\Drupal::entityTypeManager()->getStorage($entity_type)->loadMultiple() as $display) {
      /** @var \Drupal\Core\Entity\Display\EntityDisplayInterface $display */
      if (in_array('field_group', $display->getThirdPartyProviders())) {
        $field_groups = $display->getThirdPartySettings('field_group');
        $updated = FALSE;

        // Take Display Suite regions into account.
        $has_ds = FALSE;
        $ds_regions = [];
        if ($entity_type == 'entity_view_display' && in_array('ds', $display->getThirdPartyProviders())) {
          $ds = $display->getThirdPartySettings('ds');
          if (!empty($ds['regions'])) {
            foreach ($ds['regions'] as $region_name => $region_fields) {
              foreach ($region_fields as $field_name) {
                $has_ds = TRUE;
                $ds_regions[$field_name] = $region_name;
              }
            }
          }
        }

        $field_groups = $display->getThirdPartySettings('field_group');
        foreach ($field_groups as $group_name => $data) {
          if (!isset($data['region'])) {
            $data['region'] = 'content';
            $region = 'content';
            if ($has_ds) {
              $region = 'hidden';
              if (isset($ds_regions[$group_name])) {
                $region = $ds_regions[$group_name];
              }
            }
            $data['region'] = $region;
            $display->setThirdPartySetting('field_group', $group_name, $data);
            $updated = TRUE;
          }
+2 −0
Original line number Diff line number Diff line
@@ -64,6 +64,8 @@ function field_group_field_ui_form_params($form, EntityDisplayBase $display) {
  elseif (!empty($ds_info['layout']['id'])) {
    $layout = \Drupal::service('plugin.manager.core.layout')->getDefinition($ds_info['layout']['id']);
    $params->available_regions = $layout->getRegionNames();
    // Hidden is an available region too, as weird as it may seems.
    $params->available_regions[] = 'hidden';
    $params->default_region = $layout->getDefaultRegion() ?: 'hidden';
  }
  else {