2222 id: 'layout_library_icons ' ,
2323 label: new TranslatableMarkup ('Layout Library Icons ' ),
2424 field_types: ['entity_reference ' ],
25+ multiple_values: TRUE ,
2526)]
2627class LayoutLibraryIconsWidget extends OptionsWidgetBase {
2728
@@ -57,11 +58,19 @@ public static function create(ContainerInterface $container, array $configuratio
5758 );
5859 }
5960
61+ /**
62+ * {@inheritdoc}
63+ */
64+ public static function isApplicable (FieldDefinitionInterface $ field_definition ) {
65+ return $ field_definition ->getName () == 'layout_selection ' ;
66+ }
67+
6068 /**
6169 * {@inheritdoc}
6270 */
6371 public function formElement (FieldItemListInterface $ items , $ delta , array $ element , array &$ form , FormStateInterface $ form_state ) {
6472 $ element = parent ::formElement ($ items , $ delta , $ element , $ form , $ form_state );
73+
6574 $ options = $ this ->getOptions ($ items ->getEntity ());
6675 /** @var \Drupal\layout_library\Entity\Layout[] $layouts */
6776 $ layouts = $ this ->entityTypeManager ->getStorage ('layout ' )
@@ -93,10 +102,11 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
93102 $ options ['_none ' ] .= $ this ->renderer ->render ($ image );
94103 }
95104
105+ $ selectedOption = $ this ->getSelectedOptions ($ items );
96106 $ element += [
97107 '#type ' => 'radios ' ,
98108 '#options ' => $ options ,
99- '#default_value ' => $ this -> getSelectedOptions ( $ items ) ?: '_none ' ,
109+ '#default_value ' => $ selectedOption [ 0 ] ?? '_none ' ,
100110 '#attached ' => ['library ' => ['stanford_profile_helper/layout_library_icon_widget ' ]],
101111 '#attributes ' => ['class ' => ['layout-library-icons ' ]],
102112 ];
@@ -110,5 +120,9 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
110120 protected function getEmptyLabel () {
111121 return $ this ->t ('- Default - ' );
112122 }
123+ public function massageFormValues (array $ values , array $ form , FormStateInterface $ form_state ) {
124+ dpm ($ values );
125+ return parent ::massageFormValues ($ values , $ form , $ form_state ); // TODO: Change the autogenerated stub
126+ }
113127
114128}
0 commit comments