You are here

public function EntityDisplayBulkCloneForm::submitForm in Field tools 8

Form submission handler.

Parameters

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

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

Overrides FormInterface::submitForm

File

src/Form/EntityDisplayBulkCloneForm.php, line 173

Class

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

Namespace

Drupal\field_tools\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $destination_bundles = array_filter($form_state
    ->getValue('destination_bundles'));
  $form_display_ids = array_filter($form_state
    ->getValue('entity_form_display'));
  $form_displays_to_clone = $this->entityTypeManager
    ->getStorage('entity_form_display')
    ->loadMultiple($form_display_ids);
  foreach ($form_displays_to_clone as $form_display) {
    foreach ($destination_bundles as $destination_bundle) {
      $this->displayCloner
        ->cloneDisplay($form_display, $destination_bundle);
    }
  }
  $view_display_ids = array_filter($form_state
    ->getValue('entity_view_display'));
  $view_displays_to_clone = $this->entityTypeManager
    ->getStorage('entity_view_display')
    ->loadMultiple($view_display_ids);
  foreach ($view_displays_to_clone as $view_display) {
    foreach ($destination_bundles as $destination_bundle) {
      $this->displayCloner
        ->cloneDisplay($view_display, $destination_bundle);
    }
  }
  $this
    ->messenger()
    ->addMessage(t("The displays have been cloned."));
}