Commit 5c7ae267 authored by Kristof De Jaeger's avatar Kristof De Jaeger
Browse files

Issue #3308854 by swentel: Field group support

parent 085009d3
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -9,7 +9,8 @@
  "require-dev": {
    "drupal/devel": "5.x-dev",
    "drupal/classy": "^1.0",
    "drupal/stable": "^2.0"
    "drupal/stable": "^2.0",
    "drupal/field_group": "3.x-dev"
  },
  "authors": [
    {
+2 −1
Original line number Diff line number Diff line
@@ -9,3 +9,4 @@ dependencies:
test_dependencies:
  - classy:classy
  - stable:stable
  - field_group:field_group
 No newline at end of file
+7 −5
Original line number Diff line number Diff line
@@ -106,11 +106,6 @@ function ds_theme_registry_alter(&$theme_registry) {
    }
  }

  // Run field group preprocess before ds_entity_view.
  /*if (function_exists('field_group_build_entity_groups')) {
    array_unshift($theme_registry['ds_entity_view']['preprocess functions'], 'field_group_build_entity_groups');
  }*/

  // Remove ds_preprocess_field in case field templates is not enabled.
  if (!\Drupal::config('ds.settings')->get('field_template')) {
    $key = array_search('ds_preprocess_field', $theme_registry['field']['preprocess functions']);
@@ -143,6 +138,13 @@ function ds_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'entity_view_display_alter') {
    unset($implementations['node']);
  }

  // Make sure that we are after field_group for entity_view_alter.
  if ($hook == 'entity_view_alter') {
    $group = $implementations['ds'];
    unset($implementations['ds']);
    $implementations['ds'] = $group;
  }
}

/**
+0 −13
Original line number Diff line number Diff line
@@ -28,19 +28,6 @@ function ds_extras_layout_alter(&$definitions) {
  }
}

/**
 * Implements hook_module_implements_alter().
 */
function ds_extras_module_implements_alter(&$implementations, $hook) {
  // Extra fields.
  $extra_fields_hooks = [
    'field_extra_fields',
  ];
  if (!\Drupal::config('ds_extras.settings')->get('fields_extra') && in_array($hook, $extra_fields_hooks)) {
    unset($implementations['ds_extras']);
  }
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
+28 −1
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Entity\Display\EntityDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Site\Settings;

class EntityViewAlter implements EntityViewAlterInterface {

@@ -78,8 +79,8 @@ class EntityViewAlter implements EntityViewAlterInterface {

    $this->addDsFields($build, $entity, $bundle, $view_mode, $display, $manage_display_settings, $field_permissions);
    $this->implementUiLimit($build, $display);
    $this->buildFieldGroups($build, $entity, $display);
    $this->moveFieldsIntoRegions($build, $manage_display_settings);

  }

  /**
@@ -236,6 +237,32 @@ class EntityViewAlter implements EntityViewAlterInterface {
        }
      }
    }
  }

  /**
   * Build Field Groups, if any.
   *
   * @param $build
   * @param \Drupal\Core\Entity\EntityInterface $entity
   * @param \Drupal\Core\Entity\Display\EntityDisplayInterface $display
   */
  protected function buildFieldGroups(&$build, EntityInterface $entity, EntityDisplayInterface $display) {
    if (\Drupal::moduleHandler()->moduleExists('field_group')) {

      // There's a chance field_attach_groups hasn't been called yet. Not 100%
      // sure why that happens, but might be due to the following core bug:
      // https://www.drupal.org/project/drupal/issues/3120298
      // Manual testing is fine, but FieldGroupTest didn't work at all, so
      // we manually call it here. It's wrapped in a setting where the default
      // value comes from \Drupal::state('ds_call_field_group_attach');
      // which returns FALSE by default, but is set to TRUE in the test.
      $ds_call_field_group_attach_default = \Drupal::state()->get('ds_call_field_group_attach', FALSE);
      if (Settings::get('ds_call_field_group_attach', $ds_call_field_group_attach_default)) {
        field_group_entity_view_alter($build, $entity, $display);
      }

      field_group_build_entity_groups($build);
    }
  }

}
 No newline at end of file
Loading