function RulesPlugin::applyDataSelector

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 1058

Class

RulesPlugin
Base class for rules plugins.

Code

public function applyDataSelector($selector) {
  // Prevent PHP errors when $selector parameter is not a string.
  if (!is_string($selector)) {
    return FALSE;
  }
  $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;
}