public function EntityDisplaySettingsBulkCopyForm::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/ EntityDisplaySettingsBulkCopyForm.php, line 163
Class
- EntityDisplaySettingsBulkCopyForm
- Provides a form to copy displays settings between displays.
Namespace
Drupal\field_tools\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
// Get the original parameters given to buildForm().
// TODO: is this the right way to do this?
$build_info = $form_state
->getBuildInfo();
list($entity_type_id, $bundle) = $build_info['args'];
$values = $form_state
->getValues();
$source_fields = array_filter($values['source_fields']);
list($source_display_type, $source_display_id) = explode(':', $values['source_display']);
$source_display = $this->entityTypeManager
->getStorage($source_display_type)
->load($source_display_id);
$destination_bundles = array_filter($values['destination_bundles']);
$bundle_fields = $this->entityFieldManager
->getFieldDefinitions($entity_type_id, $bundle);
foreach ($source_fields as $source_field_name) {
$field_definition = $bundle_fields[$source_field_name];
foreach ($destination_bundles as $bundle) {
$this->displaySettingsCopier
->copyDisplaySettings($field_definition, $source_display, $bundle);
$this
->messenger()
->addMessage($this
->t("Copied settings for @field-name to @bundle.", [
// TODO: use human-readable labels here.
'@field-name' => $source_field_name,
'@bundle' => $bundle,
]));
}
}
}