Skip to content
Snippets Groups Projects

Issue #3450772: Media items created via the media library widget should have...

Open Issue #3450772: Media items created via the media library widget should have...
6 unresolved threads
6 unresolved threads

Issue #3450772: Media items created via the media library widget should have the same langcode as their parent entity

Closes #3450772

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
365 372 $assert_session->fieldValueEquals('Alternative text', '', $media_item_three);
366 373 }
367 374
375 /**
376 * Tests created medias have the same language as the edited translation.
377 */
378 public function testWidgetUploadMediaLanguage(): void {
379
380 // Retrieve a test image file.
381 foreach ($this->getTestFiles('image') as $image) {
382 $extension = pathinfo($image->filename, PATHINFO_EXTENSION);
383 if ($extension === 'png') {
384 $png_image = $image;
385 }
386 }
387 if (!isset($png_image)) {
  • 433 // Press save button on node edit form page
    434 $this->submitForm([], 'Save (this translation)');
    435 $this->waitForText('has been updated');
    436
    437 // Check translation edit form.
    438 $this->drupalGet('es/node/' . $node->id() . '/edit');
    439 // Open the media library and upload a file.
    440 $this->openMediaLibraryForField('field_unlimited_media');
    441 $this->switchToMediaType('Three');
    442 $this->addMediaFileToField('Add files', $this->container->get('file_system')->realpath($png_image->uri));
    443 $this->assertMediaAdded();
    444 $this->waitForFieldExists('Alternative text')->setValue($this->randomString());
    445 $this->pressSaveButton();
    446 // Check that the created media item has the same language
    447 // as the translation being edited.
    448 $media_items = Media::loadMultiple();
  • 365 372 $assert_session->fieldValueEquals('Alternative text', '', $media_item_three);
    366 373 }
    367 374
    375 /**
    376 * Tests created medias have the same language as the edited translation.
    377 */
    378 public function testWidgetUploadMediaLanguage(): void {
  • added 1 commit

    • 7f9ed88d - Move a multilingual test to its own file so we don't install multilingual...

    Compare with previous version

  • 526 527 * The name of the media type's source field.
    527 528 * @param mixed $source_field_value
    528 529 * The value for the source field of the media item.
    530 * @param mixed $langcode
    531 * The langcode of the media item.
  • 526 527 * The name of the media type's source field.
    527 528 * @param mixed $source_field_value
    528 529 * The value for the source field of the media item.
    530 * @param mixed $langcode
    531 * The langcode of the media item.
    529 532 *
    530 533 * @return \Drupal\media\MediaInterface
    531 534 * An unsaved media entity.
    532 535 */
    533 protected function createMediaFromValue(MediaTypeInterface $media_type, EntityStorageInterface $media_storage, $source_field_name, $source_field_value) {
    536 protected function createMediaFromValue(MediaTypeInterface $media_type, EntityStorageInterface $media_storage, $source_field_name, $source_field_value, $langcode = NULL) {
    • Suggested change
      536 protected function createMediaFromValue(MediaTypeInterface $media_type, EntityStorageInterface $media_storage, $source_field_name, $source_field_value, $langcode = NULL) {
      536 protected function createMediaFromValue(MediaTypeInterface $media_type, EntityStorageInterface $media_storage, $source_field_name, $source_field_value, mixed $langcode = NULL) {
    • Please register or sign in to reply
  • 499 499 $media_type = $this->getMediaType($form_state);
    500 500 $media_storage = $this->entityTypeManager->getStorage('media');
    501 501 $source_field_name = $this->getSourceFieldName($media_type);
    502 $media = array_map(function ($source_field_value) use ($media_type, $media_storage, $source_field_name) {
    503 return $this->createMediaFromValue($media_type, $media_storage, $source_field_name, $source_field_value);
    502 $langcode = $this->getMediaLibraryState($form_state)->getOpenerParameters()['langcode'] ?? NULL;
    Please register or sign in to reply
    Loading