dataType = $data_type; $this->label = $label; $this->isRequired = $required; $this->isMultiple = $multiple; $this->description = $description; $this->defaultValue = $default_value; } /** * {@inheritdoc} */ public function getDataType() { return $this->dataType; } /** * {@inheritdoc} */ public function setDataType($data_type) { $this->dataType = $data_type; return $this; } /** * {@inheritdoc} */ public function getLabel() { return $this->label; } /** * {@inheritdoc} */ public function setLabel($label) { $this->label = $label; return $this; } /** * {@inheritdoc} */ public function getDescription() { return $this->description; } /** * {@inheritdoc} */ public function setDescription($description) { $this->description = $description; return $this; } /** * {@inheritdoc} */ public function isMultiple() { return $this->isMultiple; } /** * {@inheritdoc} */ public function setMultiple($multiple = TRUE) { $this->isMultiple = $multiple; return $this; } /** * {@inheritdoc} */ public function isRequired() { return $this->isRequired; } /** * {@inheritdoc} */ public function setRequired($required = TRUE) { $this->isRequired = $required; return $this; } /** * {@inheritdoc} */ public function getDefaultValue() { return $this->defaultValue; } /** * {@inheritdoc} */ public function setDefaultValue($default_value) { $this->defaultValue = $default_value; return $this; } /** * {@inheritdoc} */ public function getConstraints() { // @todo Apply defaults. return $this->constraints; } /** * {@inheritdoc} */ public function getConstraint($constraint_name) { $constraints = $this->getConstraints(); return isset($constraints[$constraint_name]) ? $constraints[$constraint_name] : NULL; } /** * {@inheritdoc} */ public function setConstraints(array $constraints) { $this->constraints = $constraints; return $this; } /** * {@inheritdoc} */ public function addConstraint($constraint_name, $options = NULL) { $this->constraints[$constraint_name] = $options; return $this; } /** * {@inheritdoc} */ public function getDataDefinition() { if ($this->isMultiple()) { $definition = $this->getTypedDataManager()->createListDataDefinition($this->getDataType()); } else { $definition = $this->getTypedDataManager()->createDataDefinition($this->getDataType()); } if (!$definition) { throw new \Exception("The data type '{$this->getDataType()}' is invalid"); } $definition->setLabel($this->getLabel()) ->setDescription($this->getDescription()) ->setRequired($this->isRequired()); $constraints = $definition->getConstraints() + $this->getConstraints(); $definition->setConstraints($constraints); return $definition; } }