public function Form::getComponents in Form Builder 7.2
Get a list of component-arrays just like in $node->webform['components'].
1 call to Form::getComponents()
- Form::updateNode in modules/
webform/ src/ Form.php
File
- modules/
webform/ src/ Form.php, line 117
Class
Namespace
Drupal\form_builder_webformCode
public function getComponents($node) {
// Max CID is used in the creation of new components, preventing conflicts.
$cids = array();
// Filter out all cids from removed components.
foreach (array_keys($node->webform['components']) as $cid) {
if ($this
->getElement("cid_{$cid}")) {
$cids[] = $cid;
}
}
$max_cid = !empty($cids) ? max($cids) : 0;
$components = array();
// Keep track of the element_id => cid mapping for assigning the pid.
$element_cid_map = array();
$page = 1;
foreach ($this
->getElementsInPreOrder() as $element_id => $element) {
if ($component = $this
->getComponent($element_id)) {
if (empty($component['cid'])) {
$component['cid'] = ++$max_cid;
}
$element_cid_map[$element_id] = $component['cid'];
// Set the possibly changed pid.
$parent_id = $element
->parentId();
$component['pid'] = $parent_id === FORM_BUILDER_ROOT ? 0 : $element_cid_map[$parent_id];
$component['page_num'] = $page;
$components[$component['cid']] = $component;
if ($component['type'] == 'pagebreak') {
$page++;
}
}
}
return $components;
}