function media_field_ui_preconfigured_options_alter

Same name and namespace in other branches
  1. 9 core/modules/media/media.module \media_field_ui_preconfigured_options_alter()
  2. 8.9.x core/modules/media/media.module \media_field_ui_preconfigured_options_alter()
  3. 10 core/modules/media/media.module \media_field_ui_preconfigured_options_alter()

Implements hook_field_ui_preconfigured_options_alter().

File

core/modules/media/media.module, line 174

Code

function media_field_ui_preconfigured_options_alter(array &$options, $field_type) {
    // If the field is not an "entity_reference"-based field, bail out.
    
    /** @var \Drupal\Core\Field\FieldTypePluginManager $field_type_manager */
    $field_type_manager = \Drupal::service('plugin.manager.field.field_type');
    $class = $field_type_manager->getPluginClass($field_type);
    if (!is_a($class, 'Drupal\\Core\\Field\\Plugin\\Field\\FieldType\\EntityReferenceItem', TRUE)) {
        return;
    }
    // Set the default formatter for media in entity reference fields to be the
    // "Rendered entity" formatter.
    if (!empty($options['media'])) {
        $options['media']['description'] = t('Field to reference media. Allows uploading and selecting from uploaded media.');
        $options['media']['weight'] = -25;
        $options['media']['category'] = FieldTypeCategoryManagerInterface::FALLBACK_CATEGORY;
        $options['media']['entity_view_display']['type'] = 'entity_reference_entity_view';
    }
}

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