function MediaLibraryHooks::fieldUiPreconfiguredOptionsAlter

Implements hook_field_ui_preconfigured_options_alter().

File

core/modules/media_library/src/Hook/MediaLibraryHooks.php, line 212

Class

MediaLibraryHooks
Hook implementations for media_library.

Namespace

Drupal\media_library\Hook

Code

public function fieldUiPreconfiguredOptionsAlter(array &$options, $field_type) : void {
    // If the field is not an "entity_reference"-based field, bail out.
    $class = \Drupal::service('plugin.manager.field.field_type')->getPluginClass($field_type);
    if (!is_a($class, EntityReferenceItem::class, TRUE)) {
        return;
    }
    // Set the default field widget for media to be the Media library.
    if (!empty($options['media'])) {
        $options['media']['entity_form_display']['type'] = 'media_library_widget';
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.