You are here

function twigsuggest_theme_suggestions_field_alter in Twig Template Suggester 8

Implements hook_theme_suggestions_HOOK_alter() for field templates.

Add entity reference target type template suggestion.

See also

https://git.drupalcode.org/project/adaptivetheme/-/blob/8.x-3.x/at_core/...

File

./twigsuggest.module, line 293
Twig Template Suggester module hook implementations.

Code

function twigsuggest_theme_suggestions_field_alter(array &$suggestions, array $variables) {

  // Add the entity reference type as a field template suggestion.
  if (isset($variables['element']['#items']) && is_object($variables['element']['#items'])) {
    $target_type = $variables['element']['#items']
      ->getSetting('target_type') ?: NULL;
    if ($target_type !== NULL) {
      array_splice($suggestions, 1, 0, 'field__entity_reference_type__' . $target_type);
    }
  }
}