PatternDefinitionSetting.php in UI Patterns Settings 8.2
File
src/Definition/PatternDefinitionSetting.php
View source
<?php
namespace Drupal\ui_patterns_settings\Definition;
use Drupal\ui_patterns\Definition\ArrayAccessDefinitionTrait;
class PatternDefinitionSetting implements \ArrayAccess {
use ArrayAccessDefinitionTrait;
protected $definition = [
'name' => NULL,
'label' => NULL,
'description' => NULL,
'type' => NULL,
'required' => FALSE,
'default_value' => NULL,
'group' => NULL,
'forced_value' => NULL,
'options' => NULL,
'form_visible' => TRUE,
'allow_token' => FALSE,
];
public function __construct($name, $value) {
if (is_scalar($value)) {
$this->definition['name'] = is_numeric($name) ? $value : $name;
$this->definition['label'] = $value;
$this->definition['type'] = 'textfield';
$this->definition['preview'] = NULL;
$this->definition['group'] = NULL;
$this->definition['weight'] = NULL;
$this->definition['allow_token'] = FALSE;
$this->definition['allow_expose'] = FALSE;
}
else {
$name_key = !isset($value['name']) ? $name : $value['name'];
$this->definition['name'] = $name_key;
$this->definition['group'] = isset($value['group']) ? $value['group'] : NULL;
$this->definition['weight'] = isset($value['weight']) ? $value['weight'] : NULL;
$this->definition['label'] = isset($value['label']) ? $value['label'] : $name_key;
$this->definition['required'] = isset($value['required']) ? $value['required'] : FALSE;
$this->definition['default_value'] = isset($value['default_value']) ? $value['default_value'] : NULL;
$this->definition['preview'] = isset($value['preview']) ? $value['preview'] : NULL;
$this->definition['options'] = isset($value['options']) ? $value['options'] : NULL;
$this->definition['allow_token'] = isset($value['allow_token']) ? $value['allow_token'] : FALSE;
$this->definition['allow_expose'] = isset($value['allow_expose']) ? $value['allow_expose'] : FALSE;
$this->definition = $value + $this->definition;
}
}
public function getValue($key) {
return isset($this->definition[$key]) ? $this->definition[$key] : NULL;
}
public function toArray() {
return $this->definition;
}
public function getName() {
return $this->definition['name'];
}
public function getGroup() {
return $this->definition['group'];
}
public function getLabel() {
return $this->definition['label'];
}
public function getRequired() {
return $this->definition['required'];
}
public function getAllowToken() {
return $this->definition['allow_token'];
}
public function getOptions() {
return $this->definition['options'];
}
public function getDefaultValue() {
return $this->definition['default_value'];
}
public function setDefaultValue($defaultValue) {
$this->definition['default_value'] = $defaultValue;
return $this;
}
public function getWeight() {
return $this->definition['weight'];
}
public function setWeight($weight) {
$this->definition['weight'] = $weight;
return $this;
}
public function setAllowToken($allow_token) {
$this->definition['allow_token'] = $allow_token;
return $this;
}
public function getForcedValue() {
return $this->definition['forced_value'];
}
public function getPreview() {
return $this->definition['preview'];
}
public function setForcedValue($forcedValue) {
$this->definition['forced_value'] = $forcedValue;
return $this;
}
public function allowExpose() {
return $this->definition['allow_expose'];
}
public function setAllowExpose($allow_expose) {
$this->definition['allow_expose'] = $allow_expose;
return $this;
}
public function getDescription() {
return $this->definition['description'];
}
public function setDescription($description) {
$this->definition['description'] = $description;
return $this;
}
public function isFormVisible() {
return $this->definition['form_visible'];
}
public function setFormVisible($visible) {
$this->definition['form_visible'] = $visible;
return $this;
}
public function getType() {
return $this->definition['type'];
}
public function setType($type) {
$this->definition['type'] = $type;
return $this;
}
}