You are here

function auto_entitylabel_entity_presave in Automatic Entity Label 8.3

Same name and namespace in other branches
  1. 8 auto_entitylabel.module \auto_entitylabel_entity_presave()
  2. 8.2 auto_entitylabel.module \auto_entitylabel_entity_presave()
  3. 7 auto_entitylabel.module \auto_entitylabel_entity_presave()

Implements hook_entity_presave().

File

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

Code

function auto_entitylabel_entity_presave(EntityInterface $entity) {
  if ($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
      ->isTitlePreserved()) {
      $decorated_entity
        ->setLabel();
    }
  }
}