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

Breadcrumb

  1. Drupal Core 11.1.x

LengthConstraint.php

Namespace

Drupal\Core\Validation\Plugin\Validation\Constraint

File

core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/LengthConstraint.php

View source
<?php

namespace Drupal\Core\Validation\Plugin\Validation\Constraint;

use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Validation\Attribute\Constraint;
use Symfony\Component\Validator\Constraints\Length;

/**
 * Length constraint.
 *
 * Overrides the symfony constraint to use Drupal-style replacement patterns.
 *
 * @todo Move this below the TypedData core component.
 */
class LengthConstraint extends Length {
    
    /**
     * {@inheritdoc}
     */
    public function __construct(...$args) {
        $this->maxMessage = 'This value is too long. It should have %limit character or less.|This value is too long. It should have %limit characters or less.';
        $this->minMessage = 'This value is too short. It should have %limit character or more.|This value is too short. It should have %limit characters or more.';
        $this->exactMessage = 'This value should have exactly %limit character.|This value should have exactly %limit characters.';
        parent::__construct(...$args);
    }
    
    /**
     * {@inheritdoc}
     */
    public function validatedBy() : string {
        return '\\Symfony\\Component\\Validator\\Constraints\\LengthValidator';
    }

}

Classes

Title Deprecated Summary
LengthConstraint Length constraint.

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal