You are here

function auto_entitylabel_entity_prepare_view in Automatic Entity Label 8.2

Same name and namespace in other branches
  1. 8.3 auto_entitylabel.module \auto_entitylabel_entity_prepare_view()
  2. 8 auto_entitylabel.module \auto_entitylabel_entity_prepare_view()

Implements hook_entity_prepare_view().

File

./auto_entitylabel.module, line 121
Allows hiding of entity label fields and automatic label creation.

Code

function auto_entitylabel_entity_prepare_view($entity_type_id, array $entities, array $displays, $view_mode) {
  foreach ($entities as $entity) {
    if ($entity->in_preview === TRUE && $entity instanceof ContentEntityInterface) {
      $decorator = \Drupal::service('auto_entitylabel.entity_decorator');

      /** @var \Drupal\auto_entitylabel\AutoEntityLabelManager $decorated_entity */
      $decorated_entity = $decorator
        ->decorate($entity);
      if ($decorated_entity
        ->hasLabel() && $decorated_entity
        ->autoLabelNeeded()) {
        $decorated_entity
          ->setLabel();
      }
    }
  }
}