You are here

public function ElementClassTrait::setEntityClass in Element Class Formatter 8

Set the class on the entity.

Parameters

array $elements: The original elements render array.

string $class: The class string.

\Drupal\Core\Entity\EntityInterface[] $entities: The referenced entities.

Return value

array The updated elements render array.

1 call to ElementClassTrait::setEntityClass()
ElementEntityClassTrait::viewElements in src/Plugin/Field/FieldFormatter/ElementEntityClassTrait.php

File

src/Plugin/Field/FieldFormatter/ElementClassTrait.php, line 111

Class

ElementClassTrait
Trait ElementClassTrait.

Namespace

Drupal\element_class_formatter\Plugin\Field\FieldFormatter

Code

public function setEntityClass(array $elements, $class, array $entities) {
  foreach ($entities as $delta => $entity) {

    // Add class.
    if (!empty($class)) {
      $elements[$delta]['#item_attributes']['class'][] = $class;
    }
  }
  return $elements;
}