You are here

entity_extra_field.theme in Entity Extra Field 2.0.x

Same filename and directory in other branches
  1. 8 templates/entity_extra_field.theme

File

templates/entity_extra_field.theme
View source
<?php

/**
 * @file
 * The theme implementation for the entity extra field.
 */
declare (strict_types=1);
use Drupal\entity_extra_field\Entity\EntityExtraFieldInterface;

/**
 * The template entity extra field preprocess.
 *
 * @param array $variables
 *   An array of template variables.
 */
function template_preprocess_entity_extra_field(array &$variables) : void {
  $element = $variables['element'];
  $extra_field = $element['#field'];
  $variables['label'] = $element['label'];
  $variables['content'] = $element['content'];
  $variables['attributes']['class'][] = 'extra-field';
  if ($extra_field instanceof EntityExtraFieldInterface) {
    $field_class_name = entity_extra_field_class_string([
      $extra_field
        ->name(),
    ]);
    $variables['attributes']['class'][] = 'extra-field--' . $field_class_name;
    $variables['attributes']['class'][] = 'extra-field--type-' . $extra_field
      ->getFieldTypePluginId();
  }
  $variables['title_attributes']['class'][] = 'extra-field--label';
  $variables['content_attributes']['class'][] = 'extra-field--content';
}

/**
 * Format values into a class string.
 *
 * @param array $values
 *   An array of class values.
 * @param string $delimiter
 *   A space delimiter to use between concatenated classes.
 *
 * @return string
 *   The concatenated class string.
 */
function entity_extra_field_class_string(array $values, string $delimiter = '-') : string {
  return implode($delimiter, array_map('\\Drupal\\Component\\Utility\\Html::getClass', $values));
}

Functions

Namesort descending Description
entity_extra_field_class_string Format values into a class string.
template_preprocess_entity_extra_field The template entity extra field preprocess.