diff --git a/core/modules/media_entity/config/schema/media_entity.schema.yml b/core/modules/media_entity/config/schema/media_entity.schema.yml index d87ae9b..37b9fb1 100644 --- a/core/modules/media_entity/config/schema/media_entity.schema.yml +++ b/core/modules/media_entity/config/schema/media_entity.schema.yml @@ -4,24 +4,24 @@ media_entity.settings: mapping: icon_base: type: string - label: 'URI where media type icons will be installed' + label: 'URI where media icons will be installed' media_entity.bundle.*: type: config_entity - label: 'Media bundle' + label: 'Media type' mapping: id: type: string label: 'Machine name' label: type: label - label: 'Label' + label: 'Name' description: type: text label: 'Description' type: type: string - label: 'Type plugin ID' + label: 'Handler' type_configuration: type: media_entity.bundle.type.[%parent.type] queue_thumbnail_downloads: diff --git a/core/modules/media_entity/media_entity.info.yml b/core/modules/media_entity/media_entity.info.yml index f09c401..89e2605 100644 --- a/core/modules/media_entity/media_entity.info.yml +++ b/core/modules/media_entity/media_entity.info.yml @@ -1,5 +1,5 @@ name: Media entity -description: 'Allows for media assets to be created and used on the site.' +description: 'Allows for media items to be created and used on the site.' type: module package: Core version: VERSION diff --git a/core/modules/media_entity/media_entity.links.action.yml b/core/modules/media_entity/media_entity.links.action.yml index cb5492c..0c79427 100644 --- a/core/modules/media_entity/media_entity.links.action.yml +++ b/core/modules/media_entity/media_entity.links.action.yml @@ -1,6 +1,6 @@ media.bundle_add: route_name: entity.media_bundle.add_form - title: 'Add media bundle' + title: 'Add media type' appears_on: - entity.media_bundle.collection diff --git a/core/modules/media_entity/media_entity.links.menu.yml b/core/modules/media_entity/media_entity.links.menu.yml index ef59afc..def8d6b 100644 --- a/core/modules/media_entity/media_entity.links.menu.yml +++ b/core/modules/media_entity/media_entity.links.menu.yml @@ -1,7 +1,7 @@ entity.media_bundle.collection: - title: 'Media bundles' + title: 'Media types' parent: system.admin_structure - description: 'Manage media bundles.' + description: 'Manage media types.' route_name: entity.media_bundle.collection entity.media.add: diff --git a/core/modules/media_entity/media_entity.permissions.yml b/core/modules/media_entity/media_entity.permissions.yml index 072259e..6bf4ed2 100644 --- a/core/modules/media_entity/media_entity.permissions.yml +++ b/core/modules/media_entity/media_entity.permissions.yml @@ -2,7 +2,7 @@ administer media: title: 'Administer media' restrict access: TRUE administer media bundles: - title: 'Administer media bundles' + title: 'Administer media types' restrict access: TRUE view media: title: 'View media' diff --git a/core/modules/media_entity/media_entity.tokens.inc b/core/modules/media_entity/media_entity.tokens.inc index 0055925..98f764a 100644 --- a/core/modules/media_entity/media_entity.tokens.inc +++ b/core/modules/media_entity/media_entity.tokens.inc @@ -35,11 +35,11 @@ function media_entity_token_info() { 'description' => t("'The unique ID of the media's latest revision."), ]; $media['bundle'] = [ - 'name' => t('Media bundle'), + 'name' => t('Media type'), ]; $media['bundle-name'] = [ - 'name' => t('Media bundle name'), - 'description' => t('The human-readable name of the media bundle.'), + 'name' => t('Media type name'), + 'description' => t('The human-readable name of the media type.'), ]; $media['langcode'] = [ 'name' => t('Language code'), diff --git a/core/modules/media_entity/src/Entity/Media.php b/core/modules/media_entity/src/Entity/Media.php index 2974b7b..77bfc67 100644 --- a/core/modules/media_entity/src/Entity/Media.php +++ b/core/modules/media_entity/src/Entity/Media.php @@ -23,7 +23,7 @@ * singular = "@count media item", * plural = "@count media items" * ), - * bundle_label = @Translation("Media bundle"), + * bundle_label = @Translation("Media type"), * handlers = { * "storage" = "Drupal\Core\Entity\Sql\SqlContentEntityStorage", * "view_builder" = "Drupal\Core\Entity\EntityViewBuilder", @@ -59,6 +59,7 @@ * permission_granularity = "entity_type", * admin_permission = "administer media", * field_ui_base_route = "entity.media_bundle.edit_form", + * common_reference_target = TRUE, * links = { * "add-page" = "/media/add", * "add-form" = "/media/add/{media_bundle}", @@ -294,7 +295,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['uid'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Publisher ID')) - ->setDescription(t('The user ID of the media publisher.')) + ->setDescription(t('The user ID of the author of the media item.')) ->setRevisionable(TRUE) ->setDefaultValueCallback('Drupal\media_entity\Entity\Media::getCurrentUserId') ->setSetting('target_type', 'user') @@ -319,7 +320,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['created'] = BaseFieldDefinition::create('created') ->setLabel(t('Created')) - ->setDescription(t('The time that the media was created.')) + ->setDescription(t('The time the media item was created.')) ->setTranslatable(TRUE) ->setRevisionable(TRUE) ->setDisplayOptions('form', [ @@ -336,13 +337,13 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['changed'] = BaseFieldDefinition::create('changed') ->setLabel(t('Changed')) - ->setDescription(t('The time that the media was last edited.')) + ->setDescription(t('The time the media item was last edited.')) ->setTranslatable(TRUE) ->setRevisionable(TRUE); $fields['revision_timestamp'] = BaseFieldDefinition::create('created') ->setLabel(t('Revision timestamp')) - ->setDescription(t('The time that the current revision was created.')) + ->setDescription(t('The time the current revision was created.')) ->setQueryable(FALSE) ->setRevisionable(TRUE); diff --git a/core/modules/media_entity/src/Entity/MediaBundle.php b/core/modules/media_entity/src/Entity/MediaBundle.php index c2cba16..8286ff4 100644 --- a/core/modules/media_entity/src/Entity/MediaBundle.php +++ b/core/modules/media_entity/src/Entity/MediaBundle.php @@ -2,7 +2,6 @@ namespace Drupal\media_entity\Entity; -use Drupal\Core\Entity\EntityDescriptionInterface; use Drupal\Core\Config\Entity\ConfigEntityBundleBase; use Drupal\Core\Entity\EntityWithPluginCollectionInterface; use Drupal\Core\Plugin\DefaultSingleLazyPluginCollection; @@ -14,12 +13,12 @@ * * @ConfigEntityType( * id = "media_bundle", - * label = @Translation("Media bundle"), - * label_singular = @Translation("media bundle"), - * label_plural = @Translation("media bundles"), + * label = @Translation("Media type"), + * label_singular = @Translation("media type"), + * label_plural = @Translation("media types"), * label_count = @PluralTranslation( - * singular = "@count media bundle", - * plural = "@count media bundles" + * singular = "@count media type", + * plural = "@count media types" * ), * handlers = { * "form" = { @@ -87,7 +86,7 @@ class MediaBundle extends ConfigEntityBundleBase implements MediaBundleInterface * * @var string */ - protected $type = 'generic'; + protected $type; /** * Are thumbnail downloads queued. diff --git a/core/modules/media_entity/src/Form/DeleteMultiple.php b/core/modules/media_entity/src/Form/DeleteMultiple.php index 2a9cc40..8a16acf 100644 --- a/core/modules/media_entity/src/Form/DeleteMultiple.php +++ b/core/modules/media_entity/src/Form/DeleteMultiple.php @@ -116,7 +116,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { } $items[$default_key] = [ 'label' => [ - '#markup' => $this->t('@label (Original translation) - The following media translations will be deleted:', ['@label' => $entity->label()]), + '#markup' => $this->t('@label (Original translation) - The following translations will be deleted:', ['@label' => $entity->label()]), ], 'deleted_translations' => [ '#theme' => 'item_list', diff --git a/core/modules/media_entity/src/MediaBundleForm.php b/core/modules/media_entity/src/MediaBundleForm.php index f8c1f30..7a38e17 100644 --- a/core/modules/media_entity/src/MediaBundleForm.php +++ b/core/modules/media_entity/src/MediaBundleForm.php @@ -2,6 +2,7 @@ namespace Drupal\media_entity; +use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Ajax\ReplaceCommand; use Drupal\Core\Entity\EntityFieldManagerInterface; @@ -72,13 +73,9 @@ public static function create(ContainerInterface $container) { * @return \Drupal\Core\Ajax\AjaxResponse * The ajax response. */ - public function ajaxTypeProviderData(array $form, FormStateInterface $form_state) { + public function ajaxHandlerData(array $form, FormStateInterface $form_state) { $response = new AjaxResponse(); - $plugin = $this->entity->getType()->getPluginId(); - - $response->addCommand(new ReplaceCommand('#edit-type-configuration-plugin-wrapper', $form['type_configuration'][$plugin])); - $response->addCommand(new ReplaceCommand('#field-mapping-wrapper', $form['field_mapping'])); - + $response->addCommand(new ReplaceCommand('#handler-dependent', $form['handler_dependent'])); return $response; } @@ -92,24 +89,31 @@ public function form(array $form, FormStateInterface $form_state) { $form['#entity'] = $bundle = $this->getEntity(); $form_state->set('bundle', $bundle->id()); + /** @var \Drupal\media_entity\MediaTypeInterface $handler */ + try { + // Handler is not set when entity is initially created. + $handler = $bundle->getType(); + } + catch (PluginNotFoundException $e) { + $handler = NULL; + } + if ($this->operation == 'add') { - $form['#title'] = $this->t('Add media bundle'); + $form['#title'] = $this->t('Add media type'); } elseif ($this->operation == 'edit') { - $form['#title'] = $this->t('Edit %label media bundle', ['%label' => $bundle->label()]); } $form['label'] = [ - '#title' => $this->t('Label'), + '#title' => $this->t('Name'), '#type' => 'textfield', '#default_value' => $bundle->label(), - '#description' => $this->t('The human-readable name of this media bundle.'), + '#description' => $this->t('The human-readable name of this media type.'), '#required' => TRUE, '#size' => 30, '#weight' => -100, ]; - // @todo: '#disabled' not always FALSE. $form['id'] = [ '#type' => 'machine_name', '#default_value' => $bundle->id(), @@ -119,7 +123,7 @@ public function form(array $form, FormStateInterface $form_state) { 'exists' => [MediaBundle::class, 'load'], 'source' => ['label'], ], - '#description' => $this->t('A unique machine-readable name for this media bundle.'), + '#description' => $this->t('A unique machine-readable name for this media type.'), '#weight' => -90, ]; @@ -127,7 +131,7 @@ public function form(array $form, FormStateInterface $form_state) { '#title' => $this->t('Description'), '#type' => 'textarea', '#default_value' => $bundle->getDescription(), - '#description' => $this->t('Describe this media bundle. The text will be displayed on the Add new media page.'), + '#description' => $this->t('Describe this media type. The text will be displayed on the Add new media page.'), '#weight' => -80, ]; @@ -137,61 +141,58 @@ public function form(array $form, FormStateInterface $form_state) { $options[$plugin] = $definition['label']; } - $form['type'] = [ + $form['handler_dependent'] = [ + '#type' => 'container', + '#attributes' => ['id' => 'handler-dependent'], + ]; + + $form['handler_dependent']['type'] = [ '#type' => 'select', - '#title' => $this->t('Type provider'), - '#default_value' => $bundle->getType()->getPluginId(), + '#title' => $this->t('Handler'), + '#default_value' => $handler ? $handler->getPluginId() : NULL, '#options' => $options, - '#description' => $this->t('Media type provider plugin that is responsible for additional logic related to this media type.'), + '#description' => $this->t('Media handler that is responsible for additional logic related to this media type.'), '#weight' => -70, - '#ajax' => ['callback' => '::ajaxTypeProviderData'], + '#ajax' => ['callback' => '::ajaxHandlerData'], + '#required' => TRUE, ]; - // Media type plugin configuration. - $form['type_configuration'] = [ - '#type' => 'fieldset', - '#title' => $this->t('Type provider configuration'), - '#tree' => TRUE, - '#weight' => -60, - ]; + if (!$handler) { + $form['type']['#empty_option'] = $this->t('- Select handler -'); + } - /** @var \Drupal\media_entity\MediaTypeInterface $plugin */ - if ($plugin = $bundle->getType()) { - $plugin_configuration = empty($this->configurableInstances[$plugin->getPluginId()]['plugin_config']) ? $bundle->getTypeConfiguration() : $this->configurableInstances[$plugin->getPluginId()]['plugin_config']; + if ($handler) { + // Media handler plugin configuration. + $form['handler_dependent']['type_configuration'] = [ + '#type' => 'fieldset', + '#title' => $this->t('Handler configuration'), + '#tree' => TRUE, + '#weight' => -60, + ]; + + $handler_configuration = empty($this->configurableInstances[$handler->getPluginId()]['plugin_config']) ? $bundle->getTypeConfiguration() : $this->configurableInstances[$plugin->getPluginId()]['plugin_config']; /** @var \Drupal\media_entity\MediaTypeBase $instance */ - $instance = $this->mediaTypeManager->createInstance($plugin->getPluginId(), $plugin_configuration); + $instance = $this->mediaTypeManager->createInstance($handler->getPluginId(), $handler_configuration); // Store the configuration for validate and submit handlers. - $this->configurableInstances[$plugin->getPluginId()]['plugin_config'] = $plugin_configuration; - - $form['type_configuration'][$plugin->getPluginId()] = [ - '#type' => 'container', - '#attributes' => [ - 'id' => 'edit-type-configuration-plugin-wrapper', - ], - ]; - $form['type_configuration'][$plugin->getPluginId()] += $instance->buildConfigurationForm([], $form_state); + $this->configurableInstances[$handler->getPluginId()]['plugin_config'] = $handler_configuration; + $form['handler_dependent']['type_configuration'][$handler->getPluginId()] = $instance->buildConfigurationForm(['#type' => 'container'], $form_state); } // Field mapping configuration. - $form['field_mapping'] = [ + $form['handler_dependent']['field_mapping'] = [ '#type' => 'fieldset', '#title' => $this->t('Field mapping'), '#tree' => TRUE, - '#attributes' => ['id' => 'field-mapping-wrapper'], 'description' => [ '#type' => 'html_tag', '#tag' => 'p', - '#value' => $this->t('Media type plugins can provide metadata fields such as title, caption, size information, credits, ... Media entity 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.'), + '#value' => $this->t('Media handlers can provide metadata fields such as title, caption, size information, credits, ... Media entity 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($plugin) || empty($plugin->providedFields())) { - $form['field_mapping']['empty_message'] = [ - '#prefix' => '', - '#suffix' => '', - '#markup' => $this->t('No metadata fields available.'), - ]; + if (empty($handler) || empty($handler->providedFields())) { + $form['handler_dependent']['field_mapping']['#access'] = FALSE; } else { $skipped_fields = [ @@ -214,8 +215,8 @@ public function form(array $form, FormStateInterface $form_state) { } $field_map = $bundle->getFieldMap(); - foreach ($plugin->providedFields() as $field_name => $field_label) { - $form['field_mapping'][$field_name] = [ + foreach ($handler->providedFields() as $field_name => $field_label) { + $form['handler_dependent']['field_mapping'][$field_name] = [ '#type' => 'select', '#title' => $field_label, '#options' => $options, @@ -257,8 +258,8 @@ public function form(array $form, FormStateInterface $form_state) { ], ]; - $form['workflow']['options']['status']['#description'] = $this->t('Entities will be automatically published when they are created.'); - $form['workflow']['options']['new_revision']['#description'] = $this->t('Automatically create a new revision of media entities. Users with the Administer media permission will be able to override this option.'); + $form['workflow']['options']['status']['#description'] = $this->t('Media will be automatically published when created.'); + $form['workflow']['options']['new_revision']['#description'] = $this->t('Automatically create new revisions. Users with the Administer media permission will be able to override this option.'); $form['workflow']['options']['queue_thumbnail_downloads']['#description'] = $this->t('Download thumbnails via a queue.'); if ($this->moduleHandler->moduleExists('language')) { @@ -319,8 +320,8 @@ public function submitForm(array &$form, FormStateInterface $form_state) { */ protected function actions(array $form, FormStateInterface $form_state) { $actions = parent::actions($form, $form_state); - $actions['submit']['#value'] = $this->t('Save media bundle'); - $actions['delete']['#value'] = $this->t('Delete media bundle'); + $actions['submit']['#value'] = $this->t('Save'); + $actions['delete']['#value'] = $this->t('Delete'); $actions['delete']['#access'] = $this->entity->access('delete'); return $actions; } @@ -332,8 +333,12 @@ protected function copyFormValuesToEntity(EntityInterface $entity, array $form, $configuration = $form_state->getValue('type_configuration'); // Store previous plugin config. - $plugin = $entity->getType()->getPluginId(); - $this->configurableInstances[$plugin]['plugin_config'] = empty($configuration[$plugin]) ? [] : $configuration[$plugin]; + try { + // Handler is not set when the entity is initially created. + $plugin = $entity->getType()->getPluginId(); + $this->configurableInstances[$plugin]['plugin_config'] = empty($configuration[$plugin]) ? [] : $configuration[$plugin]; + } + catch (PluginNotFoundException $e) {} /** @var \Drupal\media_entity\MediaBundleInterface $entity */ parent::copyFormValuesToEntity($entity, $form, $form_state); @@ -360,11 +365,11 @@ public function save(array $form, FormStateInterface $form_state) { $t_args = ['%name' => $bundle->label()]; if ($status == SAVED_UPDATED) { - drupal_set_message($this->t('The media bundle %name has been updated.', $t_args)); + drupal_set_message($this->t('The media type %name has been updated.', $t_args)); } elseif ($status == SAVED_NEW) { - drupal_set_message($this->t('The media bundle %name has been added.', $t_args)); - $this->logger('media')->notice('Added bundle %name.', $t_args); + drupal_set_message($this->t('The media type %name has been added.', $t_args)); + $this->logger('media')->notice('Added type %name.', $t_args); } // Override the "status" base field default value, for this bundle. diff --git a/core/modules/media_entity/src/MediaBundleListBuilder.php b/core/modules/media_entity/src/MediaBundleListBuilder.php index e5158b1..55f7a92 100644 --- a/core/modules/media_entity/src/MediaBundleListBuilder.php +++ b/core/modules/media_entity/src/MediaBundleListBuilder.php @@ -42,7 +42,7 @@ public function buildRow(EntityInterface $entity) { */ public function render() { $build = parent::render(); - $build['#empty'] = $this->t('No media bundle available. Add media bundle.', [ + $build['table']['#empty'] = $this->t('No media types available. Add media type.', [ '@link' => Url::fromRoute('entity.media_bundle.add_form')->toString(), ]); return $build; diff --git a/core/modules/media_entity/src/Plugin/MediaEntity/Type/Generic.php b/core/modules/media_entity/src/Plugin/MediaEntity/Type/Generic.php deleted file mode 100644 index 021fac6..0000000 --- a/core/modules/media_entity/src/Plugin/MediaEntity/Type/Generic.php +++ /dev/null @@ -1,41 +0,0 @@ -getDefaultThumbnail(); - } - -} diff --git a/core/modules/media_entity/tests/modules/media_entity_test_bundle/config/install/media_entity.bundle.test.yml b/core/modules/media_entity/tests/modules/media_entity_test_bundle/config/install/media_entity.bundle.test.yml index c0a0f70..aebbb43 100644 --- a/core/modules/media_entity/tests/modules/media_entity_test_bundle/config/install/media_entity.bundle.test.yml +++ b/core/modules/media_entity/tests/modules/media_entity_test_bundle/config/install/media_entity.bundle.test.yml @@ -1,8 +1,9 @@ id: test -label: 'Test bundle' -description: 'Test bundle.' -type: generic -type_configuration: { } +label: 'Test type' +description: 'Test type.' +type: test +type_configuration: + test_config_value: 'Kakec' status: true langcode: en dependencies: { } diff --git a/core/modules/media_entity/tests/modules/media_entity_test_bundle/media_entity_test_bundle.info.yml b/core/modules/media_entity/tests/modules/media_entity_test_bundle/media_entity_test_bundle.info.yml index 9969dad..560832e 100644 --- a/core/modules/media_entity/tests/modules/media_entity_test_bundle/media_entity_test_bundle.info.yml +++ b/core/modules/media_entity/tests/modules/media_entity_test_bundle/media_entity_test_bundle.info.yml @@ -1,6 +1,8 @@ -name: 'Media entity test bundle' +name: 'Media entity test type' type: module -description: 'Provides test bundle for media entity.' +description: 'Provides test type for media entity.' core: 8.x package: Testing version: VERSION +dependencies: + - media_entity_test_handler diff --git a/core/modules/media_entity/tests/modules/media_entity_test_type/config/schema/media_entity_test_type.schema.yml b/core/modules/media_entity/tests/modules/media_entity_test_handler/config/schema/media_entity_test_handler.schema.yml similarity index 58% rename from core/modules/media_entity/tests/modules/media_entity_test_type/config/schema/media_entity_test_type.schema.yml rename to core/modules/media_entity/tests/modules/media_entity_test_handler/config/schema/media_entity_test_handler.schema.yml index 6ff7e14..eeaf781 100644 --- a/core/modules/media_entity/tests/modules/media_entity_test_type/config/schema/media_entity_test_type.schema.yml +++ b/core/modules/media_entity/tests/modules/media_entity_test_handler/config/schema/media_entity_test_handler.schema.yml @@ -1,6 +1,6 @@ -media_entity.bundle.type.test_type: +media_entity.bundle.type.test: type: mapping - label: 'Test type configuration' + label: 'Test handler configuration' mapping: test_config_value: type: string diff --git a/core/modules/media_entity/tests/modules/media_entity_test_handler/media_entity_test_handler.info.yml b/core/modules/media_entity/tests/modules/media_entity_test_handler/media_entity_test_handler.info.yml new file mode 100644 index 0000000..e29fe8c --- /dev/null +++ b/core/modules/media_entity/tests/modules/media_entity_test_handler/media_entity_test_handler.info.yml @@ -0,0 +1,6 @@ +name: 'Test media handler' +type: module +description: 'Provides test media handler to test configuration forms.' +core: 8.x +package: Testing +version: VERSION diff --git a/core/modules/media_entity/tests/modules/media_entity_test_type/src/Plugin/MediaEntity/Type/TestType.php b/core/modules/media_entity/tests/modules/media_entity_test_handler/src/Plugin/MediaEntity/Type/Test.php similarity index 62% rename from core/modules/media_entity/tests/modules/media_entity_test_type/src/Plugin/MediaEntity/Type/TestType.php rename to core/modules/media_entity/tests/modules/media_entity_test_handler/src/Plugin/MediaEntity/Type/Test.php index 60d68a0..60596e5 100644 --- a/core/modules/media_entity/tests/modules/media_entity_test_type/src/Plugin/MediaEntity/Type/TestType.php +++ b/core/modules/media_entity/tests/modules/media_entity_test_handler/src/Plugin/MediaEntity/Type/Test.php @@ -1,20 +1,29 @@ getDefaultThumbnail(); + } /** * {@inheritdoc} @@ -29,6 +38,13 @@ public function providedFields() { /** * {@inheritdoc} */ + public function getField(MediaInterface $media, $name) { + return FALSE; + } + + /** + * {@inheritdoc} + */ public function defaultConfiguration() { return [ 'test_config_value' => 'This is default value.', diff --git a/core/modules/media_entity/tests/modules/media_entity_test_type/media_entity_test_type.info.yml b/core/modules/media_entity/tests/modules/media_entity_test_type/media_entity_test_type.info.yml deleted file mode 100644 index ed82c4c..0000000 --- a/core/modules/media_entity/tests/modules/media_entity_test_type/media_entity_test_type.info.yml +++ /dev/null @@ -1,6 +0,0 @@ -name: 'Test media type' -type: module -description: 'Provides test media type plugin to test configuration forms.' -core: 8.x -package: Testing -version: VERSION diff --git a/core/modules/media_entity/tests/src/Functional/MediaEntityFunctionalTestBase.php b/core/modules/media_entity/tests/src/Functional/MediaEntityFunctionalTestBase.php index 5ddac2f..c2069b0 100644 --- a/core/modules/media_entity/tests/src/Functional/MediaEntityFunctionalTestBase.php +++ b/core/modules/media_entity/tests/src/Functional/MediaEntityFunctionalTestBase.php @@ -24,6 +24,7 @@ 'field_ui', 'views_ui', 'media_entity', + 'media_entity_test_handler', ]; /** diff --git a/core/modules/media_entity/tests/src/Functional/MediaEntityFunctionalTestTrait.php b/core/modules/media_entity/tests/src/Functional/MediaEntityFunctionalTestTrait.php index 4e2eedf..98579cc 100644 --- a/core/modules/media_entity/tests/src/Functional/MediaEntityFunctionalTestTrait.php +++ b/core/modules/media_entity/tests/src/Functional/MediaEntityFunctionalTestTrait.php @@ -23,7 +23,7 @@ * @return \Drupal\Core\Entity\EntityInterface * Returns newly created media bundle. */ - protected function drupalCreateMediaBundle(array $values = [], $type_name = 'generic') { + protected function drupalCreateMediaBundle(array $values = [], $type_name = 'test') { if (!isset($values['bundle'])) { $id = strtolower($this->randomMachineName()); } @@ -42,7 +42,7 @@ protected function drupalCreateMediaBundle(array $values = [], $type_name = 'gen $bundle = MediaBundle::create($values); $status = $bundle->save(); - $this->assertEquals($status, SAVED_NEW, 'Could not create a media bundle of type ' . $type_name . '.'); + $this->assertEquals($status, SAVED_NEW, 'Media type was created successfully.'); return $bundle; } diff --git a/core/modules/media_entity/tests/src/Functional/MediaUiFunctionalTest.php b/core/modules/media_entity/tests/src/Functional/MediaUiFunctionalTest.php index 9306334..3116e32 100644 --- a/core/modules/media_entity/tests/src/Functional/MediaUiFunctionalTest.php +++ b/core/modules/media_entity/tests/src/Functional/MediaUiFunctionalTest.php @@ -18,7 +18,7 @@ class MediaUiFunctionalTest extends MediaEntityFunctionalTestBase { */ public static $modules = [ 'block', - 'media_entity_test_type', + 'media_entity_test_handler', ]; /** diff --git a/core/modules/media_entity/tests/src/FunctionalJavascript/MediaEntityJavascriptTestBase.php b/core/modules/media_entity/tests/src/FunctionalJavascript/MediaEntityJavascriptTestBase.php index 4f214f3..0f06770 100644 --- a/core/modules/media_entity/tests/src/FunctionalJavascript/MediaEntityJavascriptTestBase.php +++ b/core/modules/media_entity/tests/src/FunctionalJavascript/MediaEntityJavascriptTestBase.php @@ -25,6 +25,7 @@ 'field_ui', 'views_ui', 'media_entity', + 'media_entity_test_handler', ]; /** diff --git a/core/modules/media_entity/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php b/core/modules/media_entity/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php index 6711181..9a901e5 100644 --- a/core/modules/media_entity/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php +++ b/core/modules/media_entity/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php @@ -18,7 +18,7 @@ class MediaUiJavascriptTest extends MediaEntityJavascriptTestBase { */ public static $modules = [ 'block', - 'media_entity_test_type', + 'media_entity_test_handler', ]; /** @@ -45,17 +45,24 @@ public function testMediaBundles() { $page = $session->getPage(); $assert_session = $this->assertSession(); + $this->drupalGet('admin/structure/media'); + $assert_session->statusCodeEquals(200); + $assert_session->pageTextContains('No media types available. Add media type.'); + $assert_session->linkExists('Add media type'); + // Test the creation of a media bundle using the UI. $name = $this->randomMachineName(); $description = $this->randomMachineName(); $this->drupalGet('admin/structure/media/add'); $page->fillField('label', $name); - $session->wait(2000); - $page->selectFieldOption('type', 'generic'); + $machine_name = strtolower($name); + $this->assertJsCondition("jQuery('.machine-name-value').html() == '$machine_name'"); + $page->selectFieldOption('type', 'test'); + $this->assertJsCondition("jQuery('.form-item-type-configuration-test-test-config-value').length > 0;"); $page->fillField('description', $description); - $page->pressButton('Save media bundle'); + $page->pressButton('Save'); $assert_session->statusCodeEquals(200); - $assert_session->pageTextContains('The media bundle ' . $name . ' has been added.'); + $assert_session->pageTextContains('The media type ' . $name . ' has been added.'); $this->drupalGet('admin/structure/media'); $assert_session->statusCodeEquals(200); $assert_session->pageTextContains($name); @@ -76,20 +83,19 @@ public function testMediaBundles() { $page->clickLink('Edit'); $assert_session->fieldValueEquals('label', $name); $assert_session->fieldValueEquals('description', $description); - $assert_session->fieldValueEquals('type', 'generic'); + $assert_session->fieldValueEquals('type', 'test'); $assert_session->fieldValueEquals('label', $name); $assert_session->checkboxNotChecked('edit-options-new-revision'); $assert_session->checkboxChecked('edit-options-status'); $assert_session->checkboxNotChecked('edit-options-queue-thumbnail-downloads'); $assert_session->pageTextContains('Create new revision'); - $assert_session->pageTextContains('Automatically create a new revision of media entities. Users with the Administer media permission will be able to override this option.'); + $assert_session->pageTextContains('Automatically create new revisions. Users with the Administer media permission will be able to override this option.'); $assert_session->pageTextContains('Download thumbnails via a queue.'); - $assert_session->pageTextContains('Entities will be automatically published when they are created.'); - $assert_session->pageTextContains('No metadata fields available.'); - $assert_session->pageTextContains('Media type plugins can provide metadata fields such as title, caption, size information, credits, ... Media entity 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.'); + $assert_session->pageTextContains('Media will be automatically published when created.'); + $assert_session->pageTextContains('Media handlers can provide metadata fields such as title, caption, size information, credits, ... Media entity 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.'); // Try to change media type and check if new configuration sub-form appears. - $page->selectFieldOption('type', 'test_type'); + $page->selectFieldOption('type', 'test'); $assert_session->assertWaitOnAjaxRequest(); $assert_session->fieldExists('Test config value'); $assert_session->fieldValueEquals('Test config value', 'This is default value.'); @@ -104,20 +110,20 @@ public function testMediaBundles() { $new_description = $this->randomMachineName(); $page->fillField('label', $new_name); $page->fillField('description', $new_description); - $page->selectFieldOption('type', 'test_type'); + $page->selectFieldOption('type', 'test'); $page->fillField('Test config value', 'This is new config value.'); $page->selectFieldOption('field_mapping[field_1]', 'name'); $page->checkField('options[new_revision]'); $page->uncheckField('options[status]'); $page->checkField('options[queue_thumbnail_downloads]'); - $page->pressButton('Save media bundle'); + $page->pressButton('Save'); $assert_session->statusCodeEquals(200); // Test if edit worked and if new field values have been saved as expected. $this->drupalGet('admin/structure/media/manage/' . $this->testBundle->id()); $assert_session->fieldValueEquals('label', $new_name); $assert_session->fieldValueEquals('description', $new_description); - $assert_session->fieldValueEquals('type', 'test_type'); + $assert_session->fieldValueEquals('type', 'test'); $assert_session->checkboxChecked('options[new_revision]'); $assert_session->checkboxNotChecked('options[status]'); $assert_session->checkboxChecked('options[queue_thumbnail_downloads]'); @@ -132,7 +138,7 @@ public function testMediaBundles() { $this->assertEquals($loaded_bundle->id(), $this->testBundle->id()); $this->assertEquals($loaded_bundle->label(), $new_name); $this->assertEquals($loaded_bundle->getDescription(), $new_description); - $this->assertEquals($loaded_bundle->getType()->getPluginId(), 'test_type'); + $this->assertEquals($loaded_bundle->getType()->getPluginId(), 'test'); $this->assertEquals($loaded_bundle->getType()->getConfiguration()['test_config_value'], 'This is new config value.'); $this->assertTrue($loaded_bundle->shouldCreateNewRevision()); $this->assertTrue($loaded_bundle->getQueueThumbnailDownloads()); @@ -151,7 +157,7 @@ public function testMediaBundles() { $assert_session->addressEquals('admin/structure/media/manage/' . $this->testBundle->id() . '/delete'); $page->pressButton('Delete'); $assert_session->addressEquals('admin/structure/media'); - $assert_session->pageTextContains('The media bundle ' . $new_name . ' has been deleted.'); + $assert_session->pageTextContains('The media type ' . $new_name . ' has been deleted.'); // Test bundle delete prevention when there is existing media. $bundle2 = $this->drupalCreateMediaBundle(); diff --git a/core/modules/media_entity/tests/src/Kernel/BasicCreationTest.php b/core/modules/media_entity/tests/src/Kernel/BasicCreationTest.php index d5aef44..b7c785f 100644 --- a/core/modules/media_entity/tests/src/Kernel/BasicCreationTest.php +++ b/core/modules/media_entity/tests/src/Kernel/BasicCreationTest.php @@ -20,6 +20,7 @@ class BasicCreationTest extends KernelTestBase { */ public static $modules = [ 'media_entity', + 'media_entity_test_handler', 'image', 'user', 'field', @@ -52,7 +53,7 @@ protected function setUp() { $this->testBundle = MediaBundle::create([ 'id' => $id, 'label' => $id, - 'type' => 'generic', + 'type' => 'test', 'type_configuration' => [], 'field_map' => [], 'new_revision' => FALSE, @@ -69,16 +70,16 @@ public function testMediaBundleCreation() { $bundle_storage = $this->container->get('entity_type.manager')->getStorage('media_bundle'); $bundle_exists = (bool) $bundle_storage->load($this->testBundle->id()); - $this->assertTrue($bundle_exists, 'The new media bundle has not been correctly created in the database.'); + $this->assertTrue($bundle_exists, 'The new media type has not been correctly created in the database.'); // Test default bundle created from default configuration. $this->container->get('module_installer')->install(['media_entity_test_bundle']); $test_bundle = $bundle_storage->load('test'); - $this->assertTrue((bool) $test_bundle, 'The media bundle from default configuration has not been created in the database.'); - $this->assertEquals($test_bundle->get('label'), 'Test bundle', 'Could not assure the correct bundle label.'); - $this->assertEquals($test_bundle->get('description'), 'Test bundle.', 'Could not assure the correct bundle description.'); - $this->assertEquals($test_bundle->get('type'), 'generic', 'Could not assure the correct bundle plugin type.'); - $this->assertEquals($test_bundle->get('type_configuration'), [], 'Could not assure the correct plugin configuration.'); + $this->assertTrue((bool) $test_bundle, 'The media type from default configuration has not been created in the database.'); + $this->assertEquals($test_bundle->get('label'), 'Test type', 'Could not assure the correct type name.'); + $this->assertEquals($test_bundle->get('description'), 'Test type.', 'Could not assure the correct type description.'); + $this->assertEquals($test_bundle->get('type'), 'test', 'Could not assure the correct handler.'); + $this->assertEquals($test_bundle->get('type_configuration'), ['test_config_value' => 'Kakec'], 'Could not assure the correct handler configuration.'); $this->assertEquals($test_bundle->get('field_map'), [], 'Could not assure the correct field map.'); } @@ -97,7 +98,7 @@ public function testMediaEntityCreation() { $media_exists = (bool) Media::load($media->id()); $this->assertTrue($media_exists, 'The new media entity has not been created in the database.'); - $this->assertEquals($media->bundle(), $this->testBundle->id(), 'The media was not created with the correct bundle.'); + $this->assertEquals($media->bundle(), $this->testBundle->id(), 'The media was not created with the correct type.'); $this->assertEquals($media->label(), 'Unnamed', 'The media was not created with the correct name.'); // Test the creation of a media without user-defined label and check if a @@ -107,7 +108,7 @@ public function testMediaEntityCreation() { ]); $media->save(); $expected_name = 'media' . ':' . $this->testBundle->id() . ':' . $media->uuid(); - $this->assertEquals($media->bundle(), $this->testBundle->id(), 'The media was not created with correct bundle.'); + $this->assertEquals($media->bundle(), $this->testBundle->id(), 'The media was not created with correct type.'); $this->assertEquals($media->label(), $expected_name, 'The media was not created with a default name.'); } diff --git a/core/modules/media_entity/tests/src/Kernel/TokensTest.php b/core/modules/media_entity/tests/src/Kernel/TokensTest.php index 8d7032a..86ef68a 100644 --- a/core/modules/media_entity/tests/src/Kernel/TokensTest.php +++ b/core/modules/media_entity/tests/src/Kernel/TokensTest.php @@ -21,6 +21,7 @@ class TokensTest extends EntityKernelTestBase { */ public static $modules = [ 'media_entity', + 'media_entity_test_handler', 'path', 'file', 'image', @@ -43,14 +44,14 @@ protected function setUp() { * Tests some of the tokens provided by media_entity. */ public function testMediaEntityTokens() { - // Create a generic media bundle. + // Create a test media bundle. $bundle_name = $this->randomMachineName(); MediaBundle::create([ 'id' => $bundle_name, 'label' => $bundle_name, - 'type' => 'generic', - 'type_configuration' => [], + 'type' => 'test', + 'type_configuration' => ['test_config_value' => 'Kakec'], 'field_map' => [], 'status' => 1, 'new_revision' => FALSE,