function _media_library_configure_view_display
Same name in other branches
- 9 core/modules/media_library/media_library.module \_media_library_configure_view_display()
- 10 core/modules/media_library/media_library.module \_media_library_configure_view_display()
- 11.x core/modules/media_library/media_library.module \_media_library_configure_view_display()
Ensures that the given media type has a media_library view display.
Parameters
\Drupal\media\MediaTypeInterface $type: The media type to configure.
Return value
bool Whether a view display has been created or not.
Throws
\Drupal\Core\Entity\EntityStorageException
3 calls to _media_library_configure_view_display()
- media_library_install in core/
modules/ media_library/ media_library.install - Implements hook_install().
- media_library_post_update_display_modes in core/
modules/ media_library/ media_library.post_update.php - Create and configure Media Library form and view displays for media types.
- _media_library_media_type_form_submit in core/
modules/ media_library/ media_library.module - Submit callback for media type form.
File
-
core/
modules/ media_library/ media_library.module, line 443
Code
function _media_library_configure_view_display(MediaTypeInterface $type) {
$display = EntityViewDisplay::load('media.' . $type->id() . '.media_library');
if ($display) {
return FALSE;
}
$values = [
'targetEntityType' => 'media',
'bundle' => $type->id(),
'mode' => 'media_library',
'status' => TRUE,
];
$display = EntityViewDisplay::create($values);
// Remove all default components.
foreach (array_keys($display->getComponents()) as $name) {
$display->removeComponent($name);
}
// @todo: Remove dependency on 'medium' and 'thumbnail' image styles from
// media and media library modules.
// https://www.drupal.org/project/drupal/issues/3030437
$image_style = ImageStyle::load('medium');
// Expose the thumbnail component. If the medium image style doesn't exist,
// use the fallback 'media_library' image style.
$display->setComponent('thumbnail', [
'type' => 'image',
'label' => 'hidden',
'settings' => [
'image_style' => $image_style ? $image_style->id() : 'media_library',
'image_link' => '',
],
]);
return (bool) $display->save();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.