ContextDefinitionInterface.php 4.08 KB
Newer Older
1 2 3 4 5
<?php

namespace Drupal\Component\Plugin\Context;

/**
6 7 8
 * Interface used to define definition objects found in ContextInterface.
 *
 * @see \Drupal\Component\Plugin\Context\ContextInterface
9
 *
10
 * @todo WARNING: This interface is going to receive some additions as part of
11
 * https://www.drupal.org/node/2346999.
12 13 14 15
 */
interface ContextDefinitionInterface {

  /**
16
   * Gets a human readable label.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
   *
   * @return string
   *   The label.
   */
  public function getLabel();

  /**
   * Sets the human readable label.
   *
   * @param string $label
   *   The label to set.
   *
   * @return $this
   */
  public function setLabel($label);

  /**
34
   * Gets a human readable description.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
   *
   * @return string|null
   *   The description, or NULL if no description is available.
   */
  public function getDescription();

  /**
   * Sets the human readable description.
   *
   * @param string|null $description
   *   The description to set.
   *
   * @return $this
   */
  public function setDescription($description);

  /**
52
   * Gets the data type needed by the context.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
   *
   * If the context is multiple-valued, this represents the type of each value.
   *
   * @return string
   *   The data type.
   */
  public function getDataType();

  /**
   * Sets the data type needed by the context.
   *
   * @param string $data_type
   *   The data type to set.
   *
   * @return $this
   */
  public function setDataType($data_type);

  /**
72
   * Determines whether the data is multi-valued, i.e. a list of data items.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
   *
   * @return bool
   *   Whether the data is multi-valued; i.e. a list of data items.
   */
  public function isMultiple();

  /**
   * Sets whether the data is multi-valued.
   *
   * @param bool $multiple
   *   (optional) Whether the data is multi-valued. Defaults to TRUE.
   *
   * @return $this
   */
  public function setMultiple($multiple = TRUE);

  /**
   * Determines whether the context is required.
   *
   * For required data a non-NULL value is mandatory.
   *
   * @return bool
   *   Whether a data value is required.
   */
  public function isRequired();

  /**
   * Sets whether the data is required.
   *
   * @param bool $required
   *   (optional) Whether the data is multi-valued. Defaults to TRUE.
   *
   * @return $this
   */
  public function setRequired($required = TRUE);

109
  /**
110
   * Gets the default value for this context definition.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
   *
   * @return mixed
   *   The default value or NULL if no default value is set.
   */
  public function getDefaultValue();

  /**
   * Sets the default data value.
   *
   * @param mixed $default_value
   *   The default value to be set or NULL to remove any default value.
   *
   * @return $this
   */
  public function setDefaultValue($default_value);

127
  /**
128
   * Gets an array of validation constraints.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
   *
   * @return array
   *   An array of validation constraint definitions, keyed by constraint name.
   *   Each constraint definition can be used for instantiating
   *   \Symfony\Component\Validator\Constraint objects.
   */
  public function getConstraints();

  /**
   * Sets the array of validation constraints.
   *
   * NOTE: This will override any previously set constraints. In most cases
   * ContextDefinitionInterface::addConstraint() should be used instead.
   *
   * @param array $constraints
   *   The array of constraints.
   *
   * @return $this
   *
   * @see self::addConstraint()
   */
  public function setConstraints(array $constraints);

  /**
   * Adds a validation constraint.
   *
   * @param string $constraint_name
   *   The name of the constraint to add, i.e. its plugin id.
   * @param array|null $options
   *   The constraint options as required by the constraint plugin, or NULL.
   *
   * @return $this
   */
  public function addConstraint($constraint_name, $options = NULL);

  /**
165
   * Gets a validation constraint.
166 167
   *
   * @param string $constraint_name
168
   *   The name of the constraint, i.e. its plugin id.
169 170 171 172 173 174 175 176
   *
   * @return array
   *   A validation constraint definition which can be used for instantiating a
   *   \Symfony\Component\Validator\Constraint object.
   */
  public function getConstraint($constraint_name);

}