Skip to content
Snippets Groups Projects
Unverified Commit 61aa003c authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3100470 by phenaproxima, oknate, Meenakshi.g, Wim Leers, bnjmnm:...

Issue #3100470 by phenaproxima, oknate, Meenakshi.g, Wim Leers, bnjmnm: EditorMediaDialog triggers an "undefined index" notice for data-view-mode
parent 11c46fc2
No related branches found
No related tags found
6 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!1012Issue #3226887: Hreflang on non-canonical content pages,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10,!596Issue #3046532: deleting an entity reference field, used in a contextual view, makes the whole site unrecoverable,!496Issue #2463967: Use .user.ini file for PHP settings,!144Issue #2666286: Clean up menu_ui to conform to Drupal coding standards
......@@ -173,7 +173,7 @@ public function buildForm(array $form, FormStateInterface $form_state, EditorInt
];
$view_mode_options = array_intersect_key($this->entityDisplayRepository->getViewModeOptions('media'), $media_embed_filter->settings['allowed_view_modes']);
$default_view_mode = static::getViewModeDefaultValue($view_mode_options, $media_embed_filter, $media_embed_element['data-view-mode']);
$default_view_mode = static::getViewModeDefaultValue($view_mode_options, $media_embed_filter, $media_embed_element['data-view-mode'] ?? NULL);
$form['view_mode'] = [
'#title' => $this->t("Display"),
......
<?php
namespace Drupal\Tests\media\Kernel;
use Drupal\Core\Form\FormState;
use Drupal\editor\EditorInterface;
use Drupal\filter\Entity\FilterFormat;
use Drupal\KernelTests\KernelTestBase;
use Drupal\media\Entity\Media;
use Drupal\media\Form\EditorMediaDialog;
use Drupal\Tests\media\Traits\MediaTypeCreationTrait;
/**
* @coversDefaultClass \Drupal\media\Form\EditorMediaDialog
* @group media
*/
class EditorMediaDialogTest extends KernelTestBase {
use MediaTypeCreationTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'field',
'file',
'filter',
'image',
'media',
'media_test_source',
'system',
'user',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installSchema('file', ['file_usage']);
$this->installEntitySchema('file');
$this->installEntitySchema('media');
$this->installEntitySchema('user');
}
/**
* Tests that the form builds successfully.
*
* @covers ::buildForm
*/
public function testBuildForm() {
$format = FilterFormat::create([
'filters' => [
'media_embed' => ['status' => TRUE],
],
]);
$editor = $this->prophesize(EditorInterface::class);
$editor->getFilterFormat()->willReturn($format);
// Create a sample media entity to be embedded.
$media = Media::create([
'bundle' => $this->createMediaType('test')->id(),
'name' => 'Screaming hairy armadillo',
'field_media_test' => $this->randomString(),
]);
$media->save();
$form_state = new FormState();
$form_state->setUserInput([
'editor_object' => [
'attributes' => [
'data-entity-type' => 'media',
'data-entity-uuid' => $media->uuid(),
'data-align' => 'center',
],
'hasCaption' => 'false',
'label' => $media->label(),
'link' => '',
'hostEntityLangcode' => $media->language()->getId(),
'classes' => '',
],
]);
$form_state->setRequestMethod('POST');
EditorMediaDialog::create($this->container)
->buildForm([], $form_state, $editor->reveal());
$this->pass('Form was built without errors.');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment