public function EditComponentForm::orphanedItemsElement in Layout Paragraphs 2.0.x
Form #process callback.
Builds the orphaned items form element for when a new layout's regions do not match the previous one's.
Parameters
array $element: The form element.
\Drupal\Core\Form\FormStateInterface $form_state: The form state object.
array $form: The complete form.
Return value
array The form element.
File
- src/
Form/ EditComponentForm.php, line 94
Class
- EditComponentForm
- Class LayoutParagraphsComponentEditForm.
Namespace
Drupal\layout_paragraphs\FormCode
public function orphanedItemsElement(array $element, FormStateInterface $form_state, array &$form) {
$old_regions = $this
->getLayoutRegionNames($element['#old_layout']);
$new_regions = $this
->getLayoutRegionNames($element['#new_layout']);
$section = $this->layoutParagraphsLayout
->getLayoutSection($this->paragraph);
$has_orphans = FALSE;
foreach ($old_regions as $region_name => $region) {
if ($section
->getComponentsForRegion($region_name) && empty($new_regions[$region_name])) {
$has_orphans = TRUE;
$element[$region_name] = [
'#type' => 'select',
'#options' => $new_regions,
'#wrapper_attributes' => [
'class' => [
'container-inline',
],
],
'#title' => $this
->t('Move items from "@region" to', [
'@region' => $region,
]),
];
}
}
if ($has_orphans) {
$element += [
'#type' => 'fieldset',
'#title' => $this
->t('Move Orphaned Items'),
'#description' => $this
->t('Choose where to move items for missing regions.'),
];
}
return $element;
}