association-1.0.0-alpha2/src/Plugin/Validation/Constraint/PluginFieldSettingsConstraintValidator.php
src/Plugin/Validation/Constraint/PluginFieldSettingsConstraintValidator.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | <?php namespace Drupal\association\Plugin\Validation\Constraint; use Drupal\association\Entity\AssociationInterface; use Drupal\association\Plugin\PluginFieldSettingsInterface; use Drupal\Core\Field\FieldItemListInterface; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; /** * Constraint to validate entity bundle plugin settings. * * Validates the plugin settings for an an association plugin field setting. It * ensures that the plugin has a chance to validate the configurations values * for the plugin instance and plugin type. */ class PluginFieldSettingsConstraintValidator extends ConstraintValidator { /** * {@inheritdoc} */ public function validate(mixed $items , Constraint $constraint ) { if ( $items instanceof FieldItemListInterface) { $entity = $items ->getEntity(); $fieldStorageDef = $items ->getFieldDefinition()->getFieldStorageDefinition(); $pluginType = $constraint ->type ?? $fieldStorageDef ->getSetting( 'type' ); if ( $pluginType && $entity instanceof AssociationInterface) { $plugin = $entity ->getPlugin( $pluginType ); if ( $plugin instanceof PluginFieldSettingsInterface) { $plugin ->validateSettings( $entity , $items ->settings ?? [], $constraint , $this ->context); } } } } } |