|
22 | 22 | id: 'layout_library_icons', |
23 | 23 | label: new TranslatableMarkup('Layout Library Icons'), |
24 | 24 | field_types: ['entity_reference'], |
| 25 | + multiple_values: TRUE, |
25 | 26 | )] |
26 | 27 | class LayoutLibraryIconsWidget extends OptionsWidgetBase { |
27 | 28 |
|
@@ -57,11 +58,19 @@ public static function create(ContainerInterface $container, array $configuratio |
57 | 58 | ); |
58 | 59 | } |
59 | 60 |
|
| 61 | + /** |
| 62 | + * {@inheritdoc} |
| 63 | + */ |
| 64 | + public static function isApplicable(FieldDefinitionInterface $field_definition) { |
| 65 | + return $field_definition->getName() == 'layout_selection'; |
| 66 | + } |
| 67 | + |
60 | 68 | /** |
61 | 69 | * {@inheritdoc} |
62 | 70 | */ |
63 | 71 | public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) { |
64 | 72 | $element = parent::formElement($items, $delta, $element, $form, $form_state); |
| 73 | + |
65 | 74 | $options = $this->getOptions($items->getEntity()); |
66 | 75 | /** @var \Drupal\layout_library\Entity\Layout[] $layouts */ |
67 | 76 | $layouts = $this->entityTypeManager->getStorage('layout') |
@@ -93,10 +102,11 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen |
93 | 102 | $options['_none'] .= $this->renderer->render($image); |
94 | 103 | } |
95 | 104 |
|
| 105 | + $selectedOption = $this->getSelectedOptions($items); |
96 | 106 | $element += [ |
97 | 107 | '#type' => 'radios', |
98 | 108 | '#options' => $options, |
99 | | - '#default_value' => $this->getSelectedOptions($items) ?: '_none', |
| 109 | + '#default_value' => $selectedOption[0] ?? '_none', |
100 | 110 | '#attached' => ['library' => ['stanford_profile_helper/layout_library_icon_widget']], |
101 | 111 | '#attributes' => ['class' => ['layout-library-icons']], |
102 | 112 | ]; |
|
0 commit comments