You are here

private static function GoogleAdwordsPathTracker::_buildPathTreeRecursive in Google AdWords Conversion Tracking 8

Parameters

\Drupal\google_adwords_path\Entity\GoogleAdwordsPathConfig $pathConfig:

array $tree: a render tree of exploded path parts, into which the pathconfig item should be inserted

array $path: an exploded partial route|path to match the tree

1 call to GoogleAdwordsPathTracker::_buildPathTreeRecursive()
GoogleAdwordsPathTracker::_buildPathTree in modules/google_adwords_path/src/GoogleAdwordsPathTracker.php
Build the GoogleAdwordsPathConfig path render tree

File

modules/google_adwords_path/src/GoogleAdwordsPathTracker.php, line 381
Contains Drupal\google_adwords_path\GoogleAdwordsPathTracker.

Class

GoogleAdwordsPathTracker
Class GoogleAdwordsPathTracker.

Namespace

Drupal\google_adwords_path

Code

private static function _buildPathTreeRecursive(GoogleAdwordsPathConfig &$pathConfig, array &$tree, array $path) {
  if (count($path) == 0) {
    if (!isset($tree[static::GOOGLE_ADWORDS_PATH_TREE_NODEKEY])) {
      $tree[static::GOOGLE_ADWORDS_PATH_TREE_NODEKEY] = [];
    }
    $tree[static::GOOGLE_ADWORDS_PATH_TREE_NODEKEY][$pathConfig
      ->id()] = $pathConfig
      ->id();
  }
  else {

    /**
     * @var string $pathElement
     *   a single element of the path
     */
    $pathElement = '';

    /**
     * @note some url syntax can create empty exploded items:
     *   - leading /
     *   - double-slash
     */
    while (empty($pathElement)) {
      if (count($path) == 0) {
        break;
      }
      $pathElement = array_shift($path);
    }
    if (empty($pathElement)) {

      // no more items in the path, pass it back for adding
      self::_buildPathTreeRecursive($pathConfig, $tree, []);
    }
    else {

      // sanity check on the tree array (prevent PHP warnings)
      if (!isset($tree[$pathElement])) {
        $tree[$pathElement] = [];
      }
      self::_buildPathTreeRecursive($pathConfig, $tree[$pathElement], $path);
    }
  }
}