Same name in other branches
  1. 8.x-1.x src/EntityClone/Content/ContentEntityCloneFormBase.php \Drupal\entity_clone\EntityClone\Content\ContentEntityCloneFormBase::formElement()

Overrides EntityCloneFormInterface::formElement

Fichier

src/EntityClone/Content/ContentEntityCloneFormBase.php, line 87

Classe

ContentEntityCloneFormBase
Class Content Entity Clone Form Base.

Namespace

Drupal\entity_clone\EntityClone\Content

Code

public function formElement(EntityInterface $entity, $parent = TRUE, &$discovered_entities = []) {
    $form = [
        'recursive' => [],
    ];
    if ($entity instanceof FieldableEntityInterface) {
        $discovered_entities[$entity->getEntityTypeId()][$entity->id()] = $entity;
        foreach ($entity->getFieldDefinitions() as $field_id => $field_definition) {
            if ($field_definition instanceof FieldConfigInterface && in_array($field_definition->getType(), [
                'entity_reference',
                'entity_reference_revisions',
            ], TRUE)) {
                $field = $entity->get($field_id);
                
                /** @var \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem $value */
                if ($field->count() > 0 && $this->entityTypeManager
                    ->getStorage($field->getSetting('target_type')) instanceof ContentEntityStorageInterface) {
                    $form['recursive'] = array_merge($form['recursive'], $this->getRecursiveFormElement($field_definition, $field_id, $field, $discovered_entities));
                }
            }
        }
        if ($parent) {
            $form = array_merge([
                'description' => [
                    '#markup' => $this->getFormDescription($form, $entity),
                    '#access' => TRUE,
                ],
            ], $form);
        }
    }
    return $form;
}