public static function WebformElementHelper::getRequiredFromVisibleStates in Webform 8.5
Same name and namespace in other branches
- 6.x src/Utility/WebformElementHelper.php \Drupal\webform\Utility\WebformElementHelper::getRequiredFromVisibleStates()
Get required #states from an element's visible #states.
This method allows composite and multiple to conditionally require sub-elements when they are visible.
Parameters
array $element: An element.
Return value
array An associative array containing 'visible' and 'invisible' selectors and triggers.
2 calls to WebformElementHelper::getRequiredFromVisibleStates()
- WebformCompositeBase::processWebformCompositeElementsRecursive in src/
Element/ WebformCompositeBase.php - Recursively processes a composite's elements.
- WebformMultiple::initializeElement in src/
Element/ WebformMultiple.php - Initialize element.
File
- src/
Utility/ WebformElementHelper.php, line 821
Class
- WebformElementHelper
- Helper class webform element methods.
Namespace
Drupal\webform\UtilityCode
public static function getRequiredFromVisibleStates(array $element) {
$states = WebformElementHelper::getStates($element);
$required_states = [];
if (!empty($states['visible'])) {
$required_states['required'] = $states['visible'];
}
if (!empty($states['invisible'])) {
$required_states['optional'] = $states['invisible'];
}
return $required_states;
}