You are here

public function FormBuilderWebformForm::getComponents in Form Builder 7

Get a list of component-arrays just like in $node->webform['components'].

1 call to FormBuilderWebformForm::getComponents()
FormBuilderWebformForm::updateNode in modules/webform/form_builder_webform.classes.inc

File

modules/webform/form_builder_webform.classes.inc, line 113

Class

FormBuilderWebformForm

Code

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;
}