You are here

function field_group_theme_registry_alter in Field Group 8.3

Same name and namespace in other branches
  1. 8 field_group.module \field_group_theme_registry_alter()
  2. 7.2 field_group.module \field_group_theme_registry_alter()
  3. 7 field_group.module \field_group_theme_registry_alter()

Implements hook_theme_registry_alter().

File

./field_group.module, line 57
Allows administrators to attach field groups.

Code

function field_group_theme_registry_alter(&$theme_registry) {

  // Inject field_group_build_entity_groups in all entity theming functions.
  $entity_info = Drupal::entityTypeManager()
    ->getDefinitions();
  $entity_types = [];
  foreach ($entity_info as $entity_type_id => $entity_type) {
    if ($route_name = $entity_type
      ->get('field_ui_base_route')) {
      $entity_types[] = $entity_type_id;
    }
  }
  foreach ($theme_registry as $theme_hook => $info) {
    if (in_array($theme_hook, $entity_types) || !empty($info['base hook']) && in_array($info['base hook'], $entity_types)) {
      $theme_registry[$theme_hook]['preprocess functions'][] = 'field_group_build_entity_groups';
    }
  }

  // ECK does not use the eck as theme function.
  if (isset($theme_registry['eck_entity'])) {
    $theme_registry['eck_entity']['preprocess functions'][] = 'field_group_build_entity_groups';
  }

  // External entities use the external_entity as theme function.
  if (isset($theme_registry['external_entity'])) {
    $theme_registry['external_entity']['preprocess functions'][] = 'field_group_build_entity_groups';
  }
}