function MediaLibraryDisplayManager::configureFormDisplay
Same name and namespace in other branches
- main core/modules/media_library/src/MediaLibraryDisplayManager.php \Drupal\media_library\MediaLibraryDisplayManager::configureFormDisplay()
Ensures that the given media type has a media_library form display.
Parameters
\Drupal\media\MediaTypeInterface $type: The media type to configure.
Return value
bool Whether a form display has been created or not.
Throws
\Drupal\Core\Entity\EntityStorageException
3 calls to MediaLibraryDisplayManager::configureFormDisplay()
- MediaLibraryHooks::mediaTypeFormSubmit in core/
modules/ media_library/ src/ Hook/ MediaLibraryHooks.php - Submit callback for media type form.
- media_library_install in core/
modules/ media_library/ media_library.install - Implements hook_install().
- _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/ src/ MediaLibraryDisplayManager.php, line 31
Class
- MediaLibraryDisplayManager
- The media library form and view display setup.
Namespace
Drupal\media_libraryCode
public static function configureFormDisplay(MediaTypeInterface $type) : bool {
$display = EntityFormDisplay::load('media.' . $type->id() . '.media_library');
if ($display) {
return FALSE;
}
$values = [
'targetEntityType' => 'media',
'bundle' => $type->id(),
'mode' => 'media_library',
'status' => TRUE,
];
$display = EntityFormDisplay::create($values);
// Remove all default components.
foreach (array_keys($display->getComponents()) as $name) {
$display->removeComponent($name);
}
// Expose the name field when it is not mapped.
if (!in_array('name', $type->getFieldMap(), TRUE)) {
$display->setComponent('name', [
'type' => 'string_textfield',
'settings' => [
'size' => 60,
],
]);
}
// If the source field is an image field, expose it so that users can set
// alt and title text.
$source_field = $type->getSource()
->getSourceFieldDefinition($type);
if ($source_field->isDisplayConfigurable('form') && is_a($source_field->getItemDefinition()
->getClass(), ImageItem::class, TRUE)) {
$type->getSource()
->prepareFormDisplay($type, $display);
}
return (bool) $display->save();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.