function _media_library_configure_form_display

Same name and namespace in other branches
  1. 8.9.x core/modules/media_library/media_library.module \_media_library_configure_form_display()
  2. 10 core/modules/media_library/media_library.module \_media_library_configure_form_display()
  3. 11.x core/modules/media_library/media_library.module \_media_library_configure_form_display()

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

2 calls to _media_library_configure_form_display()
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/media_library.module, line 392

Code

function _media_library_configure_form_display(MediaTypeInterface $type) {
    $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.