You are here

public static function RulesData::matchingDataSelector in Rules 7.2

Returns data for the given info and the to-be-configured parameter.

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.

$param_info: The information array about the to be configured parameter.

string $prefix: An optional prefix for the data selectors.

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

bool $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.

3 calls to RulesData::matchingDataSelector()
RulesDataUI::selectionForm in ui/ui.data.inc
Provides the selection form for a parameter.
rules_ui_form_data_selection_auto_completion in ui/ui.forms.inc
Autocomplete data selection results.
theme_rules_data_selector_help in ui/ui.theme.inc
Themes help for using the data selector.

File

includes/rules.state.inc, line 463
Contains the state and data related stuff.

Class

RulesData
A class holding static methods related to data.

Code

public static function matchingDataSelector($source, $param_info, $prefix = '', $recursions = 2, $suggestions = TRUE) {

  // If an array of info is given, get entity metadata wrappers first.
  $data = NULL;
  if (is_array($source)) {
    foreach ($source as $name => $info) {
      $source[$name] = rules_wrap_data($data, $info, TRUE);
    }
  }
  $matches = array();
  foreach ($source as $name => $wrapper) {
    $info = $wrapper
      ->info();
    $name = str_replace('_', '-', $name);
    if (self::typesMatch($info, $param_info)) {
      $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 += self::matchingDataSelector($wrapper, $param_info, $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;
}