function MediaLibraryWidget::setFieldState

Same name in other branches
  1. 8.9.x core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php \Drupal\media_library\Plugin\Field\FieldWidget\MediaLibraryWidget::setFieldState()
  2. 10 core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php \Drupal\media_library\Plugin\Field\FieldWidget\MediaLibraryWidget::setFieldState()
  3. 11.x core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php \Drupal\media_library\Plugin\Field\FieldWidget\MediaLibraryWidget::setFieldState()

Sets the field state for the widget.

Parameters

array $element: The wrapping element for this widget.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

array[] $field_state: An array of arrays with the following key/value pairs:

  • items: (array) An array of selections.

    • target_id: (int) A media entity ID.
    • weight: (int) A weight for the selection.
2 calls to MediaLibraryWidget::setFieldState()
MediaLibraryWidget::addItems in core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php
Updates the field state and flags the form for rebuild.
MediaLibraryWidget::removeItem in core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php
Submit callback for remove buttons.

File

core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php, line 992

Class

MediaLibraryWidget
Plugin implementation of the 'media_library_widget' widget.

Namespace

Drupal\media_library\Plugin\Field\FieldWidget

Code

protected static function setFieldState(array $element, FormStateInterface $form_state, array $field_state) {
    static::setWidgetState($element['#field_parents'], $element['#field_name'], $form_state, $field_state);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.