You are here

public static function PathBreadcrumbsUIAutocomplete::matchDataSelector in Path Breadcrumbs 7.3

Returns matching data variables or properties for the given info and the to be configured parameter.

Parameters

$source: Either an array of info about available variables or a entity metadata wrapper.

$prefix: An optional prefix for the data selectors.

$recursions: The number of recursions used to go down the tree. Defaults to 2.

$suggestions: Whether possibilities to recurse are suggested as soon as the deepest level of recursions is reached. Defaults to TRUE.

Return value

array An array of info about matching variables or properties that match, keyed with the data selector.

1 call to PathBreadcrumbsUIAutocomplete::matchDataSelector()
PathBreadcrumbsUIAutocomplete::processAutocomplete in path_breadcrumbs_ui/includes/path_breadcrumbs_ui.autocomplete.inc

File

path_breadcrumbs_ui/includes/path_breadcrumbs_ui.autocomplete.inc, line 95
Path breadcrumbs UI autocomplete.

Class

PathBreadcrumbsUIAutocomplete
@file Path breadcrumbs UI autocomplete.

Code

public static function matchDataSelector($source, $prefix = '', $recursions = 2, $suggestions = TRUE) {
  $matches = array();

  // Convert "parent" token from list to single item.
  if (preg_match('@:parent:$@', $prefix) && $source instanceof EntityListWrapper) {
    $source = $source
      ->get(0);
  }
  foreach ($source as $name => $wrapper) {
    $info = $wrapper
      ->info();

    // Keep underscores unchanged in context keywords.
    if (!array_key_exists($name, self::$context_keywords)) {
      $name = str_replace('_', '-', $name);
    }

    // Convert "parent" token from list to single item.
    if ($name == 'parent' && $wrapper instanceof EntityListWrapper) {
      $wrapper = $wrapper
        ->get(0);
    }
    $matches[$prefix . $name] = $info;
    if (!is_array($source) && $source instanceof EntityListWrapper) {

      // Add some more possible list items.
      for ($i = 1; $i < 4; $i++) {
        $matches[$prefix . $i] = $info;
      }
    }

    // Recurse later on to get an improved ordering of the results.
    if ($wrapper instanceof EntityStructureWrapper || $wrapper instanceof EntityListWrapper) {
      $recurse[$prefix . $name] = $wrapper;
      if ($recursions > 0) {
        $matches += PathBreadcrumbsUIAutocomplete::matchDataSelector($wrapper, $prefix . $name . ':', $recursions - 1, $suggestions);
      }
      elseif ($suggestions) {

        // We may not recurse any more, but indicate the possibility to recurse.
        $matches[$prefix . $name . ':'] = $wrapper
          ->info();
        if (!is_array($source) && $source instanceof EntityListWrapper) {

          // Add some more possible list items.
          for ($i = 1; $i < 4; $i++) {
            $matches[$prefix . $i . ':'] = $wrapper
              ->info();
          }
        }
      }
    }
  }
  return $matches;
}