You are here

function ds_theme_registry_alter in Display Suite 8.2

Same name and namespace in other branches
  1. 8.4 ds.module \ds_theme_registry_alter()
  2. 8.3 ds.module \ds_theme_registry_alter()
  3. 7.2 ds.module \ds_theme_registry_alter()
  4. 7 ds.module \ds_theme_registry_alter()

Implements hook_theme_registry_alter().

File

./ds.module, line 76
Display Suite core functions.

Code

function ds_theme_registry_alter(&$theme_registry) {
  $layouts = Ds::getLayouts();
  $layout_theme_hooks = [];
  foreach ($layouts as $info) {
    if ($info['class'] == '\\Drupal\\ds\\Plugin\\DsLayout') {
      $layout_theme_hooks[] = $info['theme'];
    }
  }

  // Only add preprocess functions if entity exposes theme function, and this
  // layout is using the Display Suite layout class.
  foreach ($theme_registry as $theme_hook => $info) {
    if (in_array($theme_hook, $layout_theme_hooks) || !empty($info['base hook']) && in_array($info['base hook'], $layout_theme_hooks)) {
      $theme_registry[$theme_hook]['preprocess functions'][] = 'ds_preprocess_ds_layout';
    }
  }

  // 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']);
    if (!empty($key)) {
      unset($theme_registry['field']['preprocess functions'][$key]);
    }
  }
}