Issue #3425870 by phenaproxima, alexpott, Wim Leers: Add validation constraints to image.settings
parent
f7cb9cfb64
commit
ad80289ed4
|
@ -12,6 +12,7 @@ use Drupal\Core\Validation\Plugin\Validation\Constraint\EmailConstraint;
|
|||
use Symfony\Component\Validator\Constraints\Blank;
|
||||
use Symfony\Component\Validator\Constraints\Callback;
|
||||
use Symfony\Component\Validator\Constraints\Choice;
|
||||
use Symfony\Component\Validator\Constraints\Image;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
|
||||
/**
|
||||
|
@ -116,6 +117,11 @@ class ConstraintManager extends DefaultPluginManager {
|
|||
'class' => Choice::class,
|
||||
'type' => FALSE,
|
||||
]);
|
||||
$this->getDiscovery()->setDefinition('Image', [
|
||||
'label' => new TranslatableMarkup('Image'),
|
||||
'class' => Image::class,
|
||||
'type' => ['string'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -30040,7 +30040,7 @@ $connection->insert('variable')
|
|||
))
|
||||
->values(array(
|
||||
'name' => 'image_style_preview_image',
|
||||
'value' => 's:33:"core/modules/image/testsample.png";',
|
||||
'value' => 's:23:"core/misc/druplicon.png";',
|
||||
))
|
||||
->values(array(
|
||||
'name' => 'image_toolkit',
|
||||
|
|
|
@ -87,10 +87,18 @@ image.effect.image_scale_and_crop:
|
|||
|
||||
image.settings:
|
||||
type: config_object
|
||||
constraints:
|
||||
FullyValidatable: ~
|
||||
mapping:
|
||||
preview_image:
|
||||
type: string
|
||||
label: 'Preview image'
|
||||
constraints:
|
||||
NotBlank: []
|
||||
# We need to use Symfony's Image constraint because it will accept a file
|
||||
# path as a string, whereas the File module's FileIsImage constraint expects
|
||||
# a full file entity.
|
||||
Image: []
|
||||
allow_insecure_derivatives:
|
||||
type: boolean
|
||||
label: 'Allow insecure image derivatives'
|
||||
|
|
|
@ -29,7 +29,7 @@ class MigrateImageSettingsTest extends MigrateDrupal7TestBase {
|
|||
// These settings are not recommended...
|
||||
$this->assertTrue($config->get('allow_insecure_derivatives'));
|
||||
$this->assertTrue($config->get('suppress_itok_output'));
|
||||
$this->assertSame("core/modules/image/testsample.png", $config->get('preview_image'));
|
||||
$this->assertSame("core/misc/druplicon.png", $config->get('preview_image'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\image\Kernel;
|
||||
|
||||
use Drupal\Core\Config\Schema\SchemaIncompleteException;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* @group image
|
||||
*/
|
||||
class SettingsConfigValidationTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $modules = ['image'];
|
||||
|
||||
/**
|
||||
* Tests that the preview_image setting must be an existing image file.
|
||||
*/
|
||||
public function testPreviewImagePathIsValidated(): void {
|
||||
$this->installConfig('image');
|
||||
|
||||
$file = sys_get_temp_dir() . '/fake_image.png';
|
||||
file_put_contents($file, 'Not an image!');
|
||||
|
||||
$this->expectException(SchemaIncompleteException::class);
|
||||
$this->expectExceptionMessage('[preview_image] This file is not a valid image.');
|
||||
$this->config('image.settings')
|
||||
->set('preview_image', $file)
|
||||
->save();
|
||||
}
|
||||
|
||||
}
|
|
@ -65678,7 +65678,7 @@ $connection->insert('variable')
|
|||
))
|
||||
->values(array(
|
||||
'name' => 'image_style_preview_image',
|
||||
'value' => 's:33:"core/modules/image/testsample.png";',
|
||||
'value' => 's:23:"core/misc/druplicon.png";',
|
||||
))
|
||||
->values(array(
|
||||
'name' => 'image_toolkit',
|
||||
|
|
|
@ -32755,7 +32755,7 @@ $connection->insert('variable')
|
|||
))
|
||||
->values(array(
|
||||
'name' => 'image_style_preview_image',
|
||||
'value' => 's:33:"core/modules/image/testsample.png";',
|
||||
'value' => 's:23:"core/misc/druplicon.png";',
|
||||
))
|
||||
->values(array(
|
||||
'name' => 'image_toolkit',
|
||||
|
|
|
@ -28210,7 +28210,7 @@ $connection->insert('variable')
|
|||
))
|
||||
->values(array(
|
||||
'name' => 'image_style_preview_image',
|
||||
'value' => 's:33:"core/modules/image/testsample.png";',
|
||||
'value' => 's:23:"core/misc/druplicon.png";',
|
||||
))
|
||||
->values(array(
|
||||
'name' => 'image_toolkit',
|
||||
|
|
Loading…
Reference in New Issue