Update to Drupal 8.2.0. For more information, see https://www.drupal.org/project/drupal/releases/8.2.0
This commit is contained in:
parent
2f563ab520
commit
f1c8716f57
1732 changed files with 52334 additions and 11780 deletions
|
@ -1,3 +1,2 @@
|
|||
administer image styles:
|
||||
title: 'Administer image styles'
|
||||
description: 'Create and modify styles for generating image modifications such as thumbnails.'
|
||||
|
|
|
@ -139,8 +139,8 @@ class ImageStyleDownloadController extends FileDownloadController {
|
|||
|
||||
// Don't start generating the image if the derivative already exists or if
|
||||
// generation is in progress in another thread.
|
||||
$lock_name = 'image_style_deliver:' . $image_style->id() . ':' . Crypt::hashBase64($image_uri);
|
||||
if (!file_exists($derivative_uri)) {
|
||||
$lock_name = 'image_style_deliver:' . $image_style->id() . ':' . Crypt::hashBase64($image_uri);
|
||||
$lock_acquired = $this->lock->acquire($lock_name);
|
||||
if (!$lock_acquired) {
|
||||
// Tell client to retry again in 3 seconds. Currently no browsers are
|
||||
|
|
|
@ -16,7 +16,7 @@ use Drupal\Component\Utility\Crypt;
|
|||
use Drupal\Component\Utility\UrlHelper;
|
||||
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
|
||||
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
|
||||
|
||||
use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
||||
/**
|
||||
* Defines an image style configuration entity.
|
||||
*
|
||||
|
@ -137,7 +137,7 @@ class ImageStyle extends ConfigEntityBase implements ImageStyleInterface, Entity
|
|||
if ($style->id() != $style->getOriginalId()) {
|
||||
// Loop through all entity displays looking for formatters / widgets using
|
||||
// the image style.
|
||||
foreach (entity_load_multiple('entity_view_display') as $display) {
|
||||
foreach (EntityViewDisplay::loadMultiple() as $display) {
|
||||
foreach ($display->getComponents() as $name => $options) {
|
||||
if (isset($options['type']) && $options['type'] == 'image' && $options['settings']['image_style'] == $style->getOriginalId()) {
|
||||
$options['settings']['image_style'] = $style->id();
|
||||
|
@ -146,7 +146,7 @@ class ImageStyle extends ConfigEntityBase implements ImageStyleInterface, Entity
|
|||
}
|
||||
}
|
||||
}
|
||||
foreach (entity_load_multiple('entity_form_display') as $display) {
|
||||
foreach (EntityViewDisplay::loadMultiple() as $display) {
|
||||
foreach ($display->getComponents() as $name => $options) {
|
||||
if (isset($options['type']) && $options['type'] == 'image_image' && $options['settings']['preview_image_style'] == $style->getOriginalId()) {
|
||||
$options['settings']['preview_image_style'] = $style->id();
|
||||
|
@ -162,15 +162,28 @@ class ImageStyle extends ConfigEntityBase implements ImageStyleInterface, Entity
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildUri($uri) {
|
||||
$scheme = $this->fileUriScheme($uri);
|
||||
if ($scheme) {
|
||||
$source_scheme = $scheme = $this->fileUriScheme($uri);
|
||||
$default_scheme = $this->fileDefaultScheme();
|
||||
|
||||
if ($source_scheme) {
|
||||
$path = $this->fileUriTarget($uri);
|
||||
// The scheme of derivative image files only needs to be computed for
|
||||
// source files not stored in the default scheme.
|
||||
if ($source_scheme != $default_scheme) {
|
||||
$class = $this->getStreamWrapperManager()->getClass($source_scheme);
|
||||
$is_writable = $class::getType() & StreamWrapperInterface::WRITE;
|
||||
|
||||
// Compute the derivative URI scheme. Derivatives created from writable
|
||||
// source stream wrappers will inherit the scheme. Derivatives created
|
||||
// from read-only stream wrappers will fall-back to the default scheme.
|
||||
$scheme = $is_writable ? $source_scheme : $default_scheme;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$path = $uri;
|
||||
$scheme = $this->fileDefaultScheme();
|
||||
$source_scheme = $scheme = $default_scheme;
|
||||
}
|
||||
return $scheme . '://styles/' . $this->id() . '/' . $scheme . '/' . $this->addExtension($path);
|
||||
return "$scheme://styles/{$this->id()}/$source_scheme/{$this->addExtension($path)}";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -211,7 +224,7 @@ class ImageStyle extends ConfigEntityBase implements ImageStyleInterface, Entity
|
|||
// to the actual file path, this avoids bootstrapping PHP once the files are
|
||||
// built.
|
||||
if ($clean_urls === FALSE && file_uri_scheme($uri) == 'public' && !file_exists($uri)) {
|
||||
$directory_path = \Drupal::service('stream_wrapper_manager')->getViaUri($uri)->getDirectoryPath();
|
||||
$directory_path = $this->getStreamWrapperManager()->getViaUri($uri)->getDirectoryPath();
|
||||
return Url::fromUri('base:' . $directory_path . '/' . file_uri_target($uri), array('absolute' => TRUE, 'query' => $token_query))->toString();
|
||||
}
|
||||
|
||||
|
@ -238,7 +251,7 @@ class ImageStyle extends ConfigEntityBase implements ImageStyleInterface, Entity
|
|||
}
|
||||
|
||||
// Delete the style directory in each registered wrapper.
|
||||
$wrappers = \Drupal::service('stream_wrapper_manager')->getWrappers(StreamWrapperInterface::WRITE_VISIBLE);
|
||||
$wrappers = $this->getStreamWrapperManager()->getWrappers(StreamWrapperInterface::WRITE_VISIBLE);
|
||||
foreach ($wrappers as $wrapper => $wrapper_data) {
|
||||
if (file_exists($directory = $wrapper . '://styles/' . $this->id())) {
|
||||
file_unmanaged_delete_recursive($directory);
|
||||
|
@ -495,4 +508,16 @@ class ImageStyle extends ConfigEntityBase implements ImageStyleInterface, Entity
|
|||
return file_default_scheme();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the stream wrapper manager service.
|
||||
*
|
||||
* @return \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface
|
||||
* The stream wrapper manager service
|
||||
*
|
||||
* @todo Properly inject this service in Drupal 9.0.x.
|
||||
*/
|
||||
protected function getStreamWrapperManager() {
|
||||
return \Drupal::service('stream_wrapper_manager');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
namespace Drupal\image\Form;
|
||||
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormState;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Form\SubformState;
|
||||
use Drupal\image\ConfigurableImageEffectInterface;
|
||||
use Drupal\image\ImageStyleInterface;
|
||||
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
|
||||
|
@ -25,7 +25,7 @@ abstract class ImageEffectFormBase extends FormBase {
|
|||
/**
|
||||
* The image effect.
|
||||
*
|
||||
* @var \Drupal\image\ImageEffectInterface
|
||||
* @var \Drupal\image\ImageEffectInterface|\Drupal\image\ConfigurableImageEffectInterface
|
||||
*/
|
||||
protected $imageEffect;
|
||||
|
||||
|
@ -73,7 +73,9 @@ abstract class ImageEffectFormBase extends FormBase {
|
|||
'#value' => $this->imageEffect->getPluginId(),
|
||||
);
|
||||
|
||||
$form['data'] = $this->imageEffect->buildConfigurationForm(array(), $form_state);
|
||||
$form['data'] = [];
|
||||
$subform_state = SubformState::createForSubform($form['data'], $form, $form_state);
|
||||
$form['data'] = $this->imageEffect->buildConfigurationForm($form['data'], $subform_state);
|
||||
$form['data']['#tree'] = TRUE;
|
||||
|
||||
// Check the URL for a weight, then the image effect, otherwise use default.
|
||||
|
@ -102,10 +104,7 @@ abstract class ImageEffectFormBase extends FormBase {
|
|||
public function validateForm(array &$form, FormStateInterface $form_state) {
|
||||
// The image effect configuration is stored in the 'data' key in the form,
|
||||
// pass that through for validation.
|
||||
$effect_data = (new FormState())->setValues($form_state->getValue('data'));
|
||||
$this->imageEffect->validateConfigurationForm($form, $effect_data);
|
||||
// Update the original form values.
|
||||
$form_state->setValue('data', $effect_data->getValues());
|
||||
$this->imageEffect->validateConfigurationForm($form['data'], SubformState::createForSubform($form['data'], $form, $form_state));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -116,10 +115,7 @@ abstract class ImageEffectFormBase extends FormBase {
|
|||
|
||||
// The image effect configuration is stored in the 'data' key in the form,
|
||||
// pass that through for submission.
|
||||
$effect_data = (new FormState())->setValues($form_state->getValue('data'));
|
||||
$this->imageEffect->submitConfigurationForm($form, $effect_data);
|
||||
// Update the original form values.
|
||||
$form_state->setValue('data', $effect_data->getValues());
|
||||
$this->imageEffect->submitConfigurationForm($form['data'], SubformState::createForSubform($form['data'], $form, $form_state));
|
||||
|
||||
$this->imageEffect->setWeight($form_state->getValue('weight'));
|
||||
if (!$this->imageEffect->getUuid()) {
|
||||
|
|
|
@ -70,7 +70,7 @@ class ScaleImageEffect extends ResizeImageEffect {
|
|||
'#type' => 'checkbox',
|
||||
'#default_value' => $this->configuration['upscale'],
|
||||
'#title' => t('Allow Upscaling'),
|
||||
'#description' => t('Let scale make images larger than their original size'),
|
||||
'#description' => t('Let scale make images larger than their original size.'),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\image\Tests;
|
||||
|
||||
use Drupal\image\Entity\ImageStyle;
|
||||
use Drupal\system\Tests\Image\ToolkitTestBase;
|
||||
|
||||
/**
|
||||
|
@ -162,6 +163,26 @@ class ImageEffectsTest extends ToolkitTestBase {
|
|||
$this->assertTrue($effects == $cached_effects, 'Cached effects are the same as generated effects.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if validation errors are passed plugin form to the parent form.
|
||||
*/
|
||||
public function testEffectFormValidationErrors() {
|
||||
$account = $this->drupalCreateUser(['administer image styles']);
|
||||
$this->drupalLogin($account);
|
||||
/** @var \Drupal\image\ImageStyleInterface $style */
|
||||
$style = ImageStyle::load('thumbnail');
|
||||
// Image Scale is the only effect shipped with 'thumbnail', by default.
|
||||
$uuids = $style->getEffects()->getInstanceIds();
|
||||
$uuid = key($uuids);
|
||||
|
||||
// We are posting the form with both, width and height, empty.
|
||||
$edit = ['data[width]' => '', 'data[height]' => ''];
|
||||
$path = 'admin/config/media/image-styles/manage/thumbnail/effects/' . $uuid;
|
||||
$this->drupalPostForm($path, $edit, t('Update effect'));
|
||||
// Check that the error message has been displayed.
|
||||
$this->assertText(t('Width and height can not both be blank.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts the effect processing of an image effect plugin.
|
||||
*
|
||||
|
|
|
@ -2,9 +2,8 @@
|
|||
|
||||
namespace Drupal\image\Tests;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\Tests\image\Kernel\ImageFieldCreationTrait;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
|
||||
/**
|
||||
* TODO: Test the following functions.
|
||||
|
@ -24,6 +23,8 @@ use Drupal\field\Entity\FieldStorageConfig;
|
|||
*/
|
||||
abstract class ImageFieldTestBase extends WebTestBase {
|
||||
|
||||
use ImageFieldCreationTrait;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
|
@ -51,62 +52,6 @@ abstract class ImageFieldTestBase extends WebTestBase {
|
|||
$this->drupalLogin($this->adminUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new image field.
|
||||
*
|
||||
* @param string $name
|
||||
* The name of the new field (all lowercase), exclude the "field_" prefix.
|
||||
* @param string $type_name
|
||||
* The node type that this field will be added to.
|
||||
* @param array $storage_settings
|
||||
* A list of field storage settings that will be added to the defaults.
|
||||
* @param array $field_settings
|
||||
* A list of instance settings that will be added to the instance defaults.
|
||||
* @param array $widget_settings
|
||||
* Widget settings to be added to the widget defaults.
|
||||
* @param array $formatter_settings
|
||||
* Formatter settings to be added to the formatter defaults.
|
||||
* @param string $description
|
||||
* A description for the field.
|
||||
*/
|
||||
function createImageField($name, $type_name, $storage_settings = array(), $field_settings = array(), $widget_settings = array(), $formatter_settings = array(), $description = '') {
|
||||
FieldStorageConfig::create(array(
|
||||
'field_name' => $name,
|
||||
'entity_type' => 'node',
|
||||
'type' => 'image',
|
||||
'settings' => $storage_settings,
|
||||
'cardinality' => !empty($storage_settings['cardinality']) ? $storage_settings['cardinality'] : 1,
|
||||
))->save();
|
||||
|
||||
$field_config = FieldConfig::create([
|
||||
'field_name' => $name,
|
||||
'label' => $name,
|
||||
'entity_type' => 'node',
|
||||
'bundle' => $type_name,
|
||||
'required' => !empty($field_settings['required']),
|
||||
'settings' => $field_settings,
|
||||
'description' => $description,
|
||||
]);
|
||||
$field_config->save();
|
||||
|
||||
entity_get_form_display('node', $type_name, 'default')
|
||||
->setComponent($name, array(
|
||||
'type' => 'image_image',
|
||||
'settings' => $widget_settings,
|
||||
))
|
||||
->save();
|
||||
|
||||
entity_get_display('node', $type_name, 'default')
|
||||
->setComponent($name, array(
|
||||
'type' => 'image',
|
||||
'settings' => $formatter_settings,
|
||||
))
|
||||
->save();
|
||||
|
||||
return $field_config;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Preview an image in a node.
|
||||
*
|
||||
|
|
|
@ -12,15 +12,43 @@ class ImageFieldValidateTest extends ImageFieldTestBase {
|
|||
* Test min/max resolution settings.
|
||||
*/
|
||||
function testResolution() {
|
||||
$field_name = strtolower($this->randomMachineName());
|
||||
$min_resolution = 50;
|
||||
$max_resolution = 100;
|
||||
$field_settings = array(
|
||||
'max_resolution' => $max_resolution . 'x' . $max_resolution,
|
||||
'min_resolution' => $min_resolution . 'x' . $min_resolution,
|
||||
'alt_field' => 0,
|
||||
);
|
||||
$this->createImageField($field_name, 'article', array(), $field_settings);
|
||||
$field_names = [
|
||||
0 => strtolower($this->randomMachineName()),
|
||||
1 => strtolower($this->randomMachineName()),
|
||||
2 => strtolower($this->randomMachineName()),
|
||||
];
|
||||
$min_resolution = [
|
||||
'width' => 50,
|
||||
'height' => 50
|
||||
];
|
||||
$max_resolution = [
|
||||
'width' => 100,
|
||||
'height' => 100
|
||||
];
|
||||
$no_height_min_resolution = [
|
||||
'width' => 50,
|
||||
'height' => NULL
|
||||
];
|
||||
$no_height_max_resolution = [
|
||||
'width' => 100,
|
||||
'height' => NULL
|
||||
];
|
||||
$no_width_min_resolution = [
|
||||
'width' => NULL,
|
||||
'height' => 50
|
||||
];
|
||||
$no_width_max_resolution = [
|
||||
'width' => NULL,
|
||||
'height' => 100
|
||||
];
|
||||
$field_settings = [
|
||||
0 => $this->getFieldSettings($min_resolution, $max_resolution),
|
||||
1 => $this->getFieldSettings($no_height_min_resolution, $no_height_max_resolution),
|
||||
2 => $this->getFieldSettings($no_width_min_resolution, $no_width_max_resolution),
|
||||
];
|
||||
$this->createImageField($field_names[0], 'article', [], $field_settings[0]);
|
||||
$this->createImageField($field_names[1], 'article', [], $field_settings[1]);
|
||||
$this->createImageField($field_names[2], 'article', [], $field_settings[2]);
|
||||
|
||||
// We want a test image that is too small, and a test image that is too
|
||||
// big, so cycle through test image files until we have what we need.
|
||||
|
@ -29,21 +57,29 @@ class ImageFieldValidateTest extends ImageFieldTestBase {
|
|||
$image_factory = $this->container->get('image.factory');
|
||||
foreach ($this->drupalGetTestFiles('image') as $image) {
|
||||
$image_file = $image_factory->get($image->uri);
|
||||
if ($image_file->getWidth() > $max_resolution) {
|
||||
if ($image_file->getWidth() > $max_resolution['width']) {
|
||||
$image_that_is_too_big = $image;
|
||||
}
|
||||
if ($image_file->getWidth() < $min_resolution) {
|
||||
if ($image_file->getWidth() < $min_resolution['width']) {
|
||||
$image_that_is_too_small = $image;
|
||||
}
|
||||
if ($image_that_is_too_small && $image_that_is_too_big) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->uploadNodeImage($image_that_is_too_small, $field_name, 'article');
|
||||
$this->assertRaw(t('The specified file %name could not be uploaded.', array('%name' => $image_that_is_too_small->filename)));
|
||||
$this->assertRaw(t('The image is too small; the minimum dimensions are %dimensions pixels.', array('%dimensions' => '50x50')));
|
||||
$this->uploadNodeImage($image_that_is_too_big, $field_name, 'article');
|
||||
$this->uploadNodeImage($image_that_is_too_small, $field_names[0], 'article');
|
||||
$this->assertRaw(t('The specified file %name could not be uploaded.', ['%name' => $image_that_is_too_small->filename]));
|
||||
$this->assertRaw(t('The image is too small; the minimum dimensions are %dimensions pixels.', ['%dimensions' => '50x50']));
|
||||
$this->uploadNodeImage($image_that_is_too_big, $field_names[0], 'article');
|
||||
$this->assertText(t('The image was resized to fit within the maximum allowed dimensions of 100x100 pixels.'));
|
||||
$this->uploadNodeImage($image_that_is_too_small, $field_names[1], 'article');
|
||||
$this->assertRaw(t('The specified file %name could not be uploaded.', ['%name' => $image_that_is_too_small->filename]));
|
||||
$this->uploadNodeImage($image_that_is_too_big, $field_names[1], 'article');
|
||||
$this->assertText(t('The image was resized to fit within the maximum allowed width of 100 pixels.'));
|
||||
$this->uploadNodeImage($image_that_is_too_small, $field_names[2], 'article');
|
||||
$this->assertRaw(t('The specified file %name could not be uploaded.', ['%name' => $image_that_is_too_small->filename]));
|
||||
$this->uploadNodeImage($image_that_is_too_big, $field_names[2], 'article');
|
||||
$this->assertText(t('The image was resized to fit within the maximum allowed height of 100 pixels.'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -102,4 +138,22 @@ class ImageFieldValidateTest extends ImageFieldTestBase {
|
|||
$this->assertNoText(t('Title field is required.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns field settings.
|
||||
*
|
||||
* @param int[] $min_resolution
|
||||
* The minimum width and height resolution setting.
|
||||
* @param int[] $max_resolution
|
||||
* The maximum width and height resolution setting.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getFieldSettings($min_resolution, $max_resolution) {
|
||||
return [
|
||||
'max_resolution' => $max_resolution['width'] . 'x' . $max_resolution['height'],
|
||||
'min_resolution' => $min_resolution['width'] . 'x' . $min_resolution['height'],
|
||||
'alt_field' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ class ImageFieldWidgetTest extends ImageFieldTestBase {
|
|||
* Tests file widget element.
|
||||
*/
|
||||
public function testWidgetElement() {
|
||||
// Check for image widget in add/node/article page
|
||||
// Check for image widget in add/node/article page
|
||||
$field_name = strtolower($this->randomMachineName());
|
||||
$min_resolution = 50;
|
||||
$max_resolution = 100;
|
||||
|
|
|
@ -30,7 +30,9 @@ class ImageOnTranslatedEntityTest extends ImageFieldTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Create the "Basic page" node type.
|
||||
$this->drupalCreateContentType(array('type' => 'basicpage', 'name' => 'Basic page'));
|
||||
// @todo Remove the disabling of new revision creation in
|
||||
// https://www.drupal.org/node/1239558.
|
||||
$this->drupalCreateContentType(['type' => 'basicpage', 'name' => 'Basic page', 'new_revision' => FALSE]);
|
||||
|
||||
// Create a image field on the "Basic page" node type.
|
||||
$this->fieldName = strtolower($this->randomMachineName());
|
||||
|
@ -191,10 +193,6 @@ class ImageOnTranslatedEntityTest extends ImageFieldTestBase {
|
|||
$file = File::load($replaced_second_fid);
|
||||
$this->assertTrue($file->isPermanent());
|
||||
|
||||
// Ensure the file status of the old second file is now temporary.
|
||||
$file = File::load($second_fid);
|
||||
$this->assertTrue($file->isTemporary());
|
||||
|
||||
// Delete the third translation.
|
||||
$this->drupalPostForm('nl/node/' . $default_language_node->id() . '/delete', array(), t('Delete Dutch translation'));
|
||||
|
||||
|
|
|
@ -62,9 +62,9 @@ class ImageStylesPathAndUrlTest extends WebTestBase {
|
|||
/**
|
||||
* Tests an image style URL with the "public://" scheme and unclean URLs.
|
||||
*/
|
||||
function testImageStyleUrlAndPathPublicUnclean() {
|
||||
$this->doImageStyleUrlAndPathTests('public', FALSE);
|
||||
}
|
||||
function testImageStyleUrlAndPathPublicUnclean() {
|
||||
$this->doImageStyleUrlAndPathTests('public', FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests an image style URL with the "private://" schema and unclean URLs.
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\image\Kernel;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
|
||||
/**
|
||||
* Provides a helper method for creating Image fields.
|
||||
*/
|
||||
trait ImageFieldCreationTrait {
|
||||
|
||||
/**
|
||||
* Create a new image field.
|
||||
*
|
||||
* @param string $name
|
||||
* The name of the new field (all lowercase), exclude the "field_" prefix.
|
||||
* @param string $type_name
|
||||
* The node type that this field will be added to.
|
||||
* @param array $storage_settings
|
||||
* (optional) A list of field storage settings that will be added to the
|
||||
* defaults.
|
||||
* @param array $field_settings
|
||||
* (optional) A list of instance settings that will be added to the instance
|
||||
* defaults.
|
||||
* @param array $widget_settings
|
||||
* (optional) Widget settings to be added to the widget defaults.
|
||||
* @param array $formatter_settings
|
||||
* (optional) Formatter settings to be added to the formatter defaults.
|
||||
* @param string $description
|
||||
* (optional) A description for the field. Defaults to ''.
|
||||
*/
|
||||
protected function createImageField($name, $type_name, $storage_settings = array(), $field_settings = array(), $widget_settings = array(), $formatter_settings = array(), $description = '') {
|
||||
FieldStorageConfig::create(array(
|
||||
'field_name' => $name,
|
||||
'entity_type' => 'node',
|
||||
'type' => 'image',
|
||||
'settings' => $storage_settings,
|
||||
'cardinality' => !empty($storage_settings['cardinality']) ? $storage_settings['cardinality'] : 1,
|
||||
))->save();
|
||||
|
||||
$field_config = FieldConfig::create([
|
||||
'field_name' => $name,
|
||||
'label' => $name,
|
||||
'entity_type' => 'node',
|
||||
'bundle' => $type_name,
|
||||
'required' => !empty($field_settings['required']),
|
||||
'settings' => $field_settings,
|
||||
'description' => $description,
|
||||
]);
|
||||
$field_config->save();
|
||||
|
||||
entity_get_form_display('node', $type_name, 'default')
|
||||
->setComponent($name, array(
|
||||
'type' => 'image_image',
|
||||
'settings' => $widget_settings,
|
||||
))
|
||||
->save();
|
||||
|
||||
entity_get_display('node', $type_name, 'default')
|
||||
->setComponent($name, array(
|
||||
'type' => 'image',
|
||||
'settings' => $formatter_settings,
|
||||
))
|
||||
->save();
|
||||
|
||||
return $field_config;
|
||||
}
|
||||
|
||||
}
|
|
@ -77,7 +77,7 @@ class ImageItemTest extends FieldKernelTestBase {
|
|||
$entity->name->value = $this->randomMachineName();
|
||||
$entity->save();
|
||||
|
||||
$entity = entity_load('entity_test', $entity->id());
|
||||
$entity = EntityTest::load($entity->id());
|
||||
$this->assertTrue($entity->image_test instanceof FieldItemListInterface, 'Field implements interface.');
|
||||
$this->assertTrue($entity->image_test[0] instanceof FieldItemInterface, 'Field item implements interface.');
|
||||
$this->assertEqual($entity->image_test->target_id, $this->image->id());
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\image\Kernel;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\StreamWrapper\PrivateStream;
|
||||
use Drupal\Core\StreamWrapper\PublicStream;
|
||||
use Drupal\file_test\StreamWrapper\DummyReadOnlyStreamWrapper;
|
||||
use Drupal\file_test\StreamWrapper\DummyRemoteReadOnlyStreamWrapper;
|
||||
use Drupal\file_test\StreamWrapper\DummyStreamWrapper;
|
||||
use Drupal\image\Entity\ImageStyle;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests derivative generation with source images using stream wrappers.
|
||||
*
|
||||
* @group image
|
||||
*/
|
||||
class ImageStyleCustomStreamWrappersTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public static $modules = ['system', 'image'];
|
||||
|
||||
/**
|
||||
* A testing image style entity.
|
||||
*
|
||||
* @var \Drupal\image\ImageStyleInterface
|
||||
*/
|
||||
protected $imageStyle;
|
||||
|
||||
/**
|
||||
* The file system service.
|
||||
*
|
||||
* @var \Drupal\Core\File\FileSystemInterface
|
||||
*/
|
||||
protected $fileSystem;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->fileSystem = $this->container->get('file_system');
|
||||
$this->config('system.file')->set('default_scheme', 'public')->save();
|
||||
$this->imageStyle = ImageStyle::create(['name' => 'test']);
|
||||
$this->imageStyle->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function register(ContainerBuilder $container) {
|
||||
parent::register($container);
|
||||
foreach ($this->providerTestCustomStreamWrappers() as $stream_wrapper) {
|
||||
$scheme = $stream_wrapper[0];
|
||||
$class = $stream_wrapper[2];
|
||||
$container->register("stream_wrapper.$scheme", $class)
|
||||
->addTag('stream_wrapper', ['scheme' => $scheme]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests derivative creation with several source on a local writable stream.
|
||||
*
|
||||
* @dataProvider providerTestCustomStreamWrappers
|
||||
*
|
||||
* @param string $source_scheme
|
||||
* The source stream wrapper scheme.
|
||||
* @param string $expected_scheme
|
||||
* The derivative expected stream wrapper scheme.
|
||||
*/
|
||||
public function testCustomStreamWrappers($source_scheme, $expected_scheme) {
|
||||
$derivative_uri = $this->imageStyle->buildUri("$source_scheme://some/path/image.png");
|
||||
$derivative_scheme = $this->fileSystem->uriScheme($derivative_uri);
|
||||
|
||||
// Check that the derivative scheme is the expected scheme.
|
||||
$this->assertSame($expected_scheme, $derivative_scheme);
|
||||
|
||||
// Check that the derivative URI is the expected one.
|
||||
$expected_uri = "$expected_scheme://styles/{$this->imageStyle->id()}/$source_scheme/some/path/image.png";
|
||||
$this->assertSame($expected_uri, $derivative_uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide test cases for testCustomStreamWrappers().
|
||||
*
|
||||
* Derivatives created from writable source stream wrappers will inherit the
|
||||
* scheme from source. Derivatives created from read-only stream wrappers will
|
||||
* fall-back to the default scheme.
|
||||
*
|
||||
* @return array[]
|
||||
* An array having each element an array with three items:
|
||||
* - The source stream wrapper scheme.
|
||||
* - The derivative expected stream wrapper scheme.
|
||||
* - The stream wrapper service class.
|
||||
*/
|
||||
public function providerTestCustomStreamWrappers() {
|
||||
return [
|
||||
['public', 'public', PublicStream::class],
|
||||
['private', 'private', PrivateStream::class],
|
||||
['dummy', 'dummy', DummyStreamWrapper::class],
|
||||
['dummy-readonly', 'public', DummyReadOnlyStreamWrapper::class],
|
||||
['dummy-remote-readonly', 'public', DummyRemoteReadOnlyStreamWrapper::class],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
|
@ -86,64 +86,64 @@ class MigrateImageCacheTest extends MigrateDrupal6TestBase {
|
|||
/**
|
||||
* Test that missing actions causes failures.
|
||||
*/
|
||||
public function testMissingEffectPlugin() {
|
||||
Database::getConnection('default', 'migrate')->insert("imagecache_action")
|
||||
public function testMissingEffectPlugin() {
|
||||
Database::getConnection('default', 'migrate')->insert("imagecache_action")
|
||||
->fields([
|
||||
'presetid',
|
||||
'weight',
|
||||
'module',
|
||||
'action',
|
||||
'data',
|
||||
])
|
||||
'presetid',
|
||||
'weight',
|
||||
'module',
|
||||
'action',
|
||||
'data',
|
||||
])
|
||||
->values([
|
||||
'presetid' => '1',
|
||||
'weight' => '0',
|
||||
'module' => 'imagecache',
|
||||
'action' => 'imagecache_deprecated_scale',
|
||||
'data' => 'a:3:{s:3:"fit";s:7:"outside";s:5:"width";s:3:"200";s:6:"height";s:3:"200";}',
|
||||
])->execute();
|
||||
'presetid' => '1',
|
||||
'weight' => '0',
|
||||
'module' => 'imagecache',
|
||||
'action' => 'imagecache_deprecated_scale',
|
||||
'data' => 'a:3:{s:3:"fit";s:7:"outside";s:5:"width";s:3:"200";s:6:"height";s:3:"200";}',
|
||||
])->execute();
|
||||
|
||||
$this->startCollectingMessages();
|
||||
$this->executeMigration('d6_imagecache_presets');
|
||||
$messages = $this->migration->getIdMap()->getMessageIterator();
|
||||
$count = 0;
|
||||
foreach ($messages as $message) {
|
||||
$count++;
|
||||
$this->assertEqual($message->message, 'The "image_deprecated_scale" plugin does not exist.');
|
||||
$this->assertEqual($message->level, MigrationInterface::MESSAGE_ERROR);
|
||||
}
|
||||
// There should be only the one message.
|
||||
$this->assertEqual($count, 1);
|
||||
$this->startCollectingMessages();
|
||||
$this->executeMigration('d6_imagecache_presets');
|
||||
$messages = $this->migration->getIdMap()->getMessageIterator();
|
||||
$count = 0;
|
||||
foreach ($messages as $message) {
|
||||
$count++;
|
||||
$this->assertEqual($message->message, 'The "image_deprecated_scale" plugin does not exist.');
|
||||
$this->assertEqual($message->level, MigrationInterface::MESSAGE_ERROR);
|
||||
}
|
||||
// There should be only the one message.
|
||||
$this->assertEqual($count, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that missing action's causes failures.
|
||||
*/
|
||||
public function testInvalidCropValues() {
|
||||
Database::getConnection('default', 'migrate')->insert("imagecache_action")
|
||||
public function testInvalidCropValues() {
|
||||
Database::getConnection('default', 'migrate')->insert("imagecache_action")
|
||||
->fields([
|
||||
'presetid',
|
||||
'weight',
|
||||
'module',
|
||||
'action',
|
||||
'data',
|
||||
])
|
||||
'presetid',
|
||||
'weight',
|
||||
'module',
|
||||
'action',
|
||||
'data',
|
||||
])
|
||||
->values([
|
||||
'presetid' => '1',
|
||||
'weight' => '0',
|
||||
'module' => 'imagecache',
|
||||
'action' => 'imagecache_crop',
|
||||
'data' => serialize([
|
||||
'xoffset' => '10',
|
||||
'yoffset' => '10',
|
||||
]),
|
||||
])->execute();
|
||||
'presetid' => '1',
|
||||
'weight' => '0',
|
||||
'module' => 'imagecache',
|
||||
'action' => 'imagecache_crop',
|
||||
'data' => serialize([
|
||||
'xoffset' => '10',
|
||||
'yoffset' => '10',
|
||||
]),
|
||||
])->execute();
|
||||
|
||||
$this->startCollectingMessages();
|
||||
$this->executeMigration('d6_imagecache_presets');
|
||||
$this->assertEqual(['error' => [
|
||||
'The Drupal 8 image crop effect does not support numeric values for x and y offsets. Use keywords to set crop effect offsets instead.'
|
||||
]], $this->migrateMessages);
|
||||
$this->startCollectingMessages();
|
||||
$this->executeMigration('d6_imagecache_presets');
|
||||
$this->assertEqual(['error' => [
|
||||
'The Drupal 8 image crop effect does not support numeric values for x and y offsets. Use keywords to set crop effect offsets instead.'
|
||||
]], $this->migrateMessages);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Reference in a new issue