diff -u b/core/modules/media/config/schema/media.schema.yml b/core/modules/media/config/schema/media.schema.yml --- b/core/modules/media/config/schema/media.schema.yml +++ b/core/modules/media/config/schema/media.schema.yml @@ -56,6 +56,10 @@ type: field.formatter.settings.image label: 'Media thumbnail field display format settings' +media.handler.*: + type: mapping + label: 'Media handler plugin settings' + media.handler.field_aware: type: mapping mapping: diff -u b/core/modules/media/media.services.yml b/core/modules/media/media.services.yml --- b/core/modules/media/media.services.yml +++ b/core/modules/media/media.services.yml @@ -8 +8 @@ - arguments: ['@entity_type.manager'] + arguments: ['@entity_type.manager', '@string_translation'] diff -u b/core/modules/media/src/Entity/MediaType.php b/core/modules/media/src/Entity/MediaType.php --- b/core/modules/media/src/Entity/MediaType.php +++ b/core/modules/media/src/Entity/MediaType.php @@ -39,7 +39,8 @@ * bundle_of = "media", * entity_keys = { * "id" = "id", - * "label" = "label" + * "label" = "label", + * "status" = "status" * }, * config_export = { * "id", diff -u b/core/modules/media/src/MediaForm.php b/core/modules/media/src/MediaForm.php --- b/core/modules/media/src/MediaForm.php +++ b/core/modules/media/src/MediaForm.php @@ -4,7 +4,6 @@ use Drupal\Core\Entity\ContentEntityForm; use Drupal\Core\Form\FormStateInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; /** * Form controller for the media edit forms. diff -u b/core/modules/media/src/MediaHandlerBase.php b/core/modules/media/src/MediaHandlerBase.php --- b/core/modules/media/src/MediaHandlerBase.php +++ b/core/modules/media/src/MediaHandlerBase.php @@ -223,10 +223,21 @@ /** * Creates the source field storage definition. * + * By default, the first field type listed in the plugin definition's + * allowed_field_types array will be the generated field's type. + * * @return \Drupal\field\FieldStorageConfigInterface * The unsaved field storage definition. */ - abstract protected function createSourceFieldStorage(); + protected function createSourceFieldStorage() { + return $this->entityTypeManager + ->getStorage('field_storage_config') + ->create([ + 'entity_type' => 'media', + 'field_name' => $this->getSourceFieldName(), + 'type' => reset($this->pluginDefinition['allowed_field_types']), + ]); + } /** * Creates the source field definition for a type. diff -u b/core/modules/media/src/MediaHandlerInterface.php b/core/modules/media/src/MediaHandlerInterface.php --- b/core/modules/media/src/MediaHandlerInterface.php +++ b/core/modules/media/src/MediaHandlerInterface.php @@ -100,9 +100,9 @@ * * @param \Drupal\media\MediaInterface $media * The media entity. - * @param $source_field + * @param string $source_field * Name of the source metadata field. - * @param $destination_field + * @param string $destination_field * Name of the destination entity field. */ public function mapFieldValue(MediaInterface $media, $source_field, $destination_field); diff -u b/core/modules/media/src/MediaThumbnailHandler.php b/core/modules/media/src/MediaThumbnailHandler.php --- b/core/modules/media/src/MediaThumbnailHandler.php +++ b/core/modules/media/src/MediaThumbnailHandler.php @@ -3,12 +3,16 @@ namespace Drupal\media; use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; +use Drupal\Core\StringTranslation\TranslationInterface; /** * Provides a service for handling media thumbnails. */ class MediaThumbnailHandler implements MediaThumbnailHandlerInterface { + use StringTranslationTrait; + /** * The file entity storage handler. * @@ -21,9 +25,12 @@ * * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * The entity type manager service. + * @param \Drupal\Core\StringTranslation\TranslationInterface $translation + * The string translation service. */ - public function __construct(EntityTypeManagerInterface $entity_type_manager) { + public function __construct(EntityTypeManagerInterface $entity_type_manager, TranslationInterface $translation) { $this->fileStorage = $entity_type_manager->getStorage('file'); + $this->stringTranslation = $translation; } /** @@ -56,7 +63,7 @@ $media->thumbnail->target_id = $file->id(); } - $media->thumbnail->alt = t('Thumbnail'); + $media->thumbnail->alt = $this->t('Thumbnail'); $media->thumbnail->title = $media->label(); } diff -u b/core/modules/media/src/MediaTypeForm.php b/core/modules/media/src/MediaTypeForm.php --- b/core/modules/media/src/MediaTypeForm.php +++ b/core/modules/media/src/MediaTypeForm.php @@ -2,7 +2,6 @@ namespace Drupal\media; -use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Ajax\ReplaceCommand; use Drupal\Core\Entity\EntityFieldManagerInterface; @@ -10,7 +9,6 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Form\FormStateInterface; -use Drupal\field\Entity\FieldConfig; use Drupal\media\Entity\MediaType; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -85,7 +83,7 @@ public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); - /* $form['#entity'] = */$bundle = $this->entity; + $bundle = $this->entity; $form_state->set('bundle', $bundle->id()); /** @var \Drupal\media\MediaHandlerInterface $handler */ @@ -107,7 +105,6 @@ '#description' => $this->t('The human-readable name of this media type.'), '#required' => TRUE, '#size' => 30, - '#weight' => -100, ]; $form['id'] = [ @@ -119,7 +116,6 @@ 'exists' => [MediaType::class, 'load'], ], '#description' => $this->t('A unique machine-readable name for this media type.'), - '#weight' => -90, ]; $form['description'] = [ @@ -127,7 +123,6 @@ '#type' => 'textarea', '#default_value' => $bundle->getDescription(), '#description' => $this->t('Describe this media type. The text will be displayed on the Add new media page.'), - '#weight' => -80, ]; $plugins = $this->handlerManager->getDefinitions(); @@ -147,7 +142,6 @@ '#default_value' => $handler ? $handler->getPluginId() : NULL, '#options' => $options, '#description' => $this->t('Media handler that is responsible for additional logic related to this media type.'), - '#weight' => -70, '#ajax' => ['callback' => '::ajaxHandlerData'], '#required' => TRUE, ]; @@ -162,7 +156,6 @@ '#type' => 'fieldset', '#title' => $this->t('Handler configuration'), '#tree' => TRUE, - '#weight' => -60, ]; $handler_configuration = empty($this->configurableInstances[$handler->getPluginId()]['plugin_config']) ? $bundle->getHandlerConfiguration() : $this->configurableInstances[$plugin->getPluginId()]['plugin_config']; @@ -181,7 +174,6 @@ 'description' => [ '#markup' => '

' . $this->t('Media handlers can provide metadata fields such as title, caption, size information, credits, etc. Media can automatically save this metadata information to entity fields, which can be configured below. Information will only be mapped if the entity field is empty.') . '

', ], - '#weight' => -50, ]; if (empty($handler) || empty($handler->getProvidedFields())) { @@ -217,7 +209,6 @@ '#attached' => [ 'library' => ['media/media_type_form'], ], - '#weight' => 100, ]; $form['workflow'] = [ diff -u b/core/modules/media/src/Plugin/Field/FieldFormatter/MediaThumbnailFormatter.php b/core/modules/media/src/Plugin/Field/FieldFormatter/MediaThumbnailFormatter.php --- b/core/modules/media/src/Plugin/Field/FieldFormatter/MediaThumbnailFormatter.php +++ b/core/modules/media/src/Plugin/Field/FieldFormatter/MediaThumbnailFormatter.php @@ -11,7 +11,6 @@ use Drupal\Core\Render\RendererInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Field\FieldDefinitionInterface; -use Drupal\Core\Entity\EntityStorageInterface; /** * Plugin implementation of the 'media_thumbnail' formatter. diff -u b/core/modules/media/src/Plugin/views/wizard/Media.php b/core/modules/media/src/Plugin/views/wizard/Media.php --- b/core/modules/media/src/Plugin/views/wizard/Media.php +++ b/core/modules/media/src/Plugin/views/wizard/Media.php @@ -17,6 +17,8 @@ /** * Set the created column. + * + * @var string */ protected $createdColumn = 'media_field_data-created'; diff -u b/core/modules/media/src/Plugin/views/wizard/MediaRevision.php b/core/modules/media/src/Plugin/views/wizard/MediaRevision.php --- b/core/modules/media/src/Plugin/views/wizard/MediaRevision.php +++ b/core/modules/media/src/Plugin/views/wizard/MediaRevision.php @@ -17,6 +17,8 @@ /** * Set the created column. + * + * @var string */ protected $createdColumn = 'changed'; diff -u b/core/modules/media/tests/modules/media_test_handler/src/Plugin/media/Handler/Test.php b/core/modules/media/tests/modules/media_test_handler/src/Plugin/media/Handler/Test.php --- b/core/modules/media/tests/modules/media_test_handler/src/Plugin/media/Handler/Test.php +++ b/core/modules/media/tests/modules/media_test_handler/src/Plugin/media/Handler/Test.php @@ -68,17 +68,2 @@ - /** - * {@inheritdoc} - */ - protected function createSourceFieldStorage() { - return $this->entityTypeManager - ->getStorage('field_storage_config') - ->create([ - 'entity_type' => 'media', - 'field_name' => $this->getSourceFieldName(), - // Strings are harmless, inoffensive puppies: a good choice for a - // generic media type. - 'type' => 'string', - ]); - } - }