You are here

function WebformCalculationComponentsFormTree::buildTreePath in Webform Calculation Components 7

Same name and namespace in other branches
  1. 7.2 WebformCalculationComponentsFormTree.php \WebformCalculationComponentsFormTree::buildTreePath()

Builds up a tree path to insert AJAX attributes.

Parameters

array $components_tree: The array of components in a tree shape taken from the webform node form array. It will be used to build up the path array to insert the AJAX attributes.

array $tree_path: An array with the cid (Component Id) of the current wb_calc component as the key and the current wb_calc component form key as the value.

string $wb_calc_comp_pid: The pid (Parent Id) of the wb_calc component that calls this function.

Return value

array It returns an unidimensional array (complete) with the list of component form keys that specifies the tree path. It will be used to insert the AJAX attributes.

1 call to WebformCalculationComponentsFormTree::buildTreePath()
WebformCalculationComponentsFormTree::getOperationData in ./WebformCalculationComponentsFormTree.php
Builds up an array with the necessary data of the calculation elements.

File

./WebformCalculationComponentsFormTree.php, line 35
Handles the arrays passed in the webform node.

Class

WebformCalculationComponentsFormTree
@file Handles the arrays passed in the webform node.

Code

function buildTreePath(array $components_tree, array $tree_path, $wb_calc_comp_pid) {

  // Return if there is not a fieldset parent.
  if ($wb_calc_comp_pid == 0) {
    return $tree_path;
  }

  // The highest branch of the tree path is stored.
  $tree_path_first_index = (int) $wb_calc_comp_pid;

  // We loop until the root is reached.
  while ($tree_path_first_index != 0) {

    // The parent fieldset is isolated in one array.
    array_unshift($tree_path, $components_tree[$tree_path_first_index]['form_key']);
    $tree_path_first_index = (int) $components_tree[$tree_path_first_index]['pid'];
  }
  return $tree_path;
}