function lightning_media_entity_form_display_presave in Lightning Media 8.3
Same name and namespace in other branches
- 8 lightning_media.module \lightning_media_entity_form_display_presave()
- 8.2 lightning_media.module \lightning_media_entity_form_display_presave()
Implements hook_ENTITY_TYPE_presave().
File
- ./
lightning_media.module, line 528 - Core media asset support for Lightning.
Code
function lightning_media_entity_form_display_presave(EntityFormDisplayInterface $display) {
// Don't do anything during config sync.
if (\Drupal::isConfigSyncing()) {
return;
}
if (!\Drupal::config('lightning_media.settings')
->get('entity_browser.override_widget')) {
return;
}
$filter = function (FieldStorageDefinitionInterface $field) {
return $field
->getType() == 'entity_reference' && $field
->getSetting('target_type') == 'media';
};
$new_components = \Drupal::service('lightning.display_helper')
->getNewFields($display, $filter);
foreach ($new_components as $key => $component) {
$display
->setComponent($key, [
'type' => 'entity_browser_entity_reference',
'weight' => $component['weight'],
'settings' => [
'entity_browser' => 'media_browser',
'field_widget_display' => 'rendered_entity',
'field_widget_edit' => TRUE,
'field_widget_remove' => TRUE,
'selection_mode' => EntityBrowserElement::SELECTION_MODE_APPEND,
'field_widget_display_settings' => [
'view_mode' => 'thumbnail',
],
'open' => TRUE,
],
'region' => 'content',
]);
}
}