Verified Commit 8447a07e authored by Dave Long's avatar Dave Long
Browse files

refactor: #3569096 Remove BC layer $options argument from Constraint plugin constructors

By: godotislate
By: smustgrave
By: longwave
parent 3f4c757b
Loading
Loading
Loading
Loading
Loading
+14 −12
Original line number Diff line number Diff line
@@ -18,25 +18,27 @@
class ConfigExistsConstraint extends SymfonyConstraint {

  /**
   * Optional prefix, to be specified when this contains a config entity ID.
   * Constructs a ConfigExistsConstraint object.
   *
   * @param string $prefix
   *   Optional prefix, to be specified when this contains a config entity ID.
   *   Every config entity type can have multiple instances, all with unique IDs
   *   but the same config prefix. When config refers to a config entity,
   *   typically only the ID is stored, not the prefix.
   *
   * @var string
   * @param string $message
   *   The error message if the config does not exist.
   * @param array|null $groups
   *   The groups that the constraint belongs to.
   * @param mixed|null $payload
   *   Domain-specific data attached to a constraint.
   */
  public string $prefix = '';

  public function __construct(
    mixed $options = NULL,
    ?string $prefix = NULL,
    public string $prefix = '',
    public string $message = "The '@name' config does not exist.",
    ?array $groups = NULL,
    mixed $payload = NULL,
  ) {
    parent::__construct($options, $groups, $payload);
    $this->prefix = $prefix ?? $this->prefix;
    parent::__construct(groups: $groups, payload: $payload);
  }

}
+1 −2
Original line number Diff line number Diff line
@@ -19,13 +19,12 @@
class LangcodeRequiredIfTranslatableValuesConstraint extends SymfonyConstraint {

  public function __construct(
    mixed $options = NULL,
    public string $missingMessage = "The @name config object must specify a language code, because it contains translatable values.",
    public string $superfluousMessage = "The @name config object does not contain any translatable values, so it should not specify a language code.",
    ?array $groups = NULL,
    mixed $payload = NULL,
  ) {
    parent::__construct($options, $groups, $payload);
    parent::__construct(groups: $groups, payload: $payload);
  }

}
+13 −25
Original line number Diff line number Diff line
@@ -18,38 +18,26 @@
class RequiredConfigDependenciesConstraint extends SymfonyConstraint {

  /**
   * The IDs of entity types that need to exist in config dependencies.
   * Constructs a RequiredConfigDependenciesConstraint object.
   *
   * For example, if an entity requires a filter format in its config
   * @param array $entityTypes
   *   The IDs of entity types that need to exist in config dependencies. For
   *   example, if an entity requires a filter format in its config
   *   dependencies, this should contain `filter_format`.
   *
   * @var string[]
   * @param string $message
   *   The error message.
   * @param array|null $groups
   *   The groups that the constraint belongs to.
   * @param mixed|null $payload
   *   Domain-specific data attached to a constraint.
   */
  public array $entityTypes = [];

  public function __construct(
    mixed $options = NULL,
    ?array $entityTypes = NULL,
    public array $entityTypes = [],
    public string $message = 'This @entity_type requires a @dependency_type.',
    ?array $groups = NULL,
    mixed $payload = NULL,
  ) {
    parent::__construct($options, $groups, $payload);
    $this->entityTypes = $entityTypes ?? $this->entityTypes;
  }

  /**
   * {@inheritdoc}
   */
  public function getRequiredOptions(): array {
    return ['entityTypes'];
  }

  /**
   * {@inheritdoc}
   */
  public function getDefaultOption(): ?string {
    return 'entityTypes';
    parent::__construct(groups: $groups, payload: $payload);
  }

}
+2 −25
Original line number Diff line number Diff line
@@ -19,22 +19,13 @@
)]
class BundleConstraint extends SymfonyConstraint {

  /**
   * The bundle option.
   *
   * @var string|array
   */
  public $bundle;

  public function __construct(
    mixed $options = NULL,
    string|array|null $bundle = NULL,
    public string|array $bundle,
    public $message = 'The entity must be of bundle %bundle.',
    ?array $groups = NULL,
    mixed $payload = NULL,
  ) {
    parent::__construct($options, $groups, $payload);
    $this->bundle = $bundle ?? $this->bundle;
    parent::__construct(groups: $groups, payload: $payload);
  }

  /**
@@ -51,18 +42,4 @@ public function getBundleOption() {
    return $this->bundle;
  }

  /**
   * {@inheritdoc}
   */
  public function getDefaultOption(): ?string {
    return 'bundle';
  }

  /**
   * {@inheritdoc}
   */
  public function getRequiredOptions(): array {
    return ['bundle'];
  }

}
+1 −2
Original line number Diff line number Diff line
@@ -17,12 +17,11 @@
class EntityChangedConstraint extends SymfonyConstraint {

  public function __construct(
    mixed $options = NULL,
    public $message = 'The content has either been modified by another user, or you have already submitted modifications. As a result, your changes cannot be saved.',
    ?array $groups = NULL,
    mixed $payload = NULL,
  ) {
    parent::__construct($options, $groups, $payload);
    parent::__construct(groups: $groups, payload: $payload);
  }

}
Loading