You are here

class PatternDefinitionSetting in UI Patterns Settings 8.2

Same name and namespace in other branches
  1. 8 src/Definition/PatternDefinitionSetting.php \Drupal\ui_patterns_settings\Definition\PatternDefinitionSetting

Pattern setting definition class.

@package Drupal\ui_patterns_settings\Definition

Hierarchy

Expanded class hierarchy of PatternDefinitionSetting

16 files declare their use of PatternDefinitionSetting
AttributesSettingType.php in src/Plugin/UiPatterns/SettingType/AttributesSettingType.php
BooleanSettingType.php in src/Plugin/UiPatterns/SettingType/BooleanSettingType.php
CheckboxesSettingType.php in src/Plugin/UiPatterns/SettingType/CheckboxesSettingType.php
ColorWidgetSettingType.php in src/Plugin/UiPatterns/SettingType/ColorWidgetSettingType.php
EnumerationSettingTypeBase.php in src/Plugin/EnumerationSettingTypeBase.php

... See full list

File

src/Definition/PatternDefinitionSetting.php, line 12

Namespace

Drupal\ui_patterns_settings\Definition
View source
class PatternDefinitionSetting implements \ArrayAccess {
  use ArrayAccessDefinitionTrait;

  /**
   * Default setting values.
   *
   * @var array
   */
  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,
  ];

  /**
   * PatternDefinitionSetting constructor.
   */
  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;
    }
  }

  /**
   * Return any definition value.
   *
   * @return string
   *   The value.
   */
  public function getValue($key) {
    return isset($this->definition[$key]) ? $this->definition[$key] : NULL;
  }

  /**
   * Return array definition.
   *
   * @return array
   *   Array definition.
   */
  public function toArray() {
    return $this->definition;
  }

  /**
   * Get Name property.
   *
   * @return mixed
   *   Property value.
   */
  public function getName() {
    return $this->definition['name'];
  }

  /**
   * Get Group property.
   *
   * @return mixed
   *   Property value.
   */
  public function getGroup() {
    return $this->definition['group'];
  }

  /**
   * Get Label property.
   *
   * @return mixed
   *   Property value.
   */
  public function getLabel() {
    return $this->definition['label'];
  }

  /**
   * Get required property.
   *
   * @return mixed
   *   Property value.
   */
  public function getRequired() {
    return $this->definition['required'];
  }

  /**
   * Get allow token property.
   *
   * @return bool
   *   Property value.
   */
  public function getAllowToken() {
    return $this->definition['allow_token'];
  }

  /**
   * Get options array.
   *
   * @return mixed
   *   Property option.
   */
  public function getOptions() {
    return $this->definition['options'];
  }

  /**
   * Get default value property.
   *
   * @return mixed
   *   Property value.
   */
  public function getDefaultValue() {
    return $this->definition['default_value'];
  }

  /**
   * Set default value property.
   *
   * @return mixed
   *   Property value.
   */
  public function setDefaultValue($defaultValue) {
    $this->definition['default_value'] = $defaultValue;
    return $this;
  }

  /**
   * Get weight value property.
   *
   * @return mixed
   *   Property value.
   */
  public function getWeight() {
    return $this->definition['weight'];
  }

  /**
   * Set weight property.
   *
   * @return mixed
   *   Property value.
   */
  public function setWeight($weight) {
    $this->definition['weight'] = $weight;
    return $this;
  }

  /**
   * Set allow token value property.
   *
   * @param bool $allow_token
   *   Property value.
   *
   * @return $this
   */
  public function setAllowToken($allow_token) {
    $this->definition['allow_token'] = $allow_token;
    return $this;
  }

  /**
   * Get default value property.
   *
   * @return mixed
   *   Property value.
   */
  public function getForcedValue() {
    return $this->definition['forced_value'];
  }

  /**
   * Get preview property.
   *
   * @return mixed
   *   Property value.
   */
  public function getPreview() {
    return $this->definition['preview'];
  }

  /**
   * Set default value property.
   *
   * @return mixed
   *   Property value.
   */
  public function setForcedValue($forcedValue) {
    $this->definition['forced_value'] = $forcedValue;
    return $this;
  }

  /**
   * Get exposable property.
   *
   * @return string
   *   Property value.
   */
  public function allowExpose() {
    return $this->definition['allow_expose'];
  }

  /**
   * Set Exposable property.
   *
   * @param string $allow_expose
   *   Property value.
   *
   * @return $this
   */
  public function setAllowExpose($allow_expose) {
    $this->definition['allow_expose'] = $allow_expose;
    return $this;
  }

  /**
   * Get Description property.
   *
   * @return string
   *   Property value.
   */
  public function getDescription() {
    return $this->definition['description'];
  }

  /**
   * Set Description property.
   *
   * @param string $description
   *   Property value.
   *
   * @return $this
   */
  public function setDescription($description) {
    $this->definition['description'] = $description;
    return $this;
  }

  /**
   * Is form visible property.
   *
   * @return bool
   *   Property value.
   */
  public function isFormVisible() {
    return $this->definition['form_visible'];
  }

  /**
   * Set form visible property.
   *
   * @param bool $visible
   *   Property value.
   *
   * @return $this
   */
  public function setFormVisible($visible) {
    $this->definition['form_visible'] = $visible;
    return $this;
  }

  /**
   * Get Type property.
   *
   * @return string
   *   Property value.
   */
  public function getType() {
    return $this->definition['type'];
  }

  /**
   * Set Type property.
   *
   * @param string $type
   *   Property value.
   *
   * @return $this
   */
  public function setType($type) {
    $this->definition['type'] = $type;
    return $this;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ArrayAccessDefinitionTrait::offsetExists public function
ArrayAccessDefinitionTrait::offsetGet public function
ArrayAccessDefinitionTrait::offsetSet public function
ArrayAccessDefinitionTrait::offsetUnset public function
PatternDefinitionSetting::$definition protected property Default setting values.
PatternDefinitionSetting::allowExpose public function Get exposable property.
PatternDefinitionSetting::getAllowToken public function Get allow token property.
PatternDefinitionSetting::getDefaultValue public function Get default value property.
PatternDefinitionSetting::getDescription public function Get Description property.
PatternDefinitionSetting::getForcedValue public function Get default value property.
PatternDefinitionSetting::getGroup public function Get Group property.
PatternDefinitionSetting::getLabel public function Get Label property.
PatternDefinitionSetting::getName public function Get Name property.
PatternDefinitionSetting::getOptions public function Get options array.
PatternDefinitionSetting::getPreview public function Get preview property.
PatternDefinitionSetting::getRequired public function Get required property.
PatternDefinitionSetting::getType public function Get Type property.
PatternDefinitionSetting::getValue public function Return any definition value.
PatternDefinitionSetting::getWeight public function Get weight value property.
PatternDefinitionSetting::isFormVisible public function Is form visible property.
PatternDefinitionSetting::setAllowExpose public function Set Exposable property.
PatternDefinitionSetting::setAllowToken public function Set allow token value property.
PatternDefinitionSetting::setDefaultValue public function Set default value property.
PatternDefinitionSetting::setDescription public function Set Description property.
PatternDefinitionSetting::setForcedValue public function Set default value property.
PatternDefinitionSetting::setFormVisible public function Set form visible property.
PatternDefinitionSetting::setType public function Set Type property.
PatternDefinitionSetting::setWeight public function Set weight property.
PatternDefinitionSetting::toArray public function Return array definition.
PatternDefinitionSetting::__construct public function PatternDefinitionSetting constructor.