Skip to content
Snippets Groups Projects
Commit 25b8b7c3 authored by catch's avatar catch
Browse files

Issue #3332593 by phenaproxima, Wim Leers, borisson_, lauriii, tim.plunkett:...

Issue #3332593 by phenaproxima, Wim Leers, borisson_, lauriii, tim.plunkett: Adopt PluginExists validator in relevant places
parent e5b5af04
Branches
Tags
28 merge requests!12227Issue #3181946 by jonmcl, mglaman,!8528Issue #3456871 by Tim Bozeman: Support NULL services,!3878Removed unused condition head title for views,!38582585169-10.1.x,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3668Resolve #3347842 "Deprecate the trusted",!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3478Issue #3337882: Deleted menus are not removed from content type config,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!877Issue #2708101: Default value for link text is not saved,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!213Issue #2906496: Give Media a menu item under Content
Pipeline #91279 canceled
Pipeline: drupal

#91282

    Showing
    with 169 additions and 8 deletions
    ......@@ -198,6 +198,10 @@ filter:
    id:
    type: string
    label: 'ID'
    constraints:
    PluginExists:
    manager: plugin.manager.filter
    interface: 'Drupal\filter\Plugin\FilterInterface'
    provider:
    type: string
    label: 'Provider'
    ......@@ -425,6 +429,10 @@ condition.plugin:
    id:
    type: string
    label: 'ID'
    constraints:
    PluginExists:
    manager: plugin.manager.condition
    interface: 'Drupal\Core\Condition\ConditionInterface'
    negate:
    type: boolean
    label: 'Negate'
    ......@@ -527,6 +535,10 @@ field_config_base:
    field_type:
    type: string
    label: 'Field type'
    constraints:
    PluginExists:
    manager: plugin.manager.field.field_type
    interface: '\Drupal\Core\Field\FieldItemInterface'
    core.base_field_override.*.*.*:
    type: field_config_base
    ......@@ -711,6 +723,13 @@ field.field_settings.entity_reference:
    handler:
    type: string
    label: 'Reference method'
    constraints:
    PluginExists:
    manager: plugin.manager.entity_reference_selection
    interface: 'Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface'
    # @todo Remove this line and explicitly require valid entity reference
    # selection plugin IDs in https://drupal.org/i/3420198.
    allowFallback: true
    handler_settings:
    type: entity_reference_selection.[%parent.handler]
    label: 'Entity reference selection plugin settings'
    ......
    ......@@ -78,6 +78,10 @@ field_formatter:
    type:
    type: string
    label: 'Format type machine name'
    constraints:
    PluginExists:
    manager: plugin.manager.field.formatter
    interface: 'Drupal\Core\Field\FormatterInterface'
    label:
    type: string
    label: 'Label setting machine name'
    ......@@ -135,6 +139,10 @@ core.entity_form_display.*.*.*:
    type:
    type: string
    label: 'Widget type machine name'
    constraints:
    PluginExists:
    manager: plugin.manager.field.widget
    interface: '\Drupal\Core\Field\WidgetInterface'
    weight:
    type: integer
    label: 'Weight'
    ......
    ......@@ -48,6 +48,13 @@ class PluginExistsConstraint extends Constraint implements ContainerFactoryPlugi
    */
    public ?string $interface = NULL;
    /**
    * Whether or not to consider fallback plugin IDs as valid.
    *
    * @var bool
    */
    public bool $allowFallback = FALSE;
    /**
    * Constructs a PluginExistsConstraint.
    *
    ......
    ......@@ -25,8 +25,11 @@ public function validate(mixed $plugin_id, Constraint $constraint) {
    }
    $definition = $constraint->pluginManager->getDefinition($plugin_id, FALSE);
    // Some plugin managers provide fallbacks.
    if ($constraint->pluginManager instanceof FallbackPluginManagerInterface) {
    // Some plugin managers provide fallbacks. In most cases, the use of a
    // fallback plugin ID suggests that the given plugin ID is invalid in some
    // way, so by default, we don't consider fallback plugin IDs as valid,
    // although that can be overridden by the `allowFallback` option if needed.
    if ($constraint->pluginManager instanceof FallbackPluginManagerInterface && $constraint->allowFallback) {
    $fallback_plugin_id = $constraint->pluginManager->getFallbackPluginId($plugin_id);
    $definition = $constraint->pluginManager->getDefinition($fallback_plugin_id, FALSE);
    }
    ......
    ......@@ -33,6 +33,10 @@ block.block.*:
    PluginExists:
    manager: plugin.manager.block
    interface: Drupal\Core\Block\BlockPluginInterface
    # Block plugin IDs may not be valid in blocks that are backed by
    # block_content entities that don't exist yet. Therefore, it's okay
    # to consider the fallback plugin ID as valid.
    allowFallback: true
    settings:
    type: block.settings.[%parent.plugin]
    visibility:
    ......
    ......@@ -182,7 +182,7 @@ display:
    admin_label: ''
    entity_type: comment
    entity_field: cid
    plugin_id: field
    plugin_id: standard
    order: DESC
    expose:
    label: ''
    ......
    ......@@ -24,6 +24,10 @@ field.storage.*.*:
    type:
    type: string
    label: 'Type'
    constraints:
    PluginExists:
    manager: plugin.manager.field.field_type
    interface: '\Drupal\Core\Field\FieldItemInterface'
    settings:
    type: field.storage_settings.[%parent.type]
    module:
    ......
    ......@@ -225,3 +225,9 @@ function field_test_field_info_entity_type_ui_definitions_alter(array &$ui_defin
    $ui_definitions['boolean']['label'] = new TranslatableMarkup('Boolean (overridden by alter)');
    }
    }
    function field_test_entity_reference_selection_alter(array &$definitions): void {
    if (\Drupal::state()->get('field_test_disable_broken_entity_reference_handler')) {
    unset($definitions['broken']);
    }
    }
    ......@@ -14,6 +14,7 @@
    * id = "test_field_widget",
    * label = @Translation("Test widget"),
    * field_types = {
    * "field_test",
    * "test_field",
    * "hidden_test_field",
    * "test_field_with_preconfigured_options"
    ......
    ......@@ -120,6 +120,7 @@ public function testImmutableProperties(array $valid_values = []): void {
    parent::testImmutableProperties([
    'entity_type' => 'entity_test_with_bundle',
    'bundle' => 'another',
    'field_type' => 'string',
    ]);
    }
    ......@@ -149,4 +150,40 @@ public function testRequiredPropertyValuesMissing(?array $additional_expected_va
    ]);
    }
    /**
    * Tests that the field type plugin's existence is validated.
    */
    public function testFieldTypePluginIsValidated(): void {
    // The `field_type` property is immutable, so we need to clone the entity in
    // order to cleanly change its immutable properties.
    $this->entity = $this->entity->createDuplicate()
    // We need to clear the current settings, or we will get validation errors
    // because the old settings are not supported by the new field type.
    ->set('settings', [])
    ->set('field_type', 'invalid');
    $this->assertValidationErrors([
    'field_type' => "The 'invalid' plugin does not exist.",
    ]);
    }
    /**
    * Tests that entity reference selection handler plugin IDs are validated.
    */
    public function testEntityReferenceSelectionHandlerIsValidated(): void {
    $this->container->get('state')
    ->set('field_test_disable_broken_entity_reference_handler', TRUE);
    $this->enableModules(['field_test']);
    // The `field_type` property is immutable, so we need to clone the entity in
    // order to cleanly change its immutable properties.
    $this->entity = $this->entity->createDuplicate()
    ->set('field_type', 'entity_reference')
    ->set('settings', ['handler' => 'non_existent']);
    $this->assertValidationErrors([
    'settings.handler' => "The 'non_existent' plugin does not exist.",
    ]);
    }
    }
    ......@@ -33,4 +33,26 @@ protected function setUp(): void {
    $this->entity->save();
    }
    /**
    * {@inheritdoc}
    */
    public function testImmutableProperties(array $valid_values = []): void {
    $valid_values['type'] = 'string';
    parent::testImmutableProperties($valid_values);
    }
    /**
    * Tests that the field type plugin's existence is validated.
    */
    public function testFieldTypePluginIsValidated(): void {
    // The `type` property is immutable, so we need to clone the entity in
    // order to cleanly change its immutable properties.
    $this->entity = $this->entity->createDuplicate()
    ->set('type', 'invalid');
    $this->assertValidationErrors([
    'type' => "The 'invalid' plugin does not exist.",
    ]);
    }
    }
    ......@@ -19,6 +19,7 @@ class FieldLayoutEntityDisplayTest extends KernelTestBase {
    'field_layout',
    'entity_test',
    'field_layout_test',
    'field_test',
    'system',
    ];
    ......@@ -34,7 +35,7 @@ public function testPreSave() {
    'mode' => 'default',
    'status' => TRUE,
    'content' => [
    'foo' => ['type' => 'visible'],
    'foo' => ['type' => 'field_no_settings'],
    'name' => ['type' => 'hidden', 'region' => 'content'],
    ],
    'hidden' => [
    ......@@ -60,7 +61,7 @@ public function testPreSave() {
    'mode' => 'default',
    'content' => [
    'foo' => [
    'type' => 'visible',
    'type' => 'field_no_settings',
    ],
    ],
    'hidden' => [
    ......@@ -99,7 +100,7 @@ public function testPreSave() {
    ];
    // The field was moved to the default region.
    $expected['content']['foo'] = [
    'type' => 'visible',
    'type' => 'field_no_settings',
    'region' => 'main',
    'weight' => -4,
    'settings' => [],
    ......
    ......@@ -47,7 +47,9 @@ protected function setUp(): void {
    \Drupal::service('entity_display.repository')
    ->getFormDisplay($entity_type, $entity_type)
    ->setComponent('field_test_no_plugin', [])
    ->setComponent('field_test_no_plugin', [
    'type' => 'test_field_widget',
    ])
    ->save();
    }
    ......
    ......@@ -18,6 +18,10 @@ image.style.*:
    type: uuid
    id:
    type: string
    constraints:
    PluginExists:
    manager: plugin.manager.image.effect
    interface: 'Drupal\image\ImageEffectInterface'
    weight:
    type: integer
    data:
    ......
    ......@@ -20,6 +20,10 @@ layout_builder.section:
    layout_id:
    type: string
    label: 'Layout ID'
    constraints:
    PluginExists:
    manager: plugin.manager.core.layout
    interface: '\Drupal\Core\Layout\LayoutInterface'
    layout_settings:
    type: layout_plugin.settings.[%parent.layout_id]
    label: 'Layout settings'
    ......
    ......@@ -37,6 +37,10 @@ media.type.*:
    source:
    type: string
    label: 'Source'
    constraints:
    PluginExists:
    manager: plugin.manager.media.source
    interface: 'Drupal\media\MediaSourceInterface'
    queue_thumbnail_downloads:
    type: boolean
    label: 'Whether the thumbnail downloads should be queued'
    ......
    ......@@ -36,7 +36,28 @@ public function testImmutableProperties(array $valid_values = []): void {
    // settings from the *old* source won't match the config schema for the
    // settings of the *new* source.
    $this->entity->set('source_configuration', []);
    $valid_values['source'] = 'image';
    parent::testImmutableProperties($valid_values);
    }
    /**
    * Tests that the media source plugin's existence is validated.
    */
    public function testMediaSourceIsValidated(): void {
    // The `source` property is immutable, so we need to clone the entity in
    // order to cleanly change its immutable properties.
    $this->entity = $this->entity->createDuplicate()
    // The `id` property is thrown out by createDuplicate().
    ->set('id', 'test')
    // We need to clear the current source configuration, or we will get
    // validation errors because the old configuration is not supported by the
    // new source.
    ->set('source_configuration', [])
    ->set('source', 'invalid');
    $this->assertValidationErrors([
    'source' => "The 'invalid' plugin does not exist.",
    ]);
    }
    }
    ......@@ -107,7 +107,7 @@ display:
    admin_label: ''
    entity_type: node
    entity_field: sticky
    plugin_id: boolean
    plugin_id: standard
    order: DESC
    expose:
    label: ''
    ......
    ......@@ -79,6 +79,10 @@ rest.resource.*:
    plugin_id:
    type: string
    label: 'REST resource plugin id'
    constraints:
    PluginExists:
    manager: plugin.manager.rest
    interface: 'Drupal\rest\Plugin\ResourceInterface'
    granularity:
    type: string
    label: 'REST resource configuration granularity'
    ......
    ......@@ -38,4 +38,14 @@ protected function setUp(): void {
    $this->entity->save();
    }
    /**
    * Tests that the resource plugin ID is validated.
    */
    public function testInvalidPluginId(): void {
    $this->entity->set('plugin_id', 'non_existent');
    $this->assertValidationErrors([
    'plugin_id' => "The 'non_existent' plugin does not exist.",
    ]);
    }
    }
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment