function lightning_media_field_widget_entity_browser_entity_reference_form_alter in Lightning Media 8.2
Same name and namespace in other branches
- 8.4 lightning_media.module \lightning_media_field_widget_entity_browser_entity_reference_form_alter()
- 8 lightning_media.module \lightning_media_field_widget_entity_browser_entity_reference_form_alter()
- 8.3 lightning_media.module \lightning_media_field_widget_entity_browser_entity_reference_form_alter()
Implements hook_field_widget_WIDGET_TYPE_form_alter().
File
- ./
lightning_media.module, line 108 - Core media asset support for Lightning.
Code
function lightning_media_field_widget_entity_browser_entity_reference_form_alter(array &$element, FormStateInterface $form_state, array $context) {
// Move the remaining number of selections to the details summary.
if (isset($element['current']['#prefix'])) {
$element['#description'] .= $element['current']['#prefix'];
unset($element['current']['#prefix']);
}
/** @var \Drupal\Core\Field\FieldItemListInterface $items */
$items = $context['items'];
// Wrap the current selections in a nice <details> element.
$cardinality = $items
->getFieldDefinition()
->getFieldStorageDefinition()
->getCardinality();
$element['current']['#theme_wrappers'] = [
'details' => [
'#attributes' => [
'open' => TRUE,
],
'#title' => new Plural($cardinality, 'Current selection', 'Current selections'),
],
];
}