You are here

public function EntityDisplayBulkCloneForm::buildForm in Field tools 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 FormInterface::buildForm

File

src/Form/EntityDisplayBulkCloneForm.php, line 91

Class

EntityDisplayBulkCloneForm
Provides a form to clone displays from an entity bundle.

Namespace

Drupal\field_tools\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $bundle = NULL) {
  $form['displays']['entity_form_display'] = array(
    '#title' => $this
      ->t('Form displays to clone'),
    '#type' => 'checkboxes',
    '#options' => $this
      ->getDisplayOptions('entity_form_display', $entity_type_id, $bundle),
    '#description' => $this
      ->t("Select form displays to clone onto one or more bundles."),
  );
  $form['displays']['entity_view_display'] = array(
    '#title' => $this
      ->t('View displays to clone'),
    '#type' => 'checkboxes',
    '#options' => $this
      ->getDisplayOptions('entity_view_display', $entity_type_id, $bundle),
    '#description' => $this
      ->t("Select view displays to clone onto one or more bundles."),
  );
  $entity_type_bundles = $this->entityTypeBundleInfo
    ->getBundleInfo($entity_type_id);
  $destination_bundle_options = [];
  foreach ($entity_type_bundles as $bundle_id => $bundle_info) {
    if ($bundle_id == $bundle) {
      continue;
    }
    $destination_bundle_options[$bundle_id] = $bundle_info['label'];
  }
  natcasesort($destination_bundle_options);
  $form['destination_bundles'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t("Bundle to clone displays to"),
    '#options' => $destination_bundle_options,
  ];
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => $this
      ->t('Clone displays'),
  );
  return $form;
}