composer update
This commit is contained in:
parent
f6abc3dce2
commit
71dfaca858
1753 changed files with 45274 additions and 14619 deletions
|
@ -185,20 +185,11 @@ class Media extends EditorialContentEntityBase implements MediaInterface {
|
|||
// Set the thumbnail alt.
|
||||
$media_source = $this->getSource();
|
||||
$plugin_definition = $media_source->getPluginDefinition();
|
||||
|
||||
$this->thumbnail->alt = '';
|
||||
if (!empty($plugin_definition['thumbnail_alt_metadata_attribute'])) {
|
||||
$this->thumbnail->alt = $media_source->getMetadata($this, $plugin_definition['thumbnail_alt_metadata_attribute']);
|
||||
}
|
||||
else {
|
||||
$this->thumbnail->alt = $this->t('Thumbnail', [], ['langcode' => $this->langcode->value]);
|
||||
}
|
||||
|
||||
// Set the thumbnail title.
|
||||
if (!empty($plugin_definition['thumbnail_title_metadata_attribute'])) {
|
||||
$this->thumbnail->title = $media_source->getMetadata($this, $plugin_definition['thumbnail_title_metadata_attribute']);
|
||||
}
|
||||
else {
|
||||
$this->thumbnail->title = $this->label();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
|
@ -304,6 +304,17 @@ class MediaTypeForm extends EntityForm {
|
|||
*/
|
||||
protected function actions(array $form, FormStateInterface $form_state) {
|
||||
$actions = parent::actions($form, $form_state);
|
||||
|
||||
// If the media source has not been chosen yet, turn the submit button into
|
||||
// a button. This rebuilds the form with the media source's configuration
|
||||
// form visible, instead of saving the media type. This allows users to
|
||||
// create a media type without JavaScript enabled. With JavaScript enabled,
|
||||
// this rebuild occurs during an AJAX request.
|
||||
// @see \Drupal\media\MediaTypeForm::ajaxHandlerData()
|
||||
if (empty($this->getEntity()->get('source'))) {
|
||||
$actions['submit']['#type'] = 'button';
|
||||
}
|
||||
|
||||
$actions['submit']['#value'] = $this->t('Save');
|
||||
$actions['delete']['#value'] = $this->t('Delete');
|
||||
$actions['delete']['#access'] = $this->entity->access('delete');
|
||||
|
|
|
@ -7,7 +7,6 @@ use Drupal\Core\Cache\CacheBackendInterface;
|
|||
use Drupal\Core\Cache\UseCacheBackendTrait;
|
||||
use GuzzleHttp\ClientInterface;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Symfony\Component\Serializer\Encoder\XmlEncoder;
|
||||
|
||||
/**
|
||||
* Fetches and caches oEmbed resources.
|
||||
|
@ -69,8 +68,7 @@ class ResourceFetcher implements ResourceFetcherInterface {
|
|||
$content = (string) $response->getBody();
|
||||
|
||||
if (strstr($format, 'text/xml') || strstr($format, 'application/xml')) {
|
||||
$encoder = new XmlEncoder();
|
||||
$data = $encoder->decode($content, 'xml');
|
||||
$data = $this->parseResourceXml($content, $url);
|
||||
}
|
||||
elseif (strstr($format, 'text/javascript') || strstr($format, 'application/json')) {
|
||||
$data = Json::decode($content);
|
||||
|
@ -194,4 +192,42 @@ class ResourceFetcher implements ResourceFetcherInterface {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses XML resource data.
|
||||
*
|
||||
* @param string $data
|
||||
* The raw XML for the resource.
|
||||
* @param string $url
|
||||
* The resource URL.
|
||||
*
|
||||
* @return array
|
||||
* The parsed resource data.
|
||||
*
|
||||
* @throws \Drupal\media\OEmbed\ResourceException
|
||||
* If the resource data could not be parsed.
|
||||
*/
|
||||
protected function parseResourceXml($data, $url) {
|
||||
// Enable userspace error handling.
|
||||
$was_using_internal_errors = libxml_use_internal_errors(TRUE);
|
||||
libxml_clear_errors();
|
||||
|
||||
$content = simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA);
|
||||
// Restore the previous error handling behavior.
|
||||
libxml_use_internal_errors($was_using_internal_errors);
|
||||
|
||||
$error = libxml_get_last_error();
|
||||
if ($error) {
|
||||
libxml_clear_errors();
|
||||
throw new ResourceException($error->message, $url);
|
||||
}
|
||||
elseif ($content === FALSE) {
|
||||
throw new ResourceException('The fetched resource could not be parsed.', $url);
|
||||
}
|
||||
|
||||
// Convert XML to JSON so that the parsed resource has a consistent array
|
||||
// structure, regardless of any XML attributes or quirks of the XML parser.
|
||||
$data = Json::encode($content);
|
||||
return Json::decode($data);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,7 +22,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
* label = @Translation("Image"),
|
||||
* description = @Translation("Use local images for reusable media."),
|
||||
* allowed_field_types = {"image"},
|
||||
* default_thumbnail_filename = "no-thumbnail.png"
|
||||
* default_thumbnail_filename = "no-thumbnail.png",
|
||||
* thumbnail_alt_metadata_attribute = "thumbnail_alt_value"
|
||||
* )
|
||||
*/
|
||||
class Image extends File {
|
||||
|
@ -138,6 +139,9 @@ class Image extends File {
|
|||
|
||||
case 'thumbnail_uri':
|
||||
return $uri;
|
||||
|
||||
case 'thumbnail_alt_value':
|
||||
return $media->get($this->configuration['source_field'])->alt ?: parent::getMetadata($media, $name);
|
||||
}
|
||||
|
||||
return parent::getMetadata($media, $name);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||
<oembed>
|
||||
<type>video</type>
|
||||
<version>1.0</version>
|
||||
<version type="float">1.0</version>
|
||||
<title>Let's Not Get a Drink Sometime</title>
|
||||
<https/>
|
||||
<author_name>CollegeHumor</author_name>
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\media\Functional;
|
||||
|
||||
use Drupal\media\Entity\MediaType;
|
||||
|
||||
/**
|
||||
* Ensures that media UI works correctly without JavaScript.
|
||||
*
|
||||
* @group media
|
||||
*/
|
||||
class MediaTypeCreationTest extends MediaFunctionalTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'media_test_source',
|
||||
];
|
||||
|
||||
/**
|
||||
* Tests the media type creation form with only the mandatory options.
|
||||
*/
|
||||
public function testMediaTypeCreationForm() {
|
||||
$machine_name = mb_strtolower($this->randomMachineName());
|
||||
|
||||
$this->drupalGet('/admin/structure/media/add');
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
$this->assertSession()->fieldExists('label')->setValue($this->randomString());
|
||||
$this->assertSession()->fieldExists('id')->setValue($machine_name);
|
||||
$this->assertSession()->selectExists('source')->selectOption('test');
|
||||
$this->assertSession()->buttonExists('Save')->press();
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
$this->assertSession()->fieldValueEquals('Test config value', 'This is default value.');
|
||||
$this->assertSession()->buttonExists('Save')->press();
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
$this->assertSession()->addressEquals('admin/structure/media');
|
||||
|
||||
$this->assertInstanceOf(MediaType::class, MediaType::load($machine_name));
|
||||
}
|
||||
|
||||
}
|
|
@ -248,7 +248,7 @@ class MediaUiFunctionalTest extends MediaFunctionalTestBase {
|
|||
// Unlimited value field.
|
||||
'unlimited_value:single_type:create_list' => [FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, [TRUE], TRUE],
|
||||
// Unlimited value field with the tags widget.
|
||||
'unlimited_value:single_type:create_list' => [FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, [TRUE], TRUE, 'entity_reference_autocomplete_tags'],
|
||||
'unlimited_value:single_type:create_list:tags' => [FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, [TRUE], TRUE, 'entity_reference_autocomplete_tags'],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -167,13 +167,13 @@ abstract class MediaResourceTestBase extends EntityResourceTestBase {
|
|||
],
|
||||
'thumbnail' => [
|
||||
[
|
||||
'alt' => 'Thumbnail',
|
||||
'alt' => '',
|
||||
'width' => 180,
|
||||
'height' => 180,
|
||||
'target_id' => (int) $thumbnail->id(),
|
||||
'target_type' => 'file',
|
||||
'target_uuid' => $thumbnail->uuid(),
|
||||
'title' => 'Llama',
|
||||
'title' => NULL,
|
||||
'url' => $thumbnail->url(),
|
||||
],
|
||||
],
|
||||
|
|
|
@ -59,6 +59,8 @@ class MediaSourceImageTest extends MediaSourceTestBase {
|
|||
|
||||
// Make sure the thumbnail is displayed from uploaded image.
|
||||
$assert_session->elementAttributeContains('css', '.image-style-thumbnail', 'src', 'example_1.jpeg');
|
||||
// Ensure the thumbnail has the correct alt attribute.
|
||||
$assert_session->elementAttributeContains('css', '.image-style-thumbnail', 'alt', 'Image Alt Text 1');
|
||||
|
||||
// Load the media and check that all fields are properly populated.
|
||||
$media = Media::load(1);
|
||||
|
|
|
@ -40,7 +40,6 @@ class MediaSourceTest extends MediaKernelTestBase {
|
|||
'value' => 'Snowball',
|
||||
],
|
||||
'thumbnail_uri' => [
|
||||
'title' => 'Thumbnail',
|
||||
'value' => 'public://TheSisko.png',
|
||||
],
|
||||
]);
|
||||
|
@ -230,7 +229,7 @@ class MediaSourceTest extends MediaKernelTestBase {
|
|||
|
||||
// Save a media item and make sure thumbnail was added.
|
||||
\Drupal::state()->set('media_source_test_attributes', [
|
||||
'thumbnail_uri' => ['title' => 'Thumbnail', 'value' => 'public://thumbnail1.jpg'],
|
||||
'thumbnail_uri' => ['value' => 'public://thumbnail1.jpg'],
|
||||
]);
|
||||
/** @var \Drupal\media\MediaInterface $media */
|
||||
$media = Media::create([
|
||||
|
@ -242,45 +241,46 @@ class MediaSourceTest extends MediaKernelTestBase {
|
|||
$this->assertSame('public://thumbnail1.jpg', $media_source->getMetadata($media, 'thumbnail_uri'), 'Value of the thumbnail metadata attribute is not correct.');
|
||||
$media->save();
|
||||
$this->assertSame('public://thumbnail1.jpg', $media->thumbnail->entity->getFileUri(), 'Thumbnail was not added to the media item.');
|
||||
$this->assertSame('Mr. Jones', $media->thumbnail->title, 'Title text was not set on the thumbnail.');
|
||||
$this->assertEquals('Thumbnail', $media->thumbnail->alt, 'Alt text was not set on the thumbnail.');
|
||||
// We expect the title not to be present on the Thumbnail.
|
||||
$this->assertEmpty($media->thumbnail->title);
|
||||
$this->assertSame('', $media->thumbnail->alt);
|
||||
|
||||
// Now change the metadata attribute and make sure that the thumbnail stays
|
||||
// the same.
|
||||
\Drupal::state()->set('media_source_test_attributes', [
|
||||
'thumbnail_uri' => ['title' => 'Thumbnail', 'value' => 'public://thumbnail2.jpg'],
|
||||
'thumbnail_uri' => ['value' => 'public://thumbnail2.jpg'],
|
||||
]);
|
||||
$this->assertSame('public://thumbnail2.jpg', $media_source->getMetadata($media, 'thumbnail_uri'), 'Value of the thumbnail metadata attribute is not correct.');
|
||||
$media->save();
|
||||
$this->assertSame('public://thumbnail1.jpg', $media->thumbnail->entity->getFileUri(), 'Thumbnail was not preserved.');
|
||||
$this->assertSame('Mr. Jones', $media->thumbnail->title, 'Title text was not set on the thumbnail.');
|
||||
$this->assertEquals('Thumbnail', $media->thumbnail->alt, 'Alt text was not set on the thumbnail.');
|
||||
$this->assertEmpty($media->thumbnail->title);
|
||||
$this->assertSame('', $media->thumbnail->alt);
|
||||
|
||||
// Remove the thumbnail and make sure that it is auto-updated on save.
|
||||
$media->thumbnail->target_id = NULL;
|
||||
$this->assertSame('public://thumbnail2.jpg', $media_source->getMetadata($media, 'thumbnail_uri'), 'Value of the thumbnail metadata attribute is not correct.');
|
||||
$media->save();
|
||||
$this->assertSame('public://thumbnail2.jpg', $media->thumbnail->entity->getFileUri(), 'New thumbnail was not added to the media item.');
|
||||
$this->assertSame('Mr. Jones', $media->thumbnail->title, 'Title text was not set on the thumbnail.');
|
||||
$this->assertEquals('Thumbnail', $media->thumbnail->alt, 'Alt text was not set on the thumbnail.');
|
||||
$this->assertEmpty($media->thumbnail->title);
|
||||
$this->assertSame('', $media->thumbnail->alt);
|
||||
|
||||
// Change the metadata attribute again, change the source field value too
|
||||
// and make sure that the thumbnail updates.
|
||||
\Drupal::state()->set('media_source_test_attributes', [
|
||||
'thumbnail_uri' => ['title' => 'Thumbnail', 'value' => 'public://thumbnail1.jpg'],
|
||||
'thumbnail_uri' => ['value' => 'public://thumbnail1.jpg'],
|
||||
]);
|
||||
$media->field_media_test->value = 'some_new_value';
|
||||
$this->assertSame('public://thumbnail1.jpg', $media_source->getMetadata($media, 'thumbnail_uri'), 'Value of the thumbnail metadata attribute is not correct.');
|
||||
$media->save();
|
||||
$this->assertSame('public://thumbnail1.jpg', $media->thumbnail->entity->getFileUri(), 'New thumbnail was not added to the media item.');
|
||||
$this->assertSame('Mr. Jones', $media->thumbnail->title, 'Title text was not set on the thumbnail.');
|
||||
$this->assertEquals('Thumbnail', $media->thumbnail->alt, 'Alt text was not set on the thumbnail.');
|
||||
$this->assertEmpty($media->thumbnail->title);
|
||||
$this->assertSame('', $media->thumbnail->alt);
|
||||
|
||||
// Change the thumbnail metadata attribute and make sure that the thumbnail
|
||||
// is set correctly.
|
||||
\Drupal::state()->set('media_source_test_attributes', [
|
||||
'thumbnail_uri' => ['title' => 'Should not be used', 'value' => 'public://thumbnail1.jpg'],
|
||||
'alternative_thumbnail_uri' => ['title' => 'Should be used', 'value' => 'public://thumbnail2.jpg'],
|
||||
'thumbnail_uri' => ['value' => 'public://thumbnail1.jpg'],
|
||||
'alternative_thumbnail_uri' => ['value' => 'public://thumbnail2.jpg'],
|
||||
]);
|
||||
\Drupal::state()->set('media_source_test_definition', ['thumbnail_uri_metadata_attribute' => 'alternative_thumbnail_uri']);
|
||||
$media = Media::create([
|
||||
|
@ -293,14 +293,14 @@ class MediaSourceTest extends MediaKernelTestBase {
|
|||
$this->assertSame('public://thumbnail2.jpg', $media_source->getMetadata($media, 'alternative_thumbnail_uri'), 'Value of the thumbnail metadata attribute is not correct.');
|
||||
$media->save();
|
||||
$this->assertSame('public://thumbnail2.jpg', $media->thumbnail->entity->getFileUri(), 'Correct metadata attribute was not used for the thumbnail.');
|
||||
$this->assertSame('Mr. Jones', $media->thumbnail->title, 'Title text was not set on the thumbnail.');
|
||||
$this->assertEquals('Thumbnail', $media->thumbnail->alt, 'Alt text was not set on the thumbnail.');
|
||||
$this->assertEmpty($media->thumbnail->title);
|
||||
$this->assertSame('', $media->thumbnail->alt);
|
||||
|
||||
// Enable queued thumbnails and make sure that the entity gets the default
|
||||
// thumbnail initially.
|
||||
\Drupal::state()->set('media_source_test_definition', []);
|
||||
\Drupal::state()->set('media_source_test_attributes', [
|
||||
'thumbnail_uri' => ['title' => 'Should not be used', 'value' => 'public://thumbnail1.jpg'],
|
||||
'thumbnail_uri' => ['value' => 'public://thumbnail1.jpg'],
|
||||
]);
|
||||
$this->testMediaType->setQueueThumbnailDownloadsStatus(TRUE)->save();
|
||||
$media = Media::create([
|
||||
|
@ -311,8 +311,8 @@ class MediaSourceTest extends MediaKernelTestBase {
|
|||
$this->assertSame('public://thumbnail1.jpg', $media->getSource()->getMetadata($media, 'thumbnail_uri'), 'Value of the metadata attribute is not correct.');
|
||||
$media->save();
|
||||
$this->assertSame('public://media-icons/generic/generic.png', $media->thumbnail->entity->getFileUri(), 'Default thumbnail was not set initially.');
|
||||
$this->assertSame('Mr. Jones', $media->thumbnail->title, 'Title text was not set on the thumbnail.');
|
||||
$this->assertEquals('Thumbnail', $media->thumbnail->alt, 'Alt text was not set on the thumbnail.');
|
||||
$this->assertEmpty($media->thumbnail->title);
|
||||
$this->assertSame('', $media->thumbnail->alt);
|
||||
|
||||
// Process the queue item and make sure that the thumbnail was updated too.
|
||||
$queue_name = 'media_entity_thumbnail';
|
||||
|
@ -330,18 +330,15 @@ class MediaSourceTest extends MediaKernelTestBase {
|
|||
|
||||
$media = Media::load($media->id());
|
||||
$this->assertSame('public://thumbnail1.jpg', $media->thumbnail->entity->getFileUri(), 'Thumbnail was not updated by the queue.');
|
||||
$this->assertSame('Mr. Jones', $media->thumbnail->title, 'Title text was not set on the thumbnail.');
|
||||
$this->assertSame('Thumbnail', $media->thumbnail->alt, 'Alt text was not set on the thumbnail.');
|
||||
$this->assertEmpty($media->thumbnail->title);
|
||||
$this->assertSame('', $media->thumbnail->alt);
|
||||
|
||||
// Set alt and title metadata attributes and make sure they are used for the
|
||||
// thumbnail.
|
||||
// Set the alt metadata attribute and make sure it's used for the thumbnail.
|
||||
\Drupal::state()->set('media_source_test_definition', [
|
||||
'thumbnail_alt_metadata_attribute' => 'alt',
|
||||
'thumbnail_title_metadata_attribute' => 'title',
|
||||
]);
|
||||
\Drupal::state()->set('media_source_test_attributes', [
|
||||
'alt' => ['title' => 'Alt text', 'value' => 'This will be alt.'],
|
||||
'title' => ['title' => 'Title text', 'value' => 'This will be title.'],
|
||||
'alt' => ['value' => 'This will be alt.'],
|
||||
]);
|
||||
$media = Media::create([
|
||||
'bundle' => $this->testMediaType->id(),
|
||||
|
@ -350,8 +347,8 @@ class MediaSourceTest extends MediaKernelTestBase {
|
|||
]);
|
||||
$media->save();
|
||||
$this->assertSame('Boxer', $media->getName(), 'Correct name was not set on the media item.');
|
||||
$this->assertSame('This will be title.', $media->thumbnail->title, 'Title text was not set on the thumbnail.');
|
||||
$this->assertSame('This will be alt.', $media->thumbnail->alt, 'Alt text was not set on the thumbnail.');
|
||||
$this->assertEmpty($media->thumbnail->title);
|
||||
$this->assertSame('This will be alt.', $media->thumbnail->alt);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Reference in a new issue