You are here

protected static function MediaForm::getFieldState in GridStack 8.2

Gets the field state for the widget.

2 calls to MediaForm::getFieldState()
MediaForm::addItems in src/Plugin/gridstack/stylizer/MediaForm.php
Updates the field state and flags the form for rebuild.
MediaForm::removeItem in src/Plugin/gridstack/stylizer/MediaForm.php
Submit callback for remove buttons.

File

src/Plugin/gridstack/stylizer/MediaForm.php, line 645

Class

MediaForm
Provides the media form for Layout Builder integration.

Namespace

Drupal\gridstack\Plugin\gridstack\stylizer

Code

protected static function getFieldState(array $element, FormStateInterface $form_state) {
  $values = self::getUserInputValues($element, $form_state);
  $selection = isset($values['selection']) ? $values['selection'] : [];
  $parents = isset($element['#parents']) ? $element['#parents'] : [];
  $parents = isset($element['#field_parents']) ? $element['#field_parents'] : $parents;
  $widget_state = MediaLibraryWidget::getWidgetState($parents, $element['#field_name'], $form_state);
  $widget_state['items'] = isset($widget_state['items']) ? $widget_state['items'] : $selection;
  return $widget_state;
}