function UmamiHooks::preprocessField

Same name and namespace in other branches
  1. main core/profiles/demo_umami/themes/umami/src/Hook/UmamiHooks.php \Drupal\umami\Hook\UmamiHooks::preprocessField()

Implements hook_preprocess_HOOK() for field.

Attributes

#[Hook('preprocess_field')]

File

core/profiles/demo_umami/themes/umami/src/Hook/UmamiHooks.php, line 40

Class

UmamiHooks
Hook implementations for umami.

Namespace

Drupal\umami\Hook

Code

public function preprocessField(&$variables, $hook) : void {
  $element = $variables['element'];
  // Add class to label and items fields to be styled using the meta styles.
  if (isset($element['#field_name'])) {
    if ($element['#field_name'] == 'field_recipe_category' || $element['#field_name'] == 'field_tags' || $element['#field_name'] == 'field_difficulty') {
      $variables['attributes']['class'][] = 'label-items';
      if ($element['#view_mode'] == 'card' && $element['#field_name'] == 'field_difficulty') {
        $variables['attributes']['class'][] = 'umami-card__label-items';
      }
    }
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.