Same name and namespace in other branches
  1. 2.x src/EntityClone/Content/ContentEntityCloneBase.php \Drupal\entity_clone\EntityClone\Content\ContentEntityCloneBase::setClonedEntityLabel()

Sets the cloned entity's label.

Paramètres

\Drupal\Core\Entity\EntityInterface $original_entity: The original entity.

\Drupal\Core\Entity\EntityInterface $cloned_entity: The entity cloned from the original.

array $properties: The properties array.

1 call to ContentEntityCloneBase::setClonedEntityLabel()
ContentEntityCloneBase::cloneEntity dans src/EntityClone/Content/ContentEntityCloneBase.php
Clone an entity.

Fichier

src/EntityClone/Content/ContentEntityCloneBase.php, line 173

Classe

ContentEntityCloneBase
Class Content Entity Clone Base.

Namespace

Drupal\entity_clone\EntityClone\Content

Code

protected function setClonedEntityLabel(EntityInterface $original_entity, EntityInterface $cloned_entity, array $properties) {
    $label_key = $this->entityTypeManager
        ->getDefinition($this->entityTypeId)
        ->getKey('label');
    if ($label_key && $cloned_entity->hasField($label_key)) {
        if (isset($properties['no_suffix']) && $properties['no_suffix'] === 1) {
            $cloned_entity->set($label_key, $original_entity->label());
        }
        else {
            $languages = $cloned_entity->getTranslationLanguages();
            foreach ($languages as $langcode => $language) {
                $translation = $cloned_entity->getTranslation($langcode);
                $translation->set($label_key, $translation->label() . ' - Cloned');
            }
        }
    }
}