Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. MediaMappingsConstraintValidator.php

class MediaMappingsConstraintValidator

Validates media mappings.

Hierarchy

  • class \Symfony\Component\Validator\ConstraintValidator implements \Symfony\Component\Validator\ConstraintValidatorInterface
    • class \Drupal\media\Plugin\Validation\Constraint\MediaMappingsConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator

Expanded class hierarchy of MediaMappingsConstraintValidator

File

core/modules/media/src/Plugin/Validation/Constraint/MediaMappingsConstraintValidator.php, line 14

Namespace

Drupal\media\Plugin\Validation\Constraint
View source
class MediaMappingsConstraintValidator extends ConstraintValidator {
    
    /**
     * {@inheritdoc}
     */
    public function validate($value, Constraint $constraint) : void {
        if (!$constraint instanceof MediaMappingsConstraint) {
            throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\\MediaMappingsConstraint');
        }
        if (!$value instanceof MediaTypeInterface) {
            throw new UnexpectedTypeException($value, MediaTypeInterface::class);
        }
        // The source field cannot be the target of a field mapping because that
        // would cause it to be overwritten, possibly with invalid data. This is
        // also enforced in the UI.
        if (is_array($value->getFieldMap())) {
            try {
                $source_field_name = $value->getSource()
                    ->getSourceFieldDefinition($value)?->getName();
                if (in_array($source_field_name, $value->getFieldMap(), TRUE)) {
                    $this->context
                        ->addViolation($constraint->invalidMappingMessage, [
                        '@source_field_name' => $source_field_name,
                    ]);
                }
            } catch (PluginException) {
                // The source references an invalid plugin.
            }
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
ConstraintValidator::$context protected property
ConstraintValidator::formatTypeOf protected function Returns a string representation of the type of the value.
ConstraintValidator::formatValue protected function Returns a string representation of the value.
ConstraintValidator::formatValues protected function Returns a string representation of a list of values.
ConstraintValidator::initialize public function Initializes the constraint validator. Overrides ConstraintValidatorInterface::initialize
ConstraintValidator::OBJECT_TO_STRING public constant Whether to cast objects with a "__toString()" method to strings.
ConstraintValidator::PRETTY_DATE public constant Whether to format {@link \DateTime} objects, either with the {@link \IntlDateFormatter}
(if it is available) or as RFC-3339 dates ("Y-m-d H:i:s").
MediaMappingsConstraintValidator::validate public function Checks if the passed value is valid. Overrides ConstraintValidatorInterface::validate
RSS feed
Powered by Drupal