You are here

public function EntityCloneSettingsForm::buildForm in Entity Clone 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/EntityCloneSettingsForm.php, line 61

Class

EntityCloneSettingsForm
Provide the settings form for entity clone.

Namespace

Drupal\entity_clone\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['#tree'] = TRUE;
  $form['form_settings'] = [
    '#tree' => TRUE,
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Clone form settings'),
    '#description' => $this
      ->t("\n        For each type of child entity (the entity that's referenced by the entity being\n        cloned), please set your cloning preferences. This will affect the clone form presented to users when they\n        clone entities. Default behaviour for whether or not the child entities should be cloned is specified in\n        the left-most column.  To prevent users from altering behaviour for each type when they're actually cloning\n        (but still allowing them to see what will happen), use the middle column. The right-most column can be used\n        to hide the form options from users completely. This will run the clone operation with the defaults set here\n        (in the left-most column). See the clone form (by cloning an entity) for more information.\n      "),
    '#open' => TRUE,
    '#collapsible' => FALSE,
  ];
  $form['form_settings']['table'] = [
    '#type' => 'table',
    '#header' => [
      'label' => $this
        ->t('Label'),
      'default_value' => $this
        ->t('Checkboxes default value'),
      'disable' => $this
        ->t('Disable checkboxes'),
      'hidden' => $this
        ->t('Hide checkboxes'),
    ],
  ];
  foreach ($this->entityCloneSettingsManager
    ->getContentEntityTypes() as $type_id => $type) {
    $form['form_settings']['table'][$type_id] = [
      'label' => [
        '#type' => 'label',
        '#title' => $this
          ->t('@type', [
          '@type' => $type
            ->getLabel(),
        ]),
      ],
      'default_value' => [
        '#type' => 'checkbox',
        '#default_value' => $this->entityCloneSettingsManager
          ->getDefaultValue($type_id),
      ],
      'disable' => [
        '#type' => 'checkbox',
        '#default_value' => $this->entityCloneSettingsManager
          ->getDisableValue($type_id),
      ],
      'hidden' => [
        '#type' => 'checkbox',
        '#default_value' => $this->entityCloneSettingsManager
          ->getHiddenValue($type_id),
      ],
    ];
  }
  $form['take_ownership'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Take ownership'),
    '#description' => $this
      ->t('Whether the "Take ownership" option should be checked by default on the entity clone form.'),
    '#default_value' => $this->entityCloneSettingsManager
      ->getTakeOwnershipSetting(),
  ];
  return parent::buildForm($form, $form_state);
}