function MediaLibraryWidget::settingsForm
Same name in other branches
- 9 core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php \Drupal\media_library\Plugin\Field\FieldWidget\MediaLibraryWidget::settingsForm()
- 10 core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php \Drupal\media_library\Plugin\Field\FieldWidget\MediaLibraryWidget::settingsForm()
- 11.x core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php \Drupal\media_library\Plugin\Field\FieldWidget\MediaLibraryWidget::settingsForm()
Overrides WidgetBase::settingsForm
File
-
core/
modules/ media_library/ src/ Plugin/ Field/ FieldWidget/ MediaLibraryWidget.php, line 185
Class
- MediaLibraryWidget
- Plugin implementation of the 'media_library_widget' widget.
Namespace
Drupal\media_library\Plugin\Field\FieldWidgetCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$media_type_ids = $this->getAllowedMediaTypeIdsSorted();
if (count($media_type_ids) <= 1) {
return $form;
}
$form['media_types'] = [
'#type' => 'table',
'#header' => [
$this->t('Tab order'),
$this->t('Weight'),
],
'#tabledrag' => [
[
'action' => 'order',
'relationship' => 'sibling',
'group' => 'weight',
],
],
'#value_callback' => [
static::class,
'setMediaTypesValue',
],
];
$media_types = $this->entityTypeManager
->getStorage('media_type')
->loadMultiple($media_type_ids);
$weight = 0;
foreach ($media_types as $media_type_id => $media_type) {
$label = $media_type->label();
$form['media_types'][$media_type_id] = [
'label' => [
'#markup' => $label,
],
'weight' => [
'#type' => 'weight',
'#title' => t('Weight for @title', [
'@title' => $label,
]),
'#title_display' => 'invisible',
'#default_value' => $weight,
'#attributes' => [
'class' => [
'weight',
],
],
],
'#weight' => $weight,
'#attributes' => [
'class' => [
'draggable',
],
],
];
$weight++;
}
return $form;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.