public function WebformOptionsStorage::getUsedByCompositeElements in Webform 8.5
Same name and namespace in other branches
- 6.x src/WebformOptionsStorage.php \Drupal\webform\WebformOptionsStorage::getUsedByCompositeElements()
Get list of composite elements that use the specified webform options.
Parameters
\Drupal\webform\WebformOptionsInterface $webform_options: A webform options entity.
Return value
array A list of composite elements that use the specified webform options.
Overrides WebformOptionsStorageInterface::getUsedByCompositeElements
File
- src/
WebformOptionsStorage.php, line 144
Class
- WebformOptionsStorage
- Storage controller class for "webform_options" configuration entities.
Namespace
Drupal\webformCode
public function getUsedByCompositeElements(WebformOptionsInterface $webform_options) {
if (!isset($this->usedByCompositeElements)) {
$this->usedByCompositeElements = [];
$definitions = $this->elementInfo
->getDefinitions();
foreach (array_keys($definitions) as $plugin_id) {
/** @var \Drupal\Core\Render\Element\ElementInterface $element */
$element = $this->elementInfo
->createInstance($plugin_id);
// Make sure element is composite and not provided by the
// webform_composite.module.
if (!$element instanceof WebformCompositeBase || in_array($plugin_id, [
'webform_composite',
])) {
continue;
}
$composite_elements = $element
->getCompositeElements([]);
foreach ($composite_elements as $composite_element_key => $composite_element) {
if (isset($composite_element['#options'])) {
$webform_element_definition = $this->elementManager
->getDefinition($plugin_id);
$f_args = [
'@composite' => $webform_element_definition['label'],
'@element' => $composite_element['#title'],
];
$this->usedByCompositeElements[$composite_element_key]["{$plugin_id}:{$composite_element_key}"] = new FormattableMarkup('@composite (@element)', $f_args);
}
}
}
}
$options_id = $webform_options
->id();
$used_by = [];
foreach ($this->usedByCompositeElements as $key => $elements) {
if (strpos($options_id, $key) === 0) {
$used_by = array_merge($used_by, $elements);
}
}
if ($used_by) {
$used_by = array_unique($used_by);
asort($used_by);
}
return $used_by;
}