You are here

public function WebformElementBase::getElementStateOptions in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Plugin/WebformElementBase.php \Drupal\webform\Plugin\WebformElementBase::getElementStateOptions()

Get an element's supported states as options.

Return value

array An array of element states.

Overrides WebformElementInterface::getElementStateOptions

1 call to WebformElementBase::getElementStateOptions()
WebformElementBase::form in src/Plugin/WebformElementBase.php
Gets the actual configuration webform array to be built.
1 method overrides WebformElementBase::getElementStateOptions()
WebformWizardPage::getElementStateOptions in src/Plugin/WebformElement/WebformWizardPage.php
Get an element's supported states as options.

File

src/Plugin/WebformElementBase.php, line 2186

Class

WebformElementBase
Provides a base class for a webform element.

Namespace

Drupal\webform\Plugin

Code

public function getElementStateOptions() {
  $visibility_optgroup = (string) $this
    ->t('Visibility');
  $state_optgroup = (string) $this
    ->t('State');
  $validation_optgroup = (string) $this
    ->t('Validation');
  $value_optgroup = (string) $this
    ->t('Value');
  $states = [];

  // Set default states that apply to the element/container and sub elements.
  $states += [
    $visibility_optgroup => [
      'visible' => $this
        ->t('Visible'),
      'invisible' => $this
        ->t('Hidden'),
      'visible-slide' => $this
        ->t('Visible (Slide)'),
      'invisible-slide' => $this
        ->t('Hidden (Slide)'),
    ],
    $state_optgroup => [
      'enabled' => $this
        ->t('Enabled'),
      'disabled' => $this
        ->t('Disabled'),
    ],
    $validation_optgroup => [
      'required' => $this
        ->t('Required'),
      'optional' => $this
        ->t('Optional'),
    ],
  ];

  // Set readwrite/readonly states for any element that supports it
  // and containers.
  if ($this
    ->hasProperty('readonly') || $this
    ->isContainer([
    '#type' => $this
      ->getPluginId(),
  ])) {
    $states[$state_optgroup] += [
      'readwrite' => $this
        ->t('Read/write'),
      'readonly' => $this
        ->t('Read-only'),
    ];
  }

  // Set checked/unchecked states for any element that contains checkboxes.
  if ($this instanceof Checkbox || $this instanceof Checkboxes) {
    $states[$value_optgroup] = [
      'checked' => $this
        ->t('Checked'),
      'unchecked' => $this
        ->t('Unchecked'),
    ];
  }

  // Set expanded/collapsed states for any details element.
  if ($this instanceof Details) {
    $states[$state_optgroup] += [
      'expanded' => $this
        ->t('Expanded'),
      'collapsed' => $this
        ->t('Collapsed'),
    ];
  }
  return $states;
}