You are here

public function RulesPlugin::applyDataSelector in Rules 7.2

Applies the given data selector.

Applies the given data selector by using the info about available variables. Thus it doesn't require an actual evaluation state.

Parameters

string $selector: The selector string, e.g. "node:author:mail".

Return value

EntityMetadataWrapper An empty wrapper for the given selector or FALSE if the selector couldn't be applied.

3 calls to RulesPlugin::applyDataSelector()
RulesPlugin::access in includes/rules.core.inc
Whether the currently logged in user has access to all configured elements.
RulesPlugin::checkParameterSettings in includes/rules.core.inc
Checks whether parameters are correctly configured.
RulesPlugin::getArgumentInfo in includes/rules.core.inc
Returns info about the configured argument.

File

includes/rules.core.inc, line 1051
Rules base classes and interfaces needed for any rule evaluation.

Class

RulesPlugin
Base class for rules plugins.

Code

public function applyDataSelector($selector) {
  $parts = explode(':', str_replace('-', '_', $selector), 2);
  if (($vars = $this
    ->availableVariables()) && isset($vars[$parts[0]]['type'])) {
    $wrapper = rules_wrap_data(NULL, $vars[$parts[0]], TRUE);
    if (count($parts) > 1 && $wrapper instanceof EntityMetadataWrapper) {
      try {
        foreach (explode(':', $parts[1]) as $name) {
          if ($wrapper instanceof EntityListWrapper || $wrapper instanceof EntityStructureWrapper) {
            $wrapper = $wrapper
              ->get($name);
          }
          else {
            return FALSE;
          }
        }
      } catch (EntityMetadataWrapperException $e) {
        return FALSE;
      }
    }
  }
  return isset($wrapper) ? $wrapper : FALSE;
}