You are here

function auto_entitylabel_inline_entity_label_callback in Automatic Entity Label 8.3

A callback function to provide autoentitylabel for inline entity form.

1 string reference to 'auto_entitylabel_inline_entity_label_callback'
auto_entitylabel_inline_entity_form_table_fields_alter in ./auto_entitylabel.module
Implements hook_inline_entity_form_table_fields_alter().

File

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

Code

function auto_entitylabel_inline_entity_label_callback($entity, $variables) {
  $autolabel = $entity
    ->label();
  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()) {
      $autolabel = $decorated_entity
        ->setLabel();
    }
  }
  return $autolabel;
}