Same name and namespace in other branches
  1. 8.x-1.x src/Form/EntityCloneForm.php \Drupal\entity_clone\Form\EntityCloneForm::submitForm()

Fichier

src/Form/EntityCloneForm.php, line 201

Classe

EntityCloneForm
Implements an entity Clone form.

Namespace

Drupal\entity_clone\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
    
    /** @var \Drupal\entity_clone\EntityClone\EntityCloneInterface $entity_clone_handler */
    $entity_clone_handler = $this->entityTypeManager
        ->getHandler($this->entityTypeDefinition
        ->id(), 'entity_clone');
    if ($this->entityTypeManager
        ->hasHandler($this->entityTypeDefinition
        ->id(), 'entity_clone_form')) {
        $entity_clone_form_handler = $this->entityTypeManager
            ->getHandler($this->entityTypeDefinition
            ->id(), 'entity_clone_form');
    }
    $properties = [];
    if (isset($entity_clone_form_handler) && $entity_clone_form_handler) {
        $properties = $entity_clone_form_handler->getValues($form_state);
    }
    $duplicate = $this->entity
        ->createDuplicate();
    $this->eventDispatcher
        ->dispatch(new EntityCloneEvent($this->entity, $duplicate, $properties), EntityCloneEvents::PRE_CLONE);
    $cloned_entity = $entity_clone_handler->cloneEntity($this->entity, $duplicate, $properties);
    $this->eventDispatcher
        ->dispatch(new EntityCloneEvent($this->entity, $duplicate, $properties), EntityCloneEvents::POST_CLONE);
    $this->messenger
        ->addMessage($this->stringTranslationManager
        ->translate('The entity <em>@entity (@entity_id)</em> of type <em>@type</em> was cloned.', [
        '@entity' => $this->entity
            ->label(),
        '@entity_id' => $this->entity
            ->id(),
        '@type' => $this->entity
            ->getEntityTypeId(),
    ]));
    $this->formSetRedirect($form_state, $cloned_entity);
}