You are here

public static function WebformElementHelper::getStates in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Utility/WebformElementHelper.php \Drupal\webform\Utility\WebformElementHelper::getStates()

Get an element's #states.

Parameters

array $element: An element.

Return value

array An associative array containing an element's states.

6 calls to WebformElementHelper::getStates()
WebformElementHelper::getRequiredFromVisibleStates in src/Utility/WebformElementHelper.php
Get required #states from an element's visible #states.
WebformMultiple::initializeElement in src/Element/WebformMultiple.php
Initialize element.
WebformSubmissionConditionsValidator::buildForm in src/WebformSubmissionConditionsValidator.php
Apply form #states to visible elements.
WebformSubmissionConditionsValidator::isElementEnabled in src/WebformSubmissionConditionsValidator.php
Determine if an element is enabled.
WebformSubmissionConditionsValidator::isElementVisible in src/WebformSubmissionConditionsValidator.php
Determine if an element is visible.

... See full list

File

src/Utility/WebformElementHelper.php, line 787

Class

WebformElementHelper
Helper class webform element methods.

Namespace

Drupal\webform\Utility

Code

public static function &getStates(array &$element) {

  // Processed elements store the original #states in '#_webform_states'.
  // @see \Drupal\webform\WebformSubmissionConditionsValidator::buildForm
  //
  // Composite and multiple elements use a custom states wrapper
  // which will change '#states' to '#_webform_states'.
  // @see \Drupal\webform\Utility\WebformElementHelper::fixStatesWrapper
  if (!empty($element['#_webform_states'])) {
    return $element['#_webform_states'];
  }
  elseif (!empty($element['#states'])) {
    return $element['#states'];
  }
  else {

    // Return empty states variable to prevent the below notice.
    // 'Only variable references should be returned by reference'.
    $empty_states = [];
    return $empty_states;
  }
}