commit e778744ecce8f1b4b5b2cbcd49adb8be44cd4559 Author: Janez Urevc Date: Thu Dec 15 14:18:17 2016 +0100 \#144 diff --git a/core/modules/media/media.module b/core/modules/media/media.module index 9d3c804..6f89e3c 100644 --- a/core/modules/media/media.module +++ b/core/modules/media/media.module @@ -19,13 +19,13 @@ function media_help($route_name, RouteMatchInterface $route_match) { $output .= '

' . t('Uses') . '

'; $output .= '
'; $output .= '
' . t('Creating media items') . '
'; - $output .= '
' . t('When a new media item is created, the Media module records basic information about it, including the author, date of creation, and the Media type. It also manages the publishing options, which define whether or not the item is published. Default settings can be configured for each type of media on your site.', [':media-type' => Url::fromRoute('entity.media_type.collection')]) . '
'; + $output .= '
' . t('When a new media item is created, the Media module records basic information about it, including the author, date of creation, and the Media type. It also manages the publishing options, which define whether or not the item is published. Default settings can be configured for each type of media on your site.', [':media-type' => Url::fromRoute('entity.media_type.collection')->toString()]) . '
'; $output .= '
' . t('Creating custom media types') . '
'; - $output .= '
' . t('The Media module gives users with the Administer media types permission the ability to create new media types in addition to the default ones already configured. Each media type has an associated media handler (such as the image handler) which support thumbnail generation and metadata extraction. Fields managed by the Field module may be added for storing that metadata, such as width and height, as well as any other associated values.', [':media-new' => Url::fromRoute('entity.media_type.add_form'), ':field' => Url::fromRoute('help.page', ['name' => 'field'])]) . '
'; + $output .= '
' . t('The Media module gives users with the Administer media types permission the ability to create new media types in addition to the default ones already configured. Each media type has an associated media handler (such as the image handler) which support thumbnail generation and metadata extraction. Fields managed by the Field module may be added for storing that metadata, such as width and height, as well as any other associated values.', [':media-new' => Url::fromRoute('entity.media_type.add_form')->toString(), ':field' => Url::fromRoute('help.page', ['name' => 'field'])->toString()]) . '
'; $output .= '
' . t('Creating revisions') . '
'; $output .= '
' . t('The Media module also enables you to create multiple versions of any media item, and revert to older versions using the Revision information settings.') . '
'; $output .= '
' . t('User permissions') . '
'; - $output .= '
' . t('The Media module makes a number of permissions available, which can be set by role on the permissions page.', [':permissions' => Url::fromRoute('user.admin_permissions', [], ['fragment' => 'module-media'])]) . '
'; + $output .= '
' . t('The Media module makes a number of permissions available, which can be set by role on the permissions page.', [':permissions' => Url::fromRoute('user.admin_permissions', [], ['fragment' => 'module-media'])->toString()]) . '
'; $output .= '
'; return $output; } diff --git a/core/modules/media/media.tokens.inc b/core/modules/media/media.tokens.inc index 205872e..410a136 100644 --- a/core/modules/media/media.tokens.inc +++ b/core/modules/media/media.tokens.inc @@ -47,7 +47,7 @@ function media_token_info() { 'name' => t('Name'), 'description' => t('The name of this media.'), ]; - $node['author'] = [ + $media['author'] = [ 'name' => t('Author'), 'type' => 'user', ]; diff --git a/core/modules/media/src/Annotation/MediaHandler.php b/core/modules/media/src/Annotation/MediaHandler.php index 14c82c3..70001a6 100644 --- a/core/modules/media/src/Annotation/MediaHandler.php +++ b/core/modules/media/src/Annotation/MediaHandler.php @@ -35,9 +35,9 @@ class MediaHandler extends Plugin { /** * The human-readable name of the handler. * - * @ingroup plugin_translatable - * * @var \Drupal\Core\Annotation\Translation + * + * @ingroup plugin_translatable */ public $label; @@ -46,9 +46,9 @@ class MediaHandler extends Plugin { * * This will be shown when adding or configuring this display. * - * @ingroup plugin_translatable - * * @var \Drupal\Core\Annotation\Translation + * + * @ingroup plugin_translatable */ public $description = ''; diff --git a/core/modules/media/src/Entity/Media.php b/core/modules/media/src/Entity/Media.php index 55bccf5..6a45bff 100644 --- a/core/modules/media/src/Entity/Media.php +++ b/core/modules/media/src/Entity/Media.php @@ -30,6 +30,7 @@ * "list_builder" = "Drupal\Core\Entity\EntityListBuilder", * "access" = "Drupal\media\MediaAccessController", * "form" = { + * "default" = "Drupal\media\MediaForm", * "add" = "Drupal\media\MediaForm", * "edit" = "Drupal\media\MediaForm", * "delete" = "Drupal\Core\Entity\ContentEntityDeleteForm", @@ -154,7 +155,7 @@ public function preSave(EntityStorageInterface $storage) { */ public function postSave(EntityStorageInterface $storage, $update = TRUE) { parent::postSave($storage, $update); - if (!$update && $this->bundle->entity->getQueueThumbnailDownloads()) { + if (!$update && $this->bundle->entity->getQueueThumbnailDownloadsStatus()) { $queue = \Drupal::queue('media_entity_thumbnail'); $queue->createItem(['id' => $this->id()]); } diff --git a/core/modules/media/src/Entity/MediaType.php b/core/modules/media/src/Entity/MediaType.php index b449589..da65b3a 100644 --- a/core/modules/media/src/Entity/MediaType.php +++ b/core/modules/media/src/Entity/MediaType.php @@ -40,7 +40,7 @@ * entity_keys = { * "id" = "id", * "label" = "label", - * "status" = "status" + * "status" = "status", * }, * config_export = { * "id", @@ -92,6 +92,13 @@ class MediaType extends ConfigEntityBundleBase implements MediaTypeInterface, En protected $handler; /** + * Whether media items should be published by default. + * + * @var bool + */ + protected $status = TRUE; + + /** * Whether thumbnail downloads are queued. * * @var bool @@ -161,30 +168,14 @@ public function setDescription($description) { /** * {@inheritdoc} */ - public function getHandlerConfiguration() { - return $this->handler_configuration; - } - - /** - * {@inheritdoc} - */ - public function setHandlerConfiguration(array $configuration) { - $this->handler_configuration = $configuration; - $this->handlerPluginCollection = NULL; - return $this; - } - - /** - * {@inheritdoc} - */ - public function getQueueThumbnailDownloads() { + public function getQueueThumbnailDownloadsStatus() { return $this->queue_thumbnail_downloads; } /** * {@inheritdoc} */ - public function setQueueThumbnailDownloads($queue_thumbnail_downloads) { + public function setQueueThumbnailDownloadsStatus($queue_thumbnail_downloads) { $this->queue_thumbnail_downloads = $queue_thumbnail_downloads; return $this; } @@ -246,12 +237,9 @@ public function preSave(EntityStorageInterface $storage) { if ($storage instanceof FieldStorageConfigInterface && $storage->isNew()) { $storage->save(); } - // Store the field name. We always want to update this value because the - // field name may have changed, or a new field may have been created, - // depending on the user's actions or the handler's behavior. - $configuration = $handler->getConfiguration(); - $configuration['source_field'] = $storage->getName(); - $this->setHandlerConfiguration($configuration); + // We need to save handler configuration that have just changed above and + // won't be included otherwise. + $this->handler_configuration = $handler->getConfiguration(); } } diff --git a/core/modules/media/src/MediaHandlerBase.php b/core/modules/media/src/MediaHandlerBase.php index 5b592f8..14d8636 100644 --- a/core/modules/media/src/MediaHandlerBase.php +++ b/core/modules/media/src/MediaHandlerBase.php @@ -143,8 +143,8 @@ public function calculateDependencies() { * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { + // If there are existing fields to choose from, allow the user to reuse one. $options = []; - foreach ($this->entityFieldManager->getFieldStorageDefinitions('media') as $field_name => $field) { $allowed_type = in_array($field->getType(), $this->pluginDefinition['allowed_field_types'], TRUE); if ($allowed_type && !$field->isBaseField()) { @@ -152,17 +152,34 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta } } - // If there are existing fields to choose from, allow the user to reuse one. - if ($options) { - $form['source_field'] = [ - '#type' => 'select', - '#title' => $this->t('Field with source information'), - '#default_value' => $this->configuration['source_field'], - '#empty_option' => $this->t('- Create -'), - '#options' => $options, - '#description' => $this->t('The field on media items of this type that will store the source information.'), + $form['source_field'] = [ + '#type' => 'select', + '#title' => $this->t('Field with source information'), + '#default_value' => $this->configuration['source_field'], + '#empty_option' => $this->t('- Create -'), + '#options' => $options, + '#description' => $this->t('Select the field that will store essential information about the media item. If "Create" is selected a new field will be automatically created.'), + ]; + + if (!$options && $form_state->get('operation') === 'add') { + $form['source_field']['#access'] = FALSE; + $field_definition = \Drupal::service('plugin.manager.field.field_type')->getDefinition(reset($this->pluginDefinition['allowed_field_types'])); + $form['source_field_message'] = [ + '#markup' => $this->t('%field_name field will be automatically created on this type to store the essential information about the media item.', [ + '%field_name' => $field_definition['label'], + ]), + ]; + } + elseif ($form_state->get('operation') === 'edit') { + $form['source_field']['#access'] = FALSE; + $fields = $this->entityFieldManager->getFieldDefinitions('media', $form_state->get('type')->id()); + $form['source_field_message'] = [ + '#markup' => $this->t('%field_name field is used to store the essential information about the media item.', [ + '%field_name' => $fields[$this->configuration['source_field']]->getLabel(), + ]), ]; } + return $form; } @@ -176,6 +193,7 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form * {@inheritdoc} */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { + $this->setConfiguration($form_state->getValues()); } /** @@ -211,7 +229,9 @@ protected function getSourceFieldStorage() { // If we don't know the name of the source field, we definitely need to // create its storage. if (empty($this->configuration['source_field'])) { - return $this->createSourceFieldStorage(); + $storage = $this->createSourceFieldStorage(); + $this->configuration['source_field'] = $storage->getName(); + return $storage; } // Even if we do know the name of the source field, we cannot guarantee that // its storage exists. So check for the storage and create it if needed. @@ -236,6 +256,7 @@ protected function createSourceFieldStorage() { 'entity_type' => 'media', 'field_name' => $this->getSourceFieldName(), 'type' => reset($this->pluginDefinition['allowed_field_types']), + 'locked' => TRUE, ]); } @@ -255,6 +276,7 @@ protected function createSourceField(MediaTypeInterface $type) { ->create([ 'field_storage' => $this->getSourceFieldStorage(), 'bundle' => $type->id(), + 'label' => $this->pluginDefinition['label'], ]); } diff --git a/core/modules/media/src/MediaThumbnailHandler.php b/core/modules/media/src/MediaThumbnailHandler.php index ea5f979..19fc180 100644 --- a/core/modules/media/src/MediaThumbnailHandler.php +++ b/core/modules/media/src/MediaThumbnailHandler.php @@ -39,7 +39,7 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager, Tra public function setThumbnail(MediaInterface $media) { // If thumbnail fetching should be queued then temporary use default // thumbnail or fetch it immediately otherwise. - if ($media->bundle->entity->getQueueThumbnailDownloads() && $media->isNew()) { + if ($media->bundle->entity->getQueueThumbnailDownloadsStatus() && $media->isNew()) { $thumbnail_uri = $media->getHandler()->getDefaultThumbnail(); } else { diff --git a/core/modules/media/src/MediaTypeForm.php b/core/modules/media/src/MediaTypeForm.php index 98813cf..a1d88f2 100644 --- a/core/modules/media/src/MediaTypeForm.php +++ b/core/modules/media/src/MediaTypeForm.php @@ -6,9 +6,9 @@ use Drupal\Core\Ajax\ReplaceCommand; use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\EntityForm; -use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Form\SubformState; use Drupal\media\Entity\MediaType; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -18,13 +18,6 @@ class MediaTypeForm extends EntityForm { /** - * The instantiated plugin instances that have configuration forms. - * - * @var \Drupal\Core\Plugin\PluginFormInterface[] - */ - protected $configurableInstances = []; - - /** * Media handler plugin manager. * * @var \Drupal\media\MediaHandlerManager @@ -82,26 +75,20 @@ public function ajaxHandlerData(array $form, FormStateInterface $form_state) { */ public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); + $form_state->set('bundle', $this->entity->id()); - $bundle = $this->entity; - $form_state->set('bundle', $bundle->id()); - + // Handler is not set when the entity is initially created. /** @var \Drupal\media\MediaHandlerInterface $handler */ - $handler = NULL; - if ($bundle->get('handler')) { - // Handler is not set when the entity is initially created. - $handler = $bundle->getHandler(); - $this->configurableInstances[$handler]['plugin_config'] = empty($configuration[$handler]) ? [] : $configuration[$handler]; - } + $handler = $this->entity->get('handler') ? $handler = $this->entity->getHandler() : NULL; - if ($this->operation == 'add') { + if ($this->operation === 'add') { $form['#title'] = $this->t('Add media type'); } $form['label'] = [ '#title' => $this->t('Name'), '#type' => 'textfield', - '#default_value' => $bundle->label(), + '#default_value' => $this->entity->label(), '#description' => $this->t('The human-readable name of this media type.'), '#required' => TRUE, '#size' => 30, @@ -109,9 +96,9 @@ public function form(array $form, FormStateInterface $form_state) { $form['id'] = [ '#type' => 'machine_name', - '#default_value' => $bundle->id(), + '#default_value' => $this->entity->id(), '#maxlength' => 32, - '#disabled' => !$bundle->isNew(), + '#disabled' => !$this->entity->isNew(), '#machine_name' => [ 'exists' => [MediaType::class, 'load'], ], @@ -121,7 +108,7 @@ public function form(array $form, FormStateInterface $form_state) { $form['description'] = [ '#title' => $this->t('Description'), '#type' => 'textarea', - '#default_value' => $bundle->getDescription(), + '#default_value' => $this->entity->getDescription(), '#description' => $this->t('Describe this media type. The text will be displayed on the Add new media page.'), ]; @@ -158,16 +145,11 @@ public function form(array $form, FormStateInterface $form_state) { '#tree' => TRUE, ]; - $handler_configuration = empty($this->configurableInstances[$handler->getPluginId()]['plugin_config']) ? $bundle->getHandlerConfiguration() : $this->configurableInstances[$plugin->getPluginId()]['plugin_config']; - /** @var \Drupal\media\MediaHandlerBase $instance */ - $instance = $this->handlerManager->createInstance($handler->getPluginId(), $handler_configuration); - // Store the configuration for validate and submit handlers. - $this->configurableInstances[$handler->getPluginId()]['plugin_config'] = $handler_configuration; - $form['handler_dependent']['handler_configuration'][$handler->getPluginId()] = $instance->buildConfigurationForm(['#type' => 'container'], $form_state); + $form['handler_dependent']['handler_configuration'] = $handler->buildConfigurationForm($form['handler_dependent']['handler_configuration'], $this->getHandlerSubFormState($form, $form_state)); } // Field mapping configuration. - $form['handler_dependent']['field_mapping'] = [ + $form['handler_dependent']['field_map'] = [ '#type' => 'fieldset', '#title' => $this->t('Field mapping'), '#tree' => TRUE, @@ -177,25 +159,19 @@ public function form(array $form, FormStateInterface $form_state) { ]; if (empty($handler) || empty($handler->getProvidedFields())) { - $form['handler_dependent']['field_mapping']['#access'] = FALSE; + $form['handler_dependent']['field_map']['#access'] = FALSE; } else { $options = ['_none' => $this->t('- Skip field -')]; - foreach ($this->entityFieldManager->getFieldDefinitions('media', $bundle->id()) as $field_name => $field) { + foreach ($this->entityFieldManager->getFieldDefinitions('media', $this->entity->id()) as $field_name => $field) { if (!($field instanceof BaseFieldDefinition) || $field_name == 'name') { $options[$field_name] = $field->getLabel(); } } - $field_map = $bundle->getFieldMap(); + $field_map = $this->entity->getFieldMap(); foreach ($handler->getProvidedFields() as $field_name => $field_definition) { - // This is a BC layer. In the past this function returned string and now - // it returns arrays. - if (!is_array($field_definition)) { - $field_definition = ['label' => $field_definition]; - } - - $form['handler_dependent']['field_mapping'][$field_name] = [ + $form['handler_dependent']['field_map'][$field_name] = [ '#type' => 'select', '#title' => $field_definition['label'], '#options' => $options, @@ -217,18 +193,10 @@ public function form(array $form, FormStateInterface $form_state) { '#group' => 'additional_settings', ]; - $workflow_options = [ - 'status' => $bundle->getStatus(), - 'new_revision' => $bundle->shouldCreateNewRevision(), - 'queue_thumbnail_downloads' => $bundle->getQueueThumbnailDownloads(), - ]; - // Prepare workflow options to be used for 'checkboxes' form element. - $keys = array_keys(array_filter($workflow_options)); - $workflow_options = array_combine($keys, $keys); $form['workflow']['options'] = [ '#type' => 'checkboxes', '#title' => $this->t('Default options'), - '#default_value' => $workflow_options, + '#default_value' => $this->getWorkflowOptions(), '#options' => [ 'status' => $this->t('Published'), 'new_revision' => $this->t('Create new revision'), @@ -250,14 +218,14 @@ public function form(array $form, FormStateInterface $form_state) { $language_configuration = call_user_func( ['\Drupal\language\Entity\ContentLanguageSettings', 'loadByEntityTypeBundle'], 'media', - $bundle->id() + $this->entity->id() ); $form['language']['language_configuration'] = [ '#type' => 'language_configuration', '#entity_information' => [ 'entity_type' => 'media', - 'bundle' => $bundle->id(), + 'bundle' => $this->entity->id(), ], '#default_value' => $language_configuration, ]; @@ -267,34 +235,73 @@ public function form(array $form, FormStateInterface $form_state) { } /** + * Prepares workflow options to be used in the 'checkboxes' form element. + * + * @return array + * Array of options ready to be used in #options. + */ + protected function getWorkflowOptions() { + $workflow_options = [ + 'status' => $this->entity->getStatus(), + 'new_revision' => $this->entity->shouldCreateNewRevision(), + 'queue_thumbnail_downloads' => $this->entity->getQueueThumbnailDownloadsStatus(), + ]; + // Prepare workflow options to be used for 'checkboxes' form element. + $keys = array_keys(array_filter($workflow_options)); + return array_combine($keys, $keys); + } + + /** + * Gets sub-form state for the handler configuration sub-form. + * + * @param array $form + * Full form array. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Parent form state. + * + * @return \Drupal\Core\Form\SubFormStateInterface + * Sub-form state for the handler configuration form. + */ + protected function getHandlerSubFormState(array $form, FormStateInterface $form_state) { + $subform_state = SubformState::createForSubform($form['handler_dependent']['handler_configuration'], $form, $form_state); + $subform_state->set('operation', $this->operation); + $subform_state->set('type', $this->entity); + return $subform_state; + } + + /** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); - // Let the selected plugin validate its settings. - $plugin = $this->entity->getHandler()->getPluginId(); - $plugin_configuration = !empty($this->configurableInstances[$plugin]['plugin_config']) ? $this->configurableInstances[$plugin]['plugin_config'] : []; - $instance = $this->handlerManager->createInstance($plugin, $plugin_configuration); - $instance->validateConfigurationForm($form, $form_state); + if ($form['handler_dependent']['handler_configuration']) { + // Let the selected plugin validate its settings. + $this->entity->getHandler()->validateConfigurationForm($form['handler_dependent']['handler_configuration'], $this->getHandlerSubFormState($form, $form_state)); + } } /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { + $form_state->setValue('field_map', array_filter( + $form_state->getValue('field_map', []), + function ($item) { + return $item != '_none'; + } + )); + parent::submitForm($form, $form_state); - $this->entity->setQueueThumbnailDownloads((bool) $form_state->getValue(['options', 'queue_thumbnail_downloads'])); + $this->entity->setQueueThumbnailDownloadsStatus((bool) $form_state->getValue(['options', 'queue_thumbnail_downloads'])); $this->entity->setStatus((bool) $form_state->getValue(['options', 'status'])); - $this->entity->setNewRevision((bool) $form_state->getValue(['options', 'new_revision'])); - // Let the selected plugin save its settings. - $plugin = $this->entity->getHandler()->getPluginId(); - $plugin_configuration = !empty($this->configurableInstances[$plugin]['plugin_config']) ? $this->configurableInstances[$plugin]['plugin_config'] : []; - $instance = $this->handlerManager->createInstance($plugin, $plugin_configuration); - $instance->submitConfigurationForm($form, $form_state); + if ($form['handler_dependent']['handler_configuration']) { + // Let the selected plugin save its settings. + $this->entity->getHandler()->submitConfigurationForm($form['handler_dependent']['handler_configuration'], $this->getHandlerSubFormState($form, $form_state)); + } } /** @@ -311,35 +318,6 @@ protected function actions(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) { - $configuration = $form_state->getValue('handler_configuration'); - - // Store previous plugin config. - $plugin = NULL; - if ($entity->get('handler')) { - // Handler is not set when the entity is initially created. - $plugin = $entity->getHandler()->getPluginId(); - $this->configurableInstances[$plugin]['plugin_config'] = empty($configuration[$plugin]) ? [] : $configuration[$plugin]; - } - - /** @var \Drupal\media\MediaInterface $entity */ - parent::copyFormValuesToEntity($entity, $form, $form_state); - - // Use type configuration for the plugin that was chosen. - $plugin = $entity->getHandler()->getPluginId(); - $plugin_configuration = empty($configuration[$plugin]) ? [] : $configuration[$plugin]; - $entity->set('handler_configuration', $plugin_configuration); - - // Save field mapping. - $entity->set('field_map', array_filter( - $form_state->getValue('field_mapping', []), - function ($item) { return $item != '_none'; } - )); - } - - /** - * {@inheritdoc} - */ public function save(array $form, FormStateInterface $form_state) { $status = parent::save($form, $form_state); $bundle = $this->entity; diff --git a/core/modules/media/src/MediaTypeInterface.php b/core/modules/media/src/MediaTypeInterface.php index cd6fd60..9407e04 100644 --- a/core/modules/media/src/MediaTypeInterface.php +++ b/core/modules/media/src/MediaTypeInterface.php @@ -29,7 +29,7 @@ public static function getLabel(MediaInterface $media); * TRUE if thumbnails are queued for download later, FALSE if they should be * downloaded now. */ - public function getQueueThumbnailDownloads(); + public function getQueueThumbnailDownloadsStatus(); /** * Sets a flag to indicate that thumbnails should be downloaded via a queue. @@ -39,7 +39,7 @@ public function getQueueThumbnailDownloads(); * * @return $this */ - public function setQueueThumbnailDownloads($queue_thumbnail_downloads); + public function setQueueThumbnailDownloadsStatus($queue_thumbnail_downloads); /** * Returns the media handler plugin. @@ -50,24 +50,6 @@ public function setQueueThumbnailDownloads($queue_thumbnail_downloads); public function getHandler(); /** - * Returns the media handler plugin configuration. - * - * @return array - * The handler configuration. - */ - public function getHandlerConfiguration(); - - /** - * Sets the media handler plugin configuration. - * - * @param array $configuration - * The handler configuration. - * - * @return $this - */ - public function setHandlerConfiguration(array $configuration); - - /** * Sets whether new revisions should be created by default. * * @param bool $new_revision @@ -80,6 +62,11 @@ public function setNewRevision($new_revision); /** * Returns the metadata field map. * + * Field mapping allows site builders to map media item related metadata to + * entity fields. This information will be used when saving a given media item + * and if metadata values will be available they are going to be automatically + * copied to the corresponding entity fields. + * * @return array * Field mapping array with fields provided by the type plugin as keys and * Drupal Entity fields as values. diff --git a/core/modules/media/src/MediaTypeListBuilder.php b/core/modules/media/src/MediaTypeListBuilder.php index c0c8490..d584d15 100644 --- a/core/modules/media/src/MediaTypeListBuilder.php +++ b/core/modules/media/src/MediaTypeListBuilder.php @@ -5,7 +5,6 @@ use Drupal\Core\Config\Entity\ConfigEntityListBuilder; use Drupal\Core\Entity\EntityHandlerInterface; use Drupal\Core\Entity\EntityInterface; -use Drupal\Component\Utility\Xss; use Drupal\Core\Url; /** @@ -33,7 +32,7 @@ public function buildRow(EntityInterface $entity) { 'data' => $entity->label(), 'class' => ['menu-label'], ]; - $row['description']['data'] = ['#markup' => Xss::filterAdmin($entity->getDescription())]; + $row['description']['data'] = ['#markup' => $entity->getDescription()]; return $row + parent::buildRow($entity); } diff --git a/core/modules/media/src/Plugin/views/wizard/Media.php b/core/modules/media/src/Plugin/views/wizard/Media.php index 8316135..ed0d46d 100644 --- a/core/modules/media/src/Plugin/views/wizard/Media.php +++ b/core/modules/media/src/Plugin/views/wizard/Media.php @@ -24,6 +24,8 @@ class Media extends WizardPluginBase { /** * Set default values for the filters. + * + * @var array */ protected $filters = [ 'status' => [ diff --git a/core/modules/media/src/Plugin/views/wizard/MediaRevision.php b/core/modules/media/src/Plugin/views/wizard/MediaRevision.php index 8513778..68cb14f 100644 --- a/core/modules/media/src/Plugin/views/wizard/MediaRevision.php +++ b/core/modules/media/src/Plugin/views/wizard/MediaRevision.php @@ -24,6 +24,8 @@ class MediaRevision extends WizardPluginBase { /** * Set default values for the filters. + * + * @var array */ protected $filters = [ 'status' => [ diff --git a/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 index c21f1e6..c43a0f9 100644 --- a/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 @@ -30,8 +30,12 @@ public function getThumbnail(MediaInterface $media) { */ public function getProvidedFields() { return [ - 'field_1' => $this->t('Field 1'), - 'field_2' => $this->t('Field 2'), + 'field_1' => [ + 'label' => $this->t('Field 1'), + ], + 'field_2' => [ + 'label' => $this->t('Field 2'), + ], ]; } diff --git a/core/modules/media/tests/src/Functional/MediaFunctionalTestBase.php b/core/modules/media/tests/src/Functional/MediaFunctionalTestBase.php index 254bb4b..a801706 100644 --- a/core/modules/media/tests/src/Functional/MediaFunctionalTestBase.php +++ b/core/modules/media/tests/src/Functional/MediaFunctionalTestBase.php @@ -60,21 +60,21 @@ /** * An admin test user account. * - * @var \Drupal\Core\Session\AccountInterface; + * @var \Drupal\Core\Session\AccountInterface */ protected $adminUser; /** * A non-admin test user account. * - * @var \Drupal\Core\Session\AccountInterface; + * @var \Drupal\Core\Session\AccountInterface */ protected $nonAdminUser; /** * The storage service. * - * @var \Drupal\Core\Entity\EntityStorageInterface; + * @var \Drupal\Core\Entity\EntityStorageInterface */ protected $storage; diff --git a/core/modules/media/tests/src/FunctionalJavascript/BundleCreationTest.php b/core/modules/media/tests/src/FunctionalJavascript/BundleCreationTest.php index cc9c097..51c8a6f 100644 --- a/core/modules/media/tests/src/FunctionalJavascript/BundleCreationTest.php +++ b/core/modules/media/tests/src/FunctionalJavascript/BundleCreationTest.php @@ -47,8 +47,7 @@ public function testBundleCreationFormWithDefaultField() { // Check that the source field is correctly assigned to media bundle. $this->drupalGet("admin/structure/media/manage/{$bundleMachineName}"); - $this->assertSession() - ->fieldValueEquals('handler_configuration[test][source_field]', 'field_media_test'); + $this->assertSession()->pageTextContains('Test handler field is used to store the essential information about the media item.'); } /** @@ -85,7 +84,7 @@ public function testBundleCreationReuseSourceField() { $page->selectFieldOption('Handler', 'test'); $this->assertSession()->assertWaitOnAjaxRequest(); // Select the existing field for re-use. - $page->selectFieldOption('handler_configuration[test][source_field]', 'field_media_test'); + $page->selectFieldOption('handler_configuration[source_field]', 'field_media_test'); $page->pressButton('Save'); // Check that there are not fields created. diff --git a/core/modules/media/tests/src/FunctionalJavascript/MediaJavascriptTestBase.php b/core/modules/media/tests/src/FunctionalJavascript/MediaJavascriptTestBase.php index 2c1f2cc..0e43fff 100644 --- a/core/modules/media/tests/src/FunctionalJavascript/MediaJavascriptTestBase.php +++ b/core/modules/media/tests/src/FunctionalJavascript/MediaJavascriptTestBase.php @@ -61,21 +61,21 @@ /** * An admin test user account. * - * @var \Drupal\Core\Session\AccountInterface; + * @var \Drupal\Core\Session\AccountInterface */ protected $adminUser; /** * A non-admin test user account. * - * @var \Drupal\Core\Session\AccountInterface; + * @var \Drupal\Core\Session\AccountInterface */ protected $nonAdminUser; /** * The storage service. * - * @var \Drupal\Core\Entity\EntityStorageInterface; + * @var \Drupal\Core\Entity\EntityStorageInterface */ protected $storage; diff --git a/core/modules/media/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php b/core/modules/media/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php index c732a2d..097629a 100644 --- a/core/modules/media/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php +++ b/core/modules/media/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php @@ -58,7 +58,7 @@ public function testMediaBundles() { $machine_name = strtolower($name); $this->assertJsCondition("jQuery('.machine-name-value').html() == '$machine_name'"); $page->selectFieldOption('handler', 'test'); - $this->assertJsCondition("jQuery('.form-item-handler-configuration-test-test-config-value').length > 0;"); + $this->assertJsCondition("jQuery('.form-item-handler-configuration-test-config-value').length > 0;"); $page->fillField('description', $description); $page->pressButton('Save'); $assert_session->statusCodeEquals(200); @@ -112,7 +112,7 @@ public function testMediaBundles() { $page->fillField('description', $new_description); $page->selectFieldOption('handler', 'test'); $page->fillField('Test config value', 'This is new config value.'); - $page->selectFieldOption('field_mapping[field_1]', 'name'); + $page->selectFieldOption('field_map[field_1]', 'name'); $page->checkField('options[new_revision]'); $page->uncheckField('options[status]'); $page->checkField('options[queue_thumbnail_downloads]'); @@ -141,7 +141,7 @@ public function testMediaBundles() { $this->assertEquals($loaded_bundle->getHandler()->getPluginId(), 'test'); $this->assertEquals($loaded_bundle->getHandler()->getConfiguration()['test_config_value'], 'This is new config value.'); $this->assertTrue($loaded_bundle->shouldCreateNewRevision()); - $this->assertTrue($loaded_bundle->getQueueThumbnailDownloads()); + $this->assertTrue($loaded_bundle->getQueueThumbnailDownloadsStatus()); $this->assertFalse($loaded_bundle->getStatus()); $this->assertEquals($loaded_bundle->getFieldMap(), ['field_1' => 'name']); diff --git a/core/modules/media/tests/src/Kernel/BasicCreationTest.php b/core/modules/media/tests/src/Kernel/BasicCreationTest.php index 0dceb05..ab04078 100644 --- a/core/modules/media/tests/src/Kernel/BasicCreationTest.php +++ b/core/modules/media/tests/src/Kernel/BasicCreationTest.php @@ -120,7 +120,7 @@ public function testProgrammaticBundleManipulation() { $this->assertFalse($field->isNew()); // Saving with a non-existent source field should create it. - $this->testBundle->setHandlerConfiguration([ + $this->testBundle->getHandler()->setConfiguration([ 'source_field' => 'field_magick', ]); $this->testBundle->save(); @@ -130,7 +130,7 @@ public function testProgrammaticBundleManipulation() { $this->assertFalse($field->isNew()); // Trying to save without a source field should create a new, de-duped one. - $this->testBundle->setHandlerConfiguration([]); + $this->testBundle->getHandler()->setConfiguration([]); $this->testBundle->save(); $field = $this->testBundle->getHandler()->getSourceField($this->testBundle); $this->assertInstanceOf(FieldConfig::class, $field); @@ -138,7 +138,7 @@ public function testProgrammaticBundleManipulation() { $this->assertFalse($field->isNew()); // Trying to reuse an existing field should, well, reuse the existing field. - $this->testBundle->setHandlerConfiguration([ + $this->testBundle->getHandler()->setConfiguration([ 'source_field' => 'field_magick', ]); $this->testBundle->save();