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

Fichier

src/Form/EntityCloneForm.php, line 151

Classe

EntityCloneForm
Implements an entity Clone form.

Namespace

Drupal\entity_clone\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
    if ($this->entity && $this->entityTypeDefinition
        ->hasHandlerClass('entity_clone')) {
        
        /** @var \Drupal\entity_clone\EntityClone\EntityCloneFormInterface $entity_clone_handler */
        if ($this->entityTypeManager
            ->hasHandler($this->entityTypeDefinition
            ->id(), 'entity_clone_form')) {
            $entity_clone_form_handler = $this->entityTypeManager
                ->getHandler($this->entityTypeDefinition
                ->id(), 'entity_clone_form');
            $form = array_merge($form, $entity_clone_form_handler->formElement($this->entity));
        }
        $entityType = $this->getEntity()
            ->getEntityTypeId();
        if ($this->serviceProvider
            ->entityTypeHasOwnerTrait($this->getEntity()
            ->getEntityType()) && $this->currentUser
            ->hasPermission('take_ownership_on_clone ' . $entityType . ' entity')) {
            $form['take_ownership'] = [
                '#type' => 'checkbox',
                '#title' => $this->stringTranslationManager
                    ->translate('Take ownership'),
                '#default_value' => $this->entityCloneSettingsManager
                    ->getTakeOwnershipSetting(),
                '#description' => $this->stringTranslationManager
                    ->translate('Take ownership of the newly created cloned entity.'),
            ];
            $form['no_suffix'] = [
                '#type' => 'checkbox',
                '#title' => $this->t('Exclude Cloned'),
                '#description' => $this->t('Exclude " - Cloned" from title of cloned entity.'),
                '#default_value' => $this->entityCloneSettingsManager
                    ->getExcludeClonedSetting(),
            ];
        }
        $form['actions'] = [
            '#type' => 'actions',
        ];
        $form['actions']['clone'] = [
            '#type' => 'submit',
            '#button_type' => 'primary',
            '#value' => $this->stringTranslationManager
                ->translate('Clone'),
        ];
        $form['actions']['abort'] = [
            '#type' => 'submit',
            '#value' => $this->stringTranslationManager
                ->translate('Cancel'),
            '#submit' => [
                '::cancelForm',
            ],
        ];
    }
    return $form;
}