function RulesPlugin::getArgument

Returns the argument for the parameter $name described with $info.

Returns the argument as configured in the element settings for the parameter $name described with $info.

Parameters

string $name: The name of the parameter for which to get the argument.

$info: Info about the parameter.

RulesState $state: The current evaluation state.

string $langcode: (optional) The language code used to get the argument value if the argument value should be translated. By default (NULL) the current interface language will be used.

Return value

The argument, possibly wrapped.

Throws

RulesEvaluationException In case the argument cannot be retrieved an exception is thrown.

3 calls to RulesPlugin::getArgument()
RulesLoop::evaluate in includes/rules.plugins.inc
Evaluate, whereas by default new vars are visible in the parent's scope.
RulesPlugin::getExecutionArguments in includes/rules.core.inc
Gets the right arguments for executing the element.
RulesPlugin::returnVariables in includes/rules.core.inc
Gets variables to return once the configuration has been executed.

File

includes/rules.core.inc, line 963

Class

RulesPlugin
Base class for rules plugins.

Code

protected function getArgument($name, $info, RulesState $state, $langcode = NULL) {
    // Only apply the langcode if the parameter has been marked translatable.
    if (empty($info['translatable'])) {
        $langcode = LANGUAGE_NONE;
    }
    elseif (!isset($langcode)) {
        $langcode = $GLOBALS['language']->language;
    }
    if (!empty($this->settings[$name . ':select'])) {
        $arg = $state->applyDataSelector($this->settings[$name . ':select'], $langcode);
    }
    elseif (isset($this->settings[$name])) {
        $arg = rules_wrap_data($this->settings[$name], $info);
        // We don't sanitize directly specified values.
        $skip_sanitize = TRUE;
    }
    elseif ($state->varinfo($name)) {
        $arg = $state->get($name);
    }
    elseif (empty($info['optional']) && $info['type'] != 'hidden') {
        throw new RulesEvaluationException('Required parameter %name is missing.', array(
            '%name' => $name,
        ), $this, RulesLog::ERROR);
    }
    else {
        $arg = isset($info['default value']) ? $info['default value'] : NULL;
        $skip_sanitize = TRUE;
        $info['allow null'] = TRUE;
    }
    // Make sure the given value is set if required (default).
    if (!isset($arg) && empty($info['allow null'])) {
        throw new RulesEvaluationException('The provided argument for parameter %name is empty.', array(
            '%name' => $name,
        ), $this);
    }
    // Support passing already sanitized values.
    if ($info['type'] == 'text' && !isset($skip_sanitize) && !empty($info['sanitize']) && !$arg instanceof EntityMetadataWrapper) {
        $arg = check_plain((string) $arg);
    }
    // Apply any configured data processors.
    if (!empty($this->settings[$name . ':process'])) {
        // For processing, make sure the data is unwrapped now.
        $return = rules_unwrap_data(array(
            $arg,
        ), array(
            $info,
        ));
        // @todo For Drupal 8: Refactor to add the name and language code as
        // separate parameter to process().
        $info['#name'] = $name;
        $info['#langcode'] = $langcode;
        return isset($return[0]) ? $this->settings[$name . ':process']
            ->process($return[0], $info, $state, $this) : NULL;
    }
    return $arg;
}