protected function WebformUiEntityElementsForm::getOrderableElements in Webform 6.x
Same name and namespace in other branches
- 8.5 modules/webform_ui/src/WebformUiEntityElementsForm.php \Drupal\webform_ui\WebformUiEntityElementsForm::getOrderableElements()
Get webform's elements as an associative array of orderable elements.
Return value
array An associative array of orderable elements.
1 call to WebformUiEntityElementsForm::getOrderableElements()
- WebformUiEntityElementsForm::buildForm in modules/
webform_ui/ src/ WebformUiEntityElementsForm.php - Form constructor.
File
- modules/
webform_ui/ src/ WebformUiEntityElementsForm.php, line 309
Class
- WebformUiEntityElementsForm
- Webform manage elements UI form.
Namespace
Drupal\webform_uiCode
protected function getOrderableElements() {
/** @var \Drupal\webform\WebformInterface $webform */
$webform = $this
->getEntity();
$elements = $webform
->getElementsInitializedAndFlattened();
$weights = [];
foreach ($elements as $element_key => &$element) {
$parent_key = $element['#webform_parent_key'];
if (!isset($weights[$parent_key])) {
$element['#weight'] = $weights[$parent_key] = 0;
}
else {
$element['#weight'] = ++$weights[$parent_key];
}
if (empty($element['#type'])) {
if (isset($element['#theme'])) {
$element['#type'] = $element['#theme'];
}
else {
$element['#type'] = '';
}
}
if (empty($element['#title'])) {
if (!empty($element['#markup'])) {
$element['#title'] = Markup::create(Unicode::truncate(strip_tags($element['#markup']), 100, TRUE, TRUE));
}
else {
$element['#title'] = '[' . $element_key . ']';
}
}
}
return $elements;
}