updated core from 8.4 to 8.5 : bug with login_destination
This commit is contained in:
@@ -5,12 +5,12 @@
|
||||
|
||||
.quickedit-image-dropzone {
|
||||
background: rgba(116, 183, 255, 0.8);
|
||||
transition: background .2s;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.quickedit-image-icon {
|
||||
margin: 0 0 10px 0;
|
||||
transition: margin .5s;
|
||||
transition: margin 0.5s;
|
||||
}
|
||||
|
||||
.quickedit-image-dropzone.hover {
|
||||
|
||||
@@ -8,8 +8,8 @@ dependencies:
|
||||
- file
|
||||
configure: entity.image_style.collection
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457825
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\file\Entity\File;
|
||||
use Drupal\file\FileInterface;
|
||||
use Drupal\field\FieldStorageConfigInterface;
|
||||
use Drupal\field\FieldConfigInterface;
|
||||
use Drupal\image\Entity\ImageStyle;
|
||||
@@ -210,7 +210,7 @@ function image_file_download($uri) {
|
||||
/**
|
||||
* Implements hook_file_move().
|
||||
*/
|
||||
function image_file_move(File $file, File $source) {
|
||||
function image_file_move(FileInterface $file, FileInterface $source) {
|
||||
// Delete any image derivatives at the original image path.
|
||||
image_path_flush($source->getFileUri());
|
||||
}
|
||||
@@ -218,7 +218,7 @@ function image_file_move(File $file, File $source) {
|
||||
/**
|
||||
* Implements hook_ENTITY_TYPE_predelete() for file entities.
|
||||
*/
|
||||
function image_file_predelete(File $file) {
|
||||
function image_file_predelete(FileInterface $file) {
|
||||
// Delete any image derivatives of this image.
|
||||
image_path_flush($file->getFileUri());
|
||||
}
|
||||
|
||||
@@ -70,15 +70,15 @@
|
||||
});
|
||||
break;
|
||||
|
||||
case 'active':
|
||||
var self = this;
|
||||
case 'active': {
|
||||
const self = this;
|
||||
|
||||
// Indicate that this element is being edited by Quick Edit Image.
|
||||
this.$el.addClass('quickedit-image-element');
|
||||
|
||||
// Render our initial dropzone element. Once the user reverts changes
|
||||
// or saves a new image, this element is removed.
|
||||
var $dropzone = this.renderDropzone('upload', Drupal.t('Drop file here or click to upload'));
|
||||
const $dropzone = this.renderDropzone('upload', Drupal.t('Drop file here or click to upload'));
|
||||
|
||||
$dropzone.on('dragenter', function (e) {
|
||||
$(this).addClass('hover');
|
||||
@@ -117,6 +117,7 @@
|
||||
|
||||
this.renderToolbar(fieldModel);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'changed':
|
||||
break;
|
||||
|
||||
@@ -50,41 +50,43 @@
|
||||
break;
|
||||
|
||||
case 'active':
|
||||
var self = this;
|
||||
{
|
||||
var self = this;
|
||||
|
||||
this.$el.addClass('quickedit-image-element');
|
||||
this.$el.addClass('quickedit-image-element');
|
||||
|
||||
var $dropzone = this.renderDropzone('upload', Drupal.t('Drop file here or click to upload'));
|
||||
var $dropzone = this.renderDropzone('upload', Drupal.t('Drop file here or click to upload'));
|
||||
|
||||
$dropzone.on('dragenter', function (e) {
|
||||
$(this).addClass('hover');
|
||||
});
|
||||
$dropzone.on('dragleave', function (e) {
|
||||
$(this).removeClass('hover');
|
||||
});
|
||||
|
||||
$dropzone.on('drop', function (e) {
|
||||
if (e.originalEvent.dataTransfer && e.originalEvent.dataTransfer.files.length) {
|
||||
$dropzone.on('dragenter', function (e) {
|
||||
$(this).addClass('hover');
|
||||
});
|
||||
$dropzone.on('dragleave', function (e) {
|
||||
$(this).removeClass('hover');
|
||||
self.uploadImage(e.originalEvent.dataTransfer.files[0]);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$dropzone.on('click', function (e) {
|
||||
$('<input type="file">').trigger('click').on('change', function () {
|
||||
if (this.files.length) {
|
||||
self.uploadImage(this.files[0]);
|
||||
$dropzone.on('drop', function (e) {
|
||||
if (e.originalEvent.dataTransfer && e.originalEvent.dataTransfer.files.length) {
|
||||
$(this).removeClass('hover');
|
||||
self.uploadImage(e.originalEvent.dataTransfer.files[0]);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$dropzone.on('dragover dragenter dragleave drop click', function (e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
});
|
||||
$dropzone.on('click', function (e) {
|
||||
$('<input type="file">').trigger('click').on('change', function () {
|
||||
if (this.files.length) {
|
||||
self.uploadImage(this.files[0]);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
this.renderToolbar(fieldModel);
|
||||
break;
|
||||
$dropzone.on('dragover dragenter dragleave drop click', function (e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
});
|
||||
|
||||
this.renderToolbar(fieldModel);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'changed':
|
||||
break;
|
||||
|
||||
+1
@@ -2,6 +2,7 @@ id: d6_imagecache_presets
|
||||
label: ImageCache Presets
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Configuration
|
||||
source:
|
||||
plugin: d6_imagecache_presets
|
||||
process:
|
||||
+1
@@ -2,6 +2,7 @@ id: d7_image_settings
|
||||
label: Image configuration
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
source:
|
||||
plugin: variable
|
||||
variables:
|
||||
+1
@@ -2,6 +2,7 @@ id: d7_image_styles
|
||||
label: Image styles
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
source:
|
||||
plugin: d7_image_styles
|
||||
process:
|
||||
@@ -10,7 +10,7 @@ use Drupal\Core\Image\ImageFactory;
|
||||
use Drupal\Core\Render\Element\StatusMessages;
|
||||
use Drupal\Core\Render\RendererInterface;
|
||||
use Drupal\image\Plugin\Field\FieldType\ImageItem;
|
||||
use Drupal\user\PrivateTempStoreFactory;
|
||||
use Drupal\Core\TempStore\PrivateTempStoreFactory;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
@@ -23,7 +23,7 @@ class QuickEditImageController extends ControllerBase {
|
||||
/**
|
||||
* Stores The Quick Edit tempstore.
|
||||
*
|
||||
* @var \Drupal\user\PrivateTempStore
|
||||
* @var \Drupal\Core\TempStore\PrivateTempStore
|
||||
*/
|
||||
protected $tempStore;
|
||||
|
||||
@@ -48,7 +48,7 @@ class QuickEditImageController extends ControllerBase {
|
||||
* The renderer.
|
||||
* @param \Drupal\Core\Image\ImageFactory $image_factory
|
||||
* The image factory.
|
||||
* @param \Drupal\user\PrivateTempStoreFactory $temp_store_factory
|
||||
* @param \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store_factory
|
||||
* The tempstore factory.
|
||||
*/
|
||||
public function __construct(RendererInterface $renderer, ImageFactory $image_factory, PrivateTempStoreFactory $temp_store_factory) {
|
||||
@@ -64,7 +64,7 @@ class QuickEditImageController extends ControllerBase {
|
||||
return new static(
|
||||
$container->get('renderer'),
|
||||
$container->get('image.factory'),
|
||||
$container->get('user.private_tempstore')
|
||||
$container->get('tempstore.private')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides an add form for image effects.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class ImageEffectAddForm extends ImageEffectFormBase {
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ use Drupal\image\ImageStyleInterface;
|
||||
|
||||
/**
|
||||
* Form for deleting an image effect.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class ImageEffectDeleteForm extends ConfirmFormBase {
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ use Drupal\image\ImageStyleInterface;
|
||||
|
||||
/**
|
||||
* Provides an edit form for image effects.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class ImageEffectEditForm extends ImageEffectFormBase {
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Controller for image style addition forms.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class ImageStyleAddForm extends ImageStyleFormBase {
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Creates a form to delete an image style.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class ImageStyleDeleteForm extends EntityDeleteForm {
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Controller for image style edit form.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class ImageStyleEditForm extends ImageStyleFormBase {
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Form controller for image style flush.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class ImageStyleFlushForm extends EntityConfirmFormBase {
|
||||
|
||||
|
||||
@@ -39,9 +39,17 @@ class ImageStyleListBuilder extends ConfigEntityListBuilder {
|
||||
'url' => $entity->urlInfo('flush-form'),
|
||||
];
|
||||
|
||||
return parent::getDefaultOperations($entity) + [
|
||||
$operations = parent::getDefaultOperations($entity) + [
|
||||
'flush' => $flush,
|
||||
];
|
||||
|
||||
// Remove destination URL from the edit link to allow editing image
|
||||
// effects.
|
||||
if (isset($operations['edit'])) {
|
||||
$operations['edit']['url'] = $entity->toUrl('edit-form');
|
||||
}
|
||||
|
||||
return $operations;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -48,8 +48,11 @@ class PathProcessorImageStyles implements InboundPathProcessorInterface {
|
||||
if (strpos($path, '/' . $directory_path . '/styles/') === 0) {
|
||||
$path_prefix = '/' . $directory_path . '/styles/';
|
||||
}
|
||||
elseif (strpos($path, '/system/files/styles/') === 0) {
|
||||
// Check if the string '/system/files/styles/' exists inside the path,
|
||||
// that means we have a case of private file's image style.
|
||||
elseif (strpos($path, '/system/files/styles/') !== FALSE) {
|
||||
$path_prefix = '/system/files/styles/';
|
||||
$path = substr($path, strpos($path, $path_prefix), strlen($path));
|
||||
}
|
||||
else {
|
||||
return $path;
|
||||
|
||||
@@ -344,8 +344,8 @@ class ImageItem extends FileItem {
|
||||
if (!isset($images[$extension][$min_resolution][$max_resolution]) || count($images[$extension][$min_resolution][$max_resolution]) <= 5) {
|
||||
$tmp_file = drupal_tempnam('temporary://', 'generateImage_');
|
||||
$destination = $tmp_file . '.' . $extension;
|
||||
file_unmanaged_move($tmp_file, $destination, FILE_CREATE_DIRECTORY);
|
||||
if ($path = $random->image(drupal_realpath($destination), $min_resolution, $max_resolution)) {
|
||||
file_unmanaged_move($tmp_file, $destination);
|
||||
if ($path = $random->image(\Drupal::service('file_system')->realpath($destination), $min_resolution, $max_resolution)) {
|
||||
$image = File::create();
|
||||
$image->setFileUri($path);
|
||||
$image->setOwnerId(\Drupal::currentUser()->id());
|
||||
@@ -354,7 +354,7 @@ class ImageItem extends FileItem {
|
||||
$destination_dir = static::doGetUploadLocation($settings);
|
||||
file_prepare_directory($destination_dir, FILE_CREATE_DIRECTORY);
|
||||
$destination = $destination_dir . '/' . basename($path);
|
||||
$file = file_move($image, $destination, FILE_CREATE_DIRECTORY);
|
||||
$file = file_move($image, $destination);
|
||||
$images[$extension][$min_resolution][$max_resolution][$file->id()] = $file;
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
|
||||
namespace Drupal\image\Plugin\Field\FieldWidget;
|
||||
|
||||
use Drupal\Core\Field\FieldDefinitionInterface;
|
||||
use Drupal\Core\Field\FieldItemListInterface;
|
||||
use Drupal\Core\Image\ImageFactory;
|
||||
use Drupal\Component\Utility\NestedArray;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Render\ElementInfoManagerInterface;
|
||||
use Drupal\file\Entity\File;
|
||||
use Drupal\file\Plugin\Field\FieldWidget\FileWidget;
|
||||
use Drupal\image\Entity\ImageStyle;
|
||||
@@ -22,6 +25,36 @@ use Drupal\image\Entity\ImageStyle;
|
||||
*/
|
||||
class ImageWidget extends FileWidget {
|
||||
|
||||
/**
|
||||
* The image factory service.
|
||||
*
|
||||
* @var \Drupal\Core\Image\ImageFactory
|
||||
*/
|
||||
protected $imageFactory;
|
||||
|
||||
/**
|
||||
* Constructs an ImageWidget object.
|
||||
*
|
||||
* @param string $plugin_id
|
||||
* The plugin_id for the widget.
|
||||
* @param mixed $plugin_definition
|
||||
* The plugin implementation definition.
|
||||
* @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
|
||||
* The definition of the field to which the widget is associated.
|
||||
* @param array $settings
|
||||
* The widget settings.
|
||||
* @param array $third_party_settings
|
||||
* Any third party settings.
|
||||
* @param \Drupal\Core\Render\ElementInfoManagerInterface $element_info
|
||||
* The element info manager service.
|
||||
* @param \Drupal\Core\Image\ImageFactory $image_factory
|
||||
* The image factory service.
|
||||
*/
|
||||
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, ElementInfoManagerInterface $element_info, ImageFactory $image_factory = NULL) {
|
||||
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings, $element_info);
|
||||
$this->imageFactory = $image_factory ?: \Drupal::service('image.factory');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -112,15 +145,21 @@ class ImageWidget extends FileWidget {
|
||||
|
||||
$field_settings = $this->getFieldSettings();
|
||||
|
||||
// Add image validation.
|
||||
$element['#upload_validators']['file_validate_is_image'] = [];
|
||||
|
||||
// Add upload resolution validation.
|
||||
if ($field_settings['max_resolution'] || $field_settings['min_resolution']) {
|
||||
$element['#upload_validators']['file_validate_image_resolution'] = [$field_settings['max_resolution'], $field_settings['min_resolution']];
|
||||
}
|
||||
|
||||
// If not using custom extension validation, ensure this is an image.
|
||||
$supported_extensions = ['png', 'gif', 'jpg', 'jpeg'];
|
||||
$extensions = isset($element['#upload_validators']['file_validate_extensions'][0]) ? $element['#upload_validators']['file_validate_extensions'][0] : implode(' ', $supported_extensions);
|
||||
$extensions = array_intersect(explode(' ', $extensions), $supported_extensions);
|
||||
$extensions = $field_settings['file_extensions'];
|
||||
$supported_extensions = $this->imageFactory->getSupportedExtensions();
|
||||
|
||||
// If using custom extension validation, ensure that the extensions are
|
||||
// supported by the current image toolkit. Otherwise, validate against all
|
||||
// toolkit supported extensions.
|
||||
$extensions = !empty($extensions) ? array_intersect(explode(' ', $extensions), $supported_extensions) : $supported_extensions;
|
||||
$element['#upload_validators']['file_validate_extensions'][0] = implode(' ', $extensions);
|
||||
|
||||
// Add mobile device image capture acceptance.
|
||||
@@ -256,7 +295,8 @@ class ImageWidget extends FileWidget {
|
||||
public static function validateRequiredFields($element, FormStateInterface $form_state) {
|
||||
// Only do validation if the function is triggered from other places than
|
||||
// the image process form.
|
||||
if (!in_array('file_managed_file_submit', $form_state->getTriggeringElement()['#submit'])) {
|
||||
$triggering_element = $form_state->getTriggeringElement();
|
||||
if (empty($triggering_element['#submit']) || !in_array('file_managed_file_submit', $triggering_element['#submit'])) {
|
||||
// If the image is not there, we do not check for empty values.
|
||||
$parents = $element['#parents'];
|
||||
$field = array_pop($parents);
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\image\Plugin\migrate\cckfield\d7;
|
||||
|
||||
@trigger_error('ImageField is deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.x. Use \Drupal\image\Plugin\migrate\field\d7\ImageField instead.', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
|
||||
|
||||
/**
|
||||
* @MigrateCckField(
|
||||
* id = "image",
|
||||
* core = {7},
|
||||
* source_module = "image",
|
||||
* destination_module = "file"
|
||||
* )
|
||||
*
|
||||
* @deprecated in Drupal 8.5.x, to be removed before Drupal 9.0.x. Use
|
||||
* \Drupal\image\Plugin\migrate\field\d7\ImageField instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2751897
|
||||
*/
|
||||
class ImageField extends CckFieldPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) {
|
||||
$process = [
|
||||
'plugin' => 'sub_process',
|
||||
'source' => $field_name,
|
||||
'process' => [
|
||||
'target_id' => 'fid',
|
||||
'alt' => 'alt',
|
||||
'title' => 'title',
|
||||
'width' => 'width',
|
||||
'height' => 'height',
|
||||
],
|
||||
];
|
||||
$migration->mergeProcessOfProperty($field_name, $process);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\image\Plugin\migrate\field\d6;
|
||||
|
||||
use Drupal\file\Plugin\migrate\field\d6\FileField;
|
||||
|
||||
/**
|
||||
* @MigrateField(
|
||||
* id = "imagefield",
|
||||
* core = {6},
|
||||
* source_module = "imagefield",
|
||||
* destination_module = "image"
|
||||
* )
|
||||
*/
|
||||
class ImageField extends FileField {}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\image\Plugin\migrate\field\d7;
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
|
||||
|
||||
/**
|
||||
* @MigrateField(
|
||||
* id = "image",
|
||||
* core = {7},
|
||||
* source_module = "image",
|
||||
* destination_module = "image"
|
||||
* )
|
||||
*/
|
||||
class ImageField extends FieldPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function processFieldValues(MigrationInterface $migration, $field_name, $data) {
|
||||
$process = [
|
||||
'plugin' => 'sub_process',
|
||||
'source' => $field_name,
|
||||
'process' => [
|
||||
'target_id' => 'fid',
|
||||
'alt' => 'alt',
|
||||
'title' => 'title',
|
||||
'width' => 'width',
|
||||
'height' => 'height',
|
||||
],
|
||||
];
|
||||
$migration->mergeProcessOfProperty($field_name, $process);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -422,9 +422,20 @@ class ImageAdminStylesTest extends ImageFieldTestBase {
|
||||
// Edit the scale effect that was just added.
|
||||
$this->clickLink(t('Edit'));
|
||||
$this->drupalPostForm(NULL, ['data[width]' => '24', 'data[height]' => '19'], t('Update effect'));
|
||||
$this->drupalPostForm(NULL, ['new' => 'image_scale'], t('Add'));
|
||||
|
||||
// Add another scale effect and make sure both exist.
|
||||
// Add another scale effect and make sure both exist. Click through from
|
||||
// the overview to make sure that it is possible to add new effect then.
|
||||
$this->drupalGet('admin/config/media/image-styles');
|
||||
$rows = $this->xpath('//table/tbody/tr');
|
||||
$i = 0;
|
||||
foreach ($rows as $row) {
|
||||
if (((string) $row->td[0]) === 'Test style scale edit scale') {
|
||||
$this->clickLink('Edit', $i);
|
||||
break;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
$this->drupalPostForm(NULL, ['new' => 'image_scale'], t('Add'));
|
||||
$this->drupalPostForm(NULL, ['data[width]' => '12', 'data[height]' => '19'], t('Add effect'));
|
||||
$this->assertText(t('Scale 24×19'));
|
||||
$this->assertText(t('Scale 12×19'));
|
||||
|
||||
@@ -305,7 +305,7 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase {
|
||||
);
|
||||
|
||||
$non_image = $this->drupalGetTestFiles('text');
|
||||
$this->drupalPostForm(NULL, ['files[settings_default_image_uuid]' => drupal_realpath($non_image[0]->uri)], t("Upload"));
|
||||
$this->drupalPostForm(NULL, ['files[settings_default_image_uuid]' => \Drupal::service('file_system')->realpath($non_image[0]->uri)], t("Upload"));
|
||||
$this->assertText('The specified file text-0.txt could not be uploaded.');
|
||||
$this->assertText('Only files with the following extensions are allowed: png gif jpg jpeg.');
|
||||
|
||||
|
||||
@@ -312,7 +312,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
|
||||
// @see FileWidget::formMultipleElements().
|
||||
$this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.' . $field_name . '/storage', ['cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED], t('Save field settings'));
|
||||
$edit = [
|
||||
'files[' . $field_name . '_1][]' => drupal_realpath($test_image->uri),
|
||||
'files[' . $field_name . '_1][]' => \Drupal::service('file_system')->realpath($test_image->uri),
|
||||
];
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
|
||||
// Add the required alt text.
|
||||
@@ -322,7 +322,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
|
||||
// Assert ImageWidget::process() calls FieldWidget::process().
|
||||
$this->drupalGet('node/' . $node->id() . '/edit');
|
||||
$edit = [
|
||||
'files[' . $field_name . '_2][]' => drupal_realpath($test_image->uri),
|
||||
'files[' . $field_name . '_2][]' => \Drupal::service('file_system')->realpath($test_image->uri),
|
||||
];
|
||||
$this->drupalPostAjaxForm(NULL, $edit, $field_name . '_2_upload_button');
|
||||
$this->assertNoRaw('<input multiple type="file" id="edit-' . strtr($field_name, '_', '-') . '-2-upload" name="files[' . $field_name . '_2][]" size="22" class="js-form-file form-file">');
|
||||
@@ -357,7 +357,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
|
||||
$title = $this->randomString(1024);
|
||||
$edit = [
|
||||
// Get the path of the 'image-test.png' file.
|
||||
'files[settings_default_image_uuid]' => drupal_realpath($images[0]->uri),
|
||||
'files[settings_default_image_uuid]' => \Drupal::service('file_system')->realpath($images[0]->uri),
|
||||
'settings[default_image][alt]' => $alt,
|
||||
'settings[default_image][title]' => $title,
|
||||
];
|
||||
@@ -426,7 +426,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
|
||||
// Add a default image to the new field.
|
||||
$edit = [
|
||||
// Get the path of the 'image-test.gif' file.
|
||||
'files[settings_default_image_uuid]' => drupal_realpath($images[2]->uri),
|
||||
'files[settings_default_image_uuid]' => \Drupal::service('file_system')->realpath($images[2]->uri),
|
||||
'settings[default_image][alt]' => $alt,
|
||||
'settings[default_image][title]' => $title,
|
||||
];
|
||||
|
||||
@@ -69,7 +69,7 @@ abstract class ImageFieldTestBase extends WebTestBase {
|
||||
$edit = [
|
||||
'title[0][value]' => $this->randomMachineName(),
|
||||
];
|
||||
$edit['files[' . $field_name . '_0]'] = drupal_realpath($image->uri);
|
||||
$edit['files[' . $field_name . '_0]'] = \Drupal::service('file_system')->realpath($image->uri);
|
||||
$this->drupalPostForm('node/add/' . $type, $edit, t('Preview'));
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ abstract class ImageFieldTestBase extends WebTestBase {
|
||||
$edit = [
|
||||
'title[0][value]' => $this->randomMachineName(),
|
||||
];
|
||||
$edit['files[' . $field_name . '_0]'] = drupal_realpath($image->uri);
|
||||
$edit['files[' . $field_name . '_0]'] = \Drupal::service('file_system')->realpath($image->uri);
|
||||
$this->drupalPostForm('node/add/' . $type, $edit, t('Save'));
|
||||
if ($alt) {
|
||||
// Add alt text.
|
||||
|
||||
@@ -2,12 +2,70 @@
|
||||
|
||||
namespace Drupal\image\Tests;
|
||||
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
|
||||
/**
|
||||
* Tests validation functions such as min/max resolution.
|
||||
*
|
||||
* @group image
|
||||
*/
|
||||
class ImageFieldValidateTest extends ImageFieldTestBase {
|
||||
|
||||
/**
|
||||
* Test image validity.
|
||||
*/
|
||||
public function testValid() {
|
||||
$file_system = $this->container->get('file_system');
|
||||
$image_files = $this->drupalGetTestFiles('image');
|
||||
|
||||
$field_name = strtolower($this->randomMachineName());
|
||||
$this->createImageField($field_name, 'article', [], ['file_directory' => 'test-upload']);
|
||||
$expected_path = 'public://test-upload';
|
||||
|
||||
// Create alt text for the image.
|
||||
$alt = $this->randomMachineName();
|
||||
|
||||
// Create a node with a valid image.
|
||||
$node = $this->uploadNodeImage($image_files[0], $field_name, 'article', $alt);
|
||||
$this->assertTrue(file_exists($expected_path . '/' . $image_files[0]->filename));
|
||||
|
||||
// Remove the image.
|
||||
$this->drupalPostForm('node/' . $node . '/edit', [], t('Remove'));
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
|
||||
// Get invalid image test files from simpletest.
|
||||
$files = file_scan_directory(drupal_get_path('module', 'simpletest') . '/files', '/invalid-img-.*/');
|
||||
$invalid_image_files = [];
|
||||
foreach ($files as $file) {
|
||||
$invalid_image_files[$file->filename] = $file;
|
||||
}
|
||||
|
||||
// Try uploading a zero-byte image.
|
||||
$zero_size_image = $invalid_image_files['invalid-img-zero-size.png'];
|
||||
$edit = [
|
||||
'files[' . $field_name . '_0]' => $file_system->realpath($zero_size_image->uri),
|
||||
];
|
||||
$this->drupalPostForm('node/' . $node . '/edit', $edit, t('Upload'));
|
||||
$this->assertFalse(file_exists($expected_path . '/' . $zero_size_image->filename));
|
||||
|
||||
// Try uploading an invalid image.
|
||||
$invalid_image = $invalid_image_files['invalid-img-test.png'];
|
||||
$edit = [
|
||||
'files[' . $field_name . '_0]' => $file_system->realpath($invalid_image->uri),
|
||||
];
|
||||
$this->drupalPostForm('node/' . $node . '/edit', $edit, t('Upload'));
|
||||
$this->assertFalse(file_exists($expected_path . '/' . $invalid_image->filename));
|
||||
|
||||
// Upload a valid image again.
|
||||
$valid_image = $image_files[0];
|
||||
$edit = [
|
||||
'files[' . $field_name . '_0]' => $file_system->realpath($valid_image->uri),
|
||||
];
|
||||
$this->drupalPostForm('node/' . $node . '/edit', $edit, t('Upload'));
|
||||
$this->assertTrue(file_exists($expected_path . '/' . $valid_image->filename));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test min/max resolution settings.
|
||||
*/
|
||||
@@ -62,6 +120,7 @@ class ImageFieldValidateTest extends ImageFieldTestBase {
|
||||
}
|
||||
if ($image_file->getWidth() < $min_resolution['width']) {
|
||||
$image_that_is_too_small = $image;
|
||||
$image_that_is_too_small_file = $image_file;
|
||||
}
|
||||
if ($image_that_is_too_small && $image_that_is_too_big) {
|
||||
break;
|
||||
@@ -69,7 +128,11 @@ class ImageFieldValidateTest extends ImageFieldTestBase {
|
||||
}
|
||||
$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->assertRaw(t('The image is too small. The minimum dimensions are %dimensions pixels and the image size is %widthx%height pixels.', [
|
||||
'%dimensions' => '50x50',
|
||||
'%width' => $image_that_is_too_small_file->getWidth(),
|
||||
'%height' => $image_that_is_too_small_file->getHeight(),
|
||||
]));
|
||||
$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');
|
||||
@@ -178,4 +241,48 @@ class ImageFieldValidateTest extends ImageFieldTestBase {
|
||||
$this->assertEqual(count($elements), 1, 'Ajax validation messages are displayed once.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that image field validation works with other form submit handlers.
|
||||
*/
|
||||
public function testFriendlyAjaxValidation() {
|
||||
// Add a custom field to the Article content type that contains an AJAX
|
||||
// handler on a select field.
|
||||
$field_storage = FieldStorageConfig::create([
|
||||
'field_name' => 'field_dummy_select',
|
||||
'type' => 'image_module_test_dummy_ajax',
|
||||
'entity_type' => 'node',
|
||||
'cardinality' => 1,
|
||||
]);
|
||||
$field_storage->save();
|
||||
|
||||
$field = FieldConfig::create([
|
||||
'field_storage' => $field_storage,
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'article',
|
||||
'field_name' => 'field_dummy_select',
|
||||
'label' => t('Dummy select'),
|
||||
])->save();
|
||||
|
||||
\Drupal::entityTypeManager()
|
||||
->getStorage('entity_form_display')
|
||||
->load('node.article.default')
|
||||
->setComponent(
|
||||
'field_dummy_select',
|
||||
[
|
||||
'type' => 'image_module_test_dummy_ajax_widget',
|
||||
'weight' => 1,
|
||||
])
|
||||
->save();
|
||||
|
||||
// Then, add an image field.
|
||||
$this->createImageField('field_dummy_image', 'article');
|
||||
|
||||
// Open an article and trigger the AJAX handler.
|
||||
$this->drupalGet('node/add/article');
|
||||
$edit = [
|
||||
'field_dummy_select[select_widget]' => 'bam',
|
||||
];
|
||||
$this->drupalPostAjaxForm(NULL, $edit, 'field_dummy_select[select_widget]');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ class ImageOnTranslatedEntityTest extends ImageFieldTestBase {
|
||||
// Edit the node to upload a file.
|
||||
$edit = [];
|
||||
$name = 'files[' . $this->fieldName . '_0]';
|
||||
$edit[$name] = drupal_realpath($this->drupalGetTestFiles('image')[0]->uri);
|
||||
$edit[$name] = \Drupal::service('file_system')->realpath($this->drupalGetTestFiles('image')[0]->uri);
|
||||
$this->drupalPostForm('node/' . $default_language_node->id() . '/edit', $edit, t('Save'));
|
||||
$edit = [$this->fieldName . '[0][alt]' => 'Lost in translation image', $this->fieldName . '[0][title]' => 'Lost in translation image title'];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
@@ -108,7 +108,7 @@ class ImageOnTranslatedEntityTest extends ImageFieldTestBase {
|
||||
$edit = [];
|
||||
$edit['title[0][value]'] = 'Scarlett Johansson';
|
||||
$name = 'files[' . $this->fieldName . '_0]';
|
||||
$edit[$name] = drupal_realpath($this->drupalGetTestFiles('image')[1]->uri);
|
||||
$edit[$name] = \Drupal::service('file_system')->realpath($this->drupalGetTestFiles('image')[1]->uri);
|
||||
$this->drupalPostForm(NULL, $edit, t('Save (this translation)'));
|
||||
$edit = [$this->fieldName . '[0][alt]' => 'Scarlett Johansson image', $this->fieldName . '[0][title]' => 'Scarlett Johansson image title'];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save (this translation)'));
|
||||
@@ -140,7 +140,7 @@ class ImageOnTranslatedEntityTest extends ImageFieldTestBase {
|
||||
$edit = [];
|
||||
$edit['title[0][value]'] = 'Akiko Takeshita';
|
||||
$name = 'files[' . $this->fieldName . '_0]';
|
||||
$edit[$name] = drupal_realpath($this->drupalGetTestFiles('image')[2]->uri);
|
||||
$edit[$name] = \Drupal::service('file_system')->realpath($this->drupalGetTestFiles('image')[2]->uri);
|
||||
$this->drupalPostForm(NULL, $edit, t('Save (this translation)'));
|
||||
$edit = [$this->fieldName . '[0][alt]' => 'Akiko Takeshita image', $this->fieldName . '[0][title]' => 'Akiko Takeshita image title'];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save (this translation)'));
|
||||
@@ -175,7 +175,7 @@ class ImageOnTranslatedEntityTest extends ImageFieldTestBase {
|
||||
$edit = [];
|
||||
$edit['title[0][value]'] = 'Giovanni Ribisi';
|
||||
$name = 'files[' . $this->fieldName . '_0]';
|
||||
$edit[$name] = drupal_realpath($this->drupalGetTestFiles('image')[3]->uri);
|
||||
$edit[$name] = \Drupal::service('file_system')->realpath($this->drupalGetTestFiles('image')[3]->uri);
|
||||
$this->drupalPostForm(NULL, $edit, t('Save (this translation)'));
|
||||
$name = $this->fieldName . '[0][alt]';
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Drupal\image\Tests;
|
||||
|
||||
use Drupal\image\Entity\ImageStyle;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
@@ -17,18 +18,29 @@ class ImageStylesPathAndUrlTest extends WebTestBase {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['image', 'image_module_test'];
|
||||
public static $modules = ['image', 'image_module_test', 'language'];
|
||||
|
||||
/**
|
||||
* The image style.
|
||||
*
|
||||
* @var \Drupal\image\ImageStyleInterface
|
||||
*/
|
||||
protected $style;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->style = ImageStyle::create(['name' => 'style_foo', 'label' => $this->randomString()]);
|
||||
$this->style = ImageStyle::create([
|
||||
'name' => 'style_foo',
|
||||
'label' => $this->randomString(),
|
||||
]);
|
||||
$this->style->save();
|
||||
|
||||
// Create a new language.
|
||||
ConfigurableLanguage::createFromLangcode('fr')->save();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,6 +85,20 @@ class ImageStylesPathAndUrlTest extends WebTestBase {
|
||||
$this->doImageStyleUrlAndPathTests('private', FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests an image style URL with the "public://" schema and language prefix.
|
||||
*/
|
||||
public function testImageStyleUrlAndPathPublicLanguage() {
|
||||
$this->doImageStyleUrlAndPathTests('public', TRUE, TRUE, 'fr');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests an image style URL with the "private://" schema and language prefix.
|
||||
*/
|
||||
public function testImageStyleUrlAndPathPrivateLanguage() {
|
||||
$this->doImageStyleUrlAndPathTests('private', TRUE, TRUE, 'fr');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests an image style URL with a file URL that has an extra slash in it.
|
||||
*/
|
||||
@@ -93,7 +119,7 @@ class ImageStylesPathAndUrlTest extends WebTestBase {
|
||||
/**
|
||||
* Tests building an image style URL.
|
||||
*/
|
||||
public function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_slash = FALSE) {
|
||||
public function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_slash = FALSE, $langcode = FALSE) {
|
||||
$this->prepareRequestForGenerator($clean_url);
|
||||
|
||||
// Make the default scheme neither "public" nor "private" to verify the
|
||||
@@ -105,6 +131,13 @@ class ImageStylesPathAndUrlTest extends WebTestBase {
|
||||
$status = file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
|
||||
$this->assertNotIdentical(FALSE, $status, 'Created the directory for the generated images for the test style.');
|
||||
|
||||
// Override the language to build the URL for the correct language.
|
||||
if ($langcode) {
|
||||
$language_manager = \Drupal::service('language_manager');
|
||||
$language = $language_manager->getLanguage($langcode);
|
||||
$language_manager->setConfigOverrideLanguage($language);
|
||||
}
|
||||
|
||||
// Create a working copy of the file.
|
||||
$files = $this->drupalGetTestFiles('image');
|
||||
$file = array_shift($files);
|
||||
@@ -119,6 +152,11 @@ class ImageStylesPathAndUrlTest extends WebTestBase {
|
||||
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
|
||||
$generate_url = $this->style->buildUrl($original_uri, $clean_url);
|
||||
|
||||
// Make sure that language prefix is never added to the image style URL.
|
||||
if ($langcode) {
|
||||
$this->assertTrue(strpos($generate_url, "/$langcode/") === FALSE, 'Langcode was not found in the image style URL.');
|
||||
}
|
||||
|
||||
// Ensure that the tests still pass when the file is generated by accessing
|
||||
// a poorly constructed (but still valid) file URL that has an extra slash
|
||||
// in it.
|
||||
@@ -157,7 +195,8 @@ class ImageStylesPathAndUrlTest extends WebTestBase {
|
||||
$this->assertEqual($this->drupalGetHeader('Content-Length'), $image->getFileSize(), 'Expected Content-Length was reported.');
|
||||
|
||||
// Check that we did not download the original file.
|
||||
$original_image = $this->container->get('image.factory')->get($original_uri);
|
||||
$original_image = $this->container->get('image.factory')
|
||||
->get($original_uri);
|
||||
$this->assertNotEqual($this->drupalGetHeader('Content-Length'), $original_image->getFileSize());
|
||||
|
||||
if ($scheme == 'private') {
|
||||
@@ -192,13 +231,15 @@ class ImageStylesPathAndUrlTest extends WebTestBase {
|
||||
|
||||
$this->drupalGet($generate_url_noaccess);
|
||||
$this->assertResponse(403, 'Confirmed that access is denied for the private image style.');
|
||||
// Verify that images are not appended to the response. Currently this test only uses PNG images.
|
||||
// Verify that images are not appended to the response.
|
||||
// Currently this test only uses PNG images.
|
||||
if (strpos($generate_url, '.png') === FALSE) {
|
||||
$this->fail('Confirming that private image styles are not appended require PNG file.');
|
||||
}
|
||||
else {
|
||||
// Check for PNG-Signature (cf. http://www.libpng.org/pub/png/book/chapter08.html#png.ch08.div.2) in the
|
||||
// response body.
|
||||
// Check for PNG-Signature
|
||||
// (cf. http://www.libpng.org/pub/png/book/chapter08.html#png.ch08.div.2)
|
||||
// in the response body.
|
||||
$this->assertNoRaw(chr(137) . chr(80) . chr(78) . chr(71) . chr(13) . chr(10) . chr(26) . chr(10), 'No PNG signature found in the response body.');
|
||||
}
|
||||
}
|
||||
@@ -215,7 +256,9 @@ class ImageStylesPathAndUrlTest extends WebTestBase {
|
||||
|
||||
// Allow insecure image derivatives to be created for the remainder of this
|
||||
// test.
|
||||
$this->config('image.settings')->set('allow_insecure_derivatives', TRUE)->save();
|
||||
$this->config('image.settings')
|
||||
->set('allow_insecure_derivatives', TRUE)
|
||||
->save();
|
||||
|
||||
// Create another working copy of the file.
|
||||
$files = $this->drupalGetTestFiles('image');
|
||||
@@ -239,7 +282,8 @@ class ImageStylesPathAndUrlTest extends WebTestBase {
|
||||
// Stop supressing the security token in the URL.
|
||||
$this->config('image.settings')->set('suppress_itok_output', FALSE)->save();
|
||||
// Ensure allow_insecure_derivatives is enabled.
|
||||
$this->assertEqual($this->config('image.settings')->get('allow_insecure_derivatives'), TRUE);
|
||||
$this->assertEqual($this->config('image.settings')
|
||||
->get('allow_insecure_derivatives'), TRUE);
|
||||
// Check that a security token is still required when generating a second
|
||||
// image derivative using the first one as a source.
|
||||
$nested_url = $this->style->buildUrl($generated_uri, $clean_url);
|
||||
|
||||
@@ -30,8 +30,8 @@ class RelationshipUserImageDataTest extends ViewTestBase {
|
||||
*/
|
||||
public static $testViews = ['test_image_user_image_data'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
// Create the user profile field and instance.
|
||||
FieldStorageConfig::create([
|
||||
|
||||
@@ -5,8 +5,8 @@ package: Testing
|
||||
# version: VERSION
|
||||
# core: 8.x
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457825
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\image_module_test\Plugin\Field\FieldFormatter;
|
||||
|
||||
use Drupal\Core\Field\FieldItemListInterface;
|
||||
use Drupal\Core\Field\FormatterBase;
|
||||
|
||||
/**
|
||||
* Empty renderer for a dummy field with an AJAX handler.
|
||||
*
|
||||
* @FieldFormatter(
|
||||
* id = "image_module_test_dummy_ajax_formatter",
|
||||
* module = "image_module_test",
|
||||
* label = @Translation("Dummy AJAX"),
|
||||
* field_types= {
|
||||
* "image_module_test_dummy_ajax"
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class DummyAjaxFormatter extends FormatterBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function settingsSummary() {
|
||||
$summary = [];
|
||||
$summary[] = t('Renders nothing');
|
||||
return $summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||
$element = [];
|
||||
return $element;
|
||||
}
|
||||
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\image_module_test\Plugin\Field\FieldType;
|
||||
|
||||
use Drupal\Core\Field\FieldItemBase;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\Core\TypedData\DataDefinition;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
|
||||
/**
|
||||
* Defines a dummy field containing an AJAX handler.
|
||||
*
|
||||
* @FieldType(
|
||||
* id = "image_module_test_dummy_ajax",
|
||||
* label = @Translation("Dummy AJAX"),
|
||||
* description = @Translation("A field containing an AJAX handler."),
|
||||
* category = @Translation("Field"),
|
||||
* default_widget = "image_module_test_dummy_ajax_widget",
|
||||
* default_formatter = "image_module_test_dummy_ajax_formatter"
|
||||
* )
|
||||
*/
|
||||
class DummyAjaxItem extends FieldItemBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function schema(FieldStorageDefinitionInterface $field_definition) {
|
||||
return [
|
||||
'columns' => [
|
||||
'value' => [
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isEmpty() {
|
||||
return empty($this->get('value')->getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
|
||||
$properties['value'] = DataDefinition::create('string')
|
||||
->setLabel(new TranslatableMarkup('Dummy string value'));
|
||||
|
||||
return $properties;
|
||||
}
|
||||
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\image_module_test\Plugin\Field\FieldWidget;
|
||||
|
||||
use Drupal\Core\Ajax\AjaxResponse;
|
||||
use Drupal\Core\Field\FieldItemListInterface;
|
||||
use Drupal\Core\Field\WidgetBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Default widget for Dummy AJAX test.
|
||||
*
|
||||
* @FieldWidget(
|
||||
* id = "image_module_test_dummy_ajax_widget",
|
||||
* label = @Translation("Dummy AJAX widget"),
|
||||
* field_types = {
|
||||
* "image_module_test_dummy_ajax"
|
||||
* },
|
||||
* multiple_values = TRUE,
|
||||
* )
|
||||
*/
|
||||
class DummyAjaxWidget extends WidgetBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
|
||||
$element['select_widget'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Dummy select'),
|
||||
'#options' => ['pow' => 'Pow!', 'bam' => 'Bam!'],
|
||||
'#required' => TRUE,
|
||||
'#ajax' => [
|
||||
'callback' => get_called_class() . '::dummyAjaxCallback',
|
||||
'effect' => 'fade',
|
||||
],
|
||||
];
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajax callback for Dummy AJAX test.
|
||||
*
|
||||
* @param array $form
|
||||
* The build form.
|
||||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
* The form state.
|
||||
*
|
||||
* @return \Drupal\Core\Ajax\AjaxResponse
|
||||
* Ajax response.
|
||||
*/
|
||||
public static function dummyAjaxCallback(array &$form, FormStateInterface $form_state) {
|
||||
return new AjaxResponse();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,8 +8,8 @@ dependencies:
|
||||
- image
|
||||
- views
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457825
|
||||
|
||||
@@ -66,7 +66,7 @@ abstract class ImageFieldTestBase extends BrowserTestBase {
|
||||
$edit = [
|
||||
'title[0][value]' => $this->randomMachineName(),
|
||||
];
|
||||
$edit['files[' . $field_name . '_0]'] = drupal_realpath($image->uri);
|
||||
$edit['files[' . $field_name . '_0]'] = \Drupal::service('file_system')->realpath($image->uri);
|
||||
$this->drupalPostForm('node/add/' . $type, $edit, t('Preview'));
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ abstract class ImageFieldTestBase extends BrowserTestBase {
|
||||
$edit = [
|
||||
'title[0][value]' => $this->randomMachineName(),
|
||||
];
|
||||
$edit['files[' . $field_name . '_0]'] = drupal_realpath($image->uri);
|
||||
$edit['files[' . $field_name . '_0]'] = \Drupal::service('file_system')->realpath($image->uri);
|
||||
$this->drupalPostForm('node/add/' . $type, $edit, t('Save and publish'));
|
||||
if ($alt) {
|
||||
// Add alt text.
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Drupal\Tests\image\Functional;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
|
||||
/**
|
||||
* Tests the image field widget.
|
||||
*
|
||||
@@ -27,6 +29,22 @@ class ImageFieldWidgetTest extends ImageFieldTestBase {
|
||||
$this->assertNotEqual(0, count($this->xpath('//div[contains(@class, "field--widget-image-image")]')), 'Image field widget found on add/node page', 'Browser');
|
||||
$this->assertNotEqual(0, count($this->xpath('//input[contains(@accept, "image/*")]')), 'Image field widget limits accepted files.', 'Browser');
|
||||
$this->assertNoText('Image test on [site:name]');
|
||||
|
||||
// Check for allowed image file extensions - default.
|
||||
$this->assertText('Allowed types: png gif jpg jpeg.');
|
||||
|
||||
// Try adding to the field config an unsupported extension, should not
|
||||
// appear in the allowed types.
|
||||
$field_config = FieldConfig::loadByName('node', 'article', $field_name);
|
||||
$field_config->setSetting('file_extensions', 'png gif jpg jpeg tiff')->save();
|
||||
$this->drupalGet('node/add/article');
|
||||
$this->assertText('Allowed types: png gif jpg jpeg.');
|
||||
|
||||
// Add a supported extension and remove some supported ones, we should see
|
||||
// the intersect of those entered in field config with those supported.
|
||||
$field_config->setSetting('file_extensions', 'png jpe tiff')->save();
|
||||
$this->drupalGet('node/add/article');
|
||||
$this->assertText('Allowed types: png jpe.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\Tests\field\Kernel\FieldKernelTestBase;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\file\Entity\File;
|
||||
use Drupal\user\Entity\Role;
|
||||
|
||||
/**
|
||||
* Tests using entity fields of the image field type.
|
||||
@@ -41,6 +42,14 @@ class ImageItemTest extends FieldKernelTestBase {
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('user');
|
||||
$this->installConfig(['user']);
|
||||
// Give anonymous users permission to access content, so that we can view
|
||||
// and download public file.
|
||||
$anonymous_role = Role::load(Role::ANONYMOUS_ID);
|
||||
$anonymous_role->grantPermission('access content');
|
||||
$anonymous_role->save();
|
||||
|
||||
$this->installEntitySchema('file');
|
||||
$this->installSchema('file', ['file_usage']);
|
||||
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\image\Kernel\Migrate\d6;
|
||||
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\Tests\node\Kernel\Migrate\d6\MigrateNodeTestBase;
|
||||
use Drupal\Tests\file\Kernel\Migrate\d6\FileMigrationTestTrait;
|
||||
|
||||
/**
|
||||
* Image migration test.
|
||||
*
|
||||
* This extends the node test, because the D6 fixture has images; they just
|
||||
* need to be migrated into D8.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateImageTest extends MigrateNodeTestBase {
|
||||
|
||||
use FileMigrationTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['menu_ui'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->setUpMigratedFiles();
|
||||
$this->installSchema('file', ['file_usage']);
|
||||
$this->executeMigrations([
|
||||
'd6_node',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test image migration from Drupal 6 to 8.
|
||||
*/
|
||||
public function testNode() {
|
||||
$node = Node::load(9);
|
||||
// Test the image field sub fields.
|
||||
$this->assertSame('2', $node->field_test_imagefield->target_id);
|
||||
$this->assertSame('Test alt', $node->field_test_imagefield->alt);
|
||||
$this->assertSame('Test title', $node->field_test_imagefield->title);
|
||||
$this->assertSame('80', $node->field_test_imagefield->width);
|
||||
$this->assertSame('60', $node->field_test_imagefield->height);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\image\Unit\Plugin\migrate\field\d7;
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\image\Plugin\migrate\field\d7\ImageField;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\image\Plugin\migrate\field\d7\ImageField
|
||||
* @group image
|
||||
*/
|
||||
class ImageFieldTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->plugin = new ImageField([], 'image', []);
|
||||
|
||||
$migration = $this->prophesize(MigrationInterface::class);
|
||||
|
||||
// The plugin's processFieldValues() method will call
|
||||
// mergeProcessOfProperty() and return nothing. So, in order to examine the
|
||||
// process pipeline created by the plugin, we need to ensure that
|
||||
// getProcess() always returns the last input to mergeProcessOfProperty().
|
||||
$migration->mergeProcessOfProperty(Argument::type('string'), Argument::type('array'))
|
||||
->will(function ($arguments) use ($migration) {
|
||||
$migration->getProcess()->willReturn($arguments[1]);
|
||||
});
|
||||
$this->migration = $migration->reveal();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::processFieldValues
|
||||
*/
|
||||
public function testProcessFieldValues() {
|
||||
$this->plugin->processFieldValues($this->migration, 'somefieldname', []);
|
||||
|
||||
$expected = [
|
||||
'plugin' => 'sub_process',
|
||||
'source' => 'somefieldname',
|
||||
'process' => [
|
||||
'target_id' => 'fid',
|
||||
'alt' => 'alt',
|
||||
'title' => 'title',
|
||||
'width' => 'width',
|
||||
'height' => 'height',
|
||||
],
|
||||
];
|
||||
$this->assertSame($expected, $this->migration->getProcess());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user