Update to Drupal 8.1.5. For more information, see https://www.drupal.org/project/drupal/releases/8.1.5
This commit is contained in:
parent
13b6ca7cc2
commit
38ba7c357d
342 changed files with 7814 additions and 1534 deletions
|
@ -188,14 +188,14 @@ class ImageFormatter extends ImageFormatterBase implements ContainerFactoryPlugi
|
|||
$image_style_setting = $this->getSetting('image_style');
|
||||
|
||||
// Collect cache tags to be added for each item in the field.
|
||||
$cache_tags = array();
|
||||
$base_cache_tags = [];
|
||||
if (!empty($image_style_setting)) {
|
||||
$image_style = $this->imageStyleStorage->load($image_style_setting);
|
||||
$cache_tags = $image_style->getCacheTags();
|
||||
$base_cache_tags = $image_style->getCacheTags();
|
||||
}
|
||||
|
||||
foreach ($files as $delta => $file) {
|
||||
$cache_contexts = array();
|
||||
$cache_contexts = [];
|
||||
if (isset($link_file)) {
|
||||
$image_uri = $file->getFileUri();
|
||||
// @todo Wrap in file_url_transform_relative(). This is currently
|
||||
|
@ -206,7 +206,7 @@ class ImageFormatter extends ImageFormatterBase implements ContainerFactoryPlugi
|
|||
$url = Url::fromUri(file_create_url($image_uri));
|
||||
$cache_contexts[] = 'url.site';
|
||||
}
|
||||
$cache_tags = Cache::mergeTags($cache_tags, $file->getCacheTags());
|
||||
$cache_tags = Cache::mergeTags($base_cache_tags, $file->getCacheTags());
|
||||
|
||||
// Extract field item attributes for the theme function, and unset them
|
||||
// from the $item so that the field template does not re-render them.
|
||||
|
|
|
@ -343,7 +343,7 @@ class ImageItem extends FileItem {
|
|||
$image = File::create();
|
||||
$image->setFileUri($path);
|
||||
$image->setOwnerId(\Drupal::currentUser()->id());
|
||||
$image->setMimeType('image/' . pathinfo($path, PATHINFO_EXTENSION));
|
||||
$image->setMimeType(\Drupal::service('file.mime_type.guesser')->guess($path));
|
||||
$image->setFileName(drupal_basename($path));
|
||||
$destination_dir = static::doGetUploadLocation($settings);
|
||||
file_prepare_directory($destination_dir, FILE_CREATE_DIRECTORY);
|
||||
|
|
102
core/modules/image/tests/src/Kernel/ImageFormatterTest.php
Normal file
102
core/modules/image/tests/src/Kernel/ImageFormatterTest.php
Normal file
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\image\Kernel;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\Tests\field\Kernel\FieldKernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests the image field rendering using entity fields of the image field type.
|
||||
*
|
||||
* @group image
|
||||
*/
|
||||
class ImageFormatterTest extends FieldKernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('file', 'image');
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $entityType;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $bundle;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $fieldName;
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface
|
||||
*/
|
||||
protected $display;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installConfig(['field']);
|
||||
$this->installEntitySchema('entity_test');
|
||||
$this->installEntitySchema('file');
|
||||
$this->installSchema('file', array('file_usage'));
|
||||
|
||||
$this->entityType = 'entity_test';
|
||||
$this->bundle = $this->entityType;
|
||||
$this->fieldName = Unicode::strtolower($this->randomMachineName());
|
||||
|
||||
FieldStorageConfig::create(array(
|
||||
'entity_type' => $this->entityType,
|
||||
'field_name' => $this->fieldName,
|
||||
'type' => 'image',
|
||||
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
|
||||
))->save();
|
||||
FieldConfig::create([
|
||||
'entity_type' => $this->entityType,
|
||||
'field_name' => $this->fieldName,
|
||||
'bundle' => $this->bundle,
|
||||
'settings' => [
|
||||
'file_extensions' => 'jpg',
|
||||
],
|
||||
])->save();
|
||||
|
||||
$this->display = entity_get_display($this->entityType, $this->bundle, 'default')
|
||||
->setComponent($this->fieldName, [
|
||||
'type' => 'image',
|
||||
'label' => 'hidden',
|
||||
]);
|
||||
$this->display->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the cache tags from image formatters.
|
||||
*/
|
||||
function testImageFormatterCacheTags() {
|
||||
// Create a test entity with the image field set.
|
||||
$entity = EntityTest::create([
|
||||
'name' => $this->randomMachineName(),
|
||||
]);
|
||||
$entity->{$this->fieldName}->generateSampleItems(2);
|
||||
$entity->save();
|
||||
|
||||
// Generate the render array to verify if the cache tags are as expected.
|
||||
$build = $this->display->build($entity);
|
||||
|
||||
$this->assertEquals($entity->{$this->fieldName}[0]->entity->getCacheTags(), $build[$this->fieldName][0]['#cache']['tags'], 'First image cache tags is as expected');
|
||||
$this->assertEquals($entity->{$this->fieldName}[1]->entity->getCacheTags(), $build[$this->fieldName][1]['#cache']['tags'], 'Second image cache tags is as expected');
|
||||
}
|
||||
|
||||
}
|
|
@ -53,6 +53,9 @@ class ImageItemTest extends FieldKernelTestBase {
|
|||
'entity_type' => 'entity_test',
|
||||
'field_name' => 'image_test',
|
||||
'bundle' => 'entity_test',
|
||||
'settings' => [
|
||||
'file_extensions' => 'jpg',
|
||||
],
|
||||
])->save();
|
||||
file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', 'public://example.jpg');
|
||||
$this->image = File::create([
|
||||
|
@ -123,6 +126,7 @@ class ImageItemTest extends FieldKernelTestBase {
|
|||
$entity = EntityTest::create();
|
||||
$entity->image_test->generateSampleItems();
|
||||
$this->entityValidateAndSave($entity);
|
||||
$this->assertEqual($entity->image_test->entity->get('filemime')->value, 'image/jpeg');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ class ImageStyleTest extends UnitTestCase {
|
|||
* @param \Drupal\image\ImageEffectInterface|\PHPUnit_Framework_MockObject_MockObject $image_effect
|
||||
* The image effect used for testing.
|
||||
*
|
||||
* @return \Drupal\image\ImageStyleInterface|\Drupal\image\ImageStyleInterface
|
||||
* @return \Drupal\image\ImageStyleInterface
|
||||
* The mocked image style.
|
||||
*/
|
||||
protected function getImageStyleMock($image_effect_id, $image_effect, $stubs = array()) {
|
||||
|
|
Reference in a new issue