class RulesI18nStringEvaluator in Rules 7.2
A class implementing a rules input evaluator processing tokens.
Hierarchy
- class \RulesDataProcessor
- class \RulesDataInputEvaluator
- class \RulesI18nStringEvaluator
- class \RulesDataInputEvaluator
Expanded class hierarchy of RulesI18nStringEvaluator
1 string reference to 'RulesI18nStringEvaluator'
- rules_i18n_rules_evaluator_info in rules_i18n/
rules_i18n.rules.inc - Implements hook_rules_evaluator_info().
File
- rules_i18n/
rules_i18n.rules.inc, line 128 - Internationalization rules integration.
View source
class RulesI18nStringEvaluator extends RulesDataInputEvaluator {
/**
* Access callback.
*/
public static function access() {
return user_access('translate admin strings');
}
/**
* Overrides RulesDataInputEvaluator::prepare().
*/
public function prepare($text, $var_info, $param_info = NULL) {
if (!empty($param_info['translatable'])) {
$this->setting = TRUE;
}
else {
// Else, skip this evaluator.
$this->setting = NULL;
}
}
/**
* Prepare the i18n-context string.
*
* We have to use process() here instead of evaluate() because we need more
* context than evaluate() provides.
*/
public function process($value, $info, RulesState $state, RulesPlugin $element, $options = NULL) {
$options = isset($options) ? $options : $this
->getEvaluatorOptions($info, $state, $element);
$value = isset($this->processor) ? $this->processor
->process($value, $info, $state, $element, $options) : $value;
if (isset($element
->root()->name)) {
$config_name = $element
->root()->name;
$id = $element
->elementId();
$name = $info['#name'];
$options['i18n context'] = "rules:rules_config:{$config_name}:{$id}:{$name}";
return $this
->evaluate($value, $options, $state);
}
return $value;
}
/**
* Translate the value.
*
* If the element provides a language parameter, we are using this target
* language provided via $options['language']. Sanitizing is handled by Rules,
* so disable that for i18n.
*/
public function evaluate($value, $options, RulesState $state) {
$langcode = isset($options['language']) ? $options['language']->language : NULL;
if (is_array($value)) {
foreach ($value as $key => $text) {
$value[$key] = i18n_string($options['i18n context'] . ':' . $key, $text, array(
'langcode' => $langcode,
'sanitize' => FALSE,
));
}
}
else {
$value = i18n_string($options['i18n context'], $value, array(
'langcode' => $langcode,
'sanitize' => FALSE,
));
}
return $value;
}
/**
* Overrides RulesDataInputEvaluator::help().
*/
public static function help($var_info, $param_info = array()) {
if (!empty($param_info['translatable'])) {
if (!empty($param_info['custom translation language'])) {
$text = t('Translations can be provided at the %translate tab. The argument value is translated to the configured language.', array(
'%translate' => t('Translate'),
));
}
else {
$text = t('Translations can be provided at the %translate tab. The argument value is translated to the current interface language.', array(
'%translate' => t('Translate'),
));
}
$render = array(
'#theme' => 'rules_settings_help',
'#text' => $text,
'#heading' => t('Translation'),
);
return $render;
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RulesDataInputEvaluator:: |
public static | function |
Overrides RulesDataProcessor::attachForm(). Overrides RulesDataProcessor:: |
|
RulesDataInputEvaluator:: |
public static | function | Returns all input evaluators that can be applied to the parameters type. | |
RulesDataInputEvaluator:: |
protected | function | Generates the evaluator $options. | |
RulesDataInputEvaluator:: |
protected | function |
Return $this or skip this processor by returning the next processor. Overrides RulesDataProcessor:: |
|
RulesDataInputEvaluator:: |
public static | function |
Overridden to prepare input evaluator processors. Overrides RulesDataProcessor:: |
|
RulesDataInputEvaluator:: |
public static | function |
Overrides RulesDataProcessor::processors(). Overrides RulesDataProcessor:: |
|
RulesDataInputEvaluator:: |
protected | function |
Overridden to invoke prepare(). Overrides RulesDataProcessor:: |
|
RulesDataProcessor:: |
protected | property | Allows chaining processors. If set, the next processor to invoke. | |
RulesDataProcessor:: |
protected | property | The processors' setting value. | |
RulesDataProcessor:: |
public | function | Returns an array of modules which we depend on. | |
RulesDataProcessor:: |
public | function | Determines whether the current user has permission to edit this chain of data processors. | 2 |
RulesDataProcessor:: |
protected static | function | Defines the processor form element. | 3 |
RulesDataProcessor:: |
public | function | Gets the settings array for this and all contained chained processors. | |
RulesDataProcessor:: |
public | function | Gets the settings of this processor. | |
RulesDataProcessor:: |
protected | function | ||
RulesDataProcessor:: |
public static | function | ||
RulesI18nStringEvaluator:: |
public static | function |
Access callback. Overrides RulesDataProcessor:: |
|
RulesI18nStringEvaluator:: |
public | function |
Translate the value. Overrides RulesDataInputEvaluator:: |
|
RulesI18nStringEvaluator:: |
public static | function |
Overrides RulesDataInputEvaluator::help(). Overrides RulesDataInputEvaluator:: |
|
RulesI18nStringEvaluator:: |
public | function |
Overrides RulesDataInputEvaluator::prepare(). Overrides RulesDataInputEvaluator:: |
|
RulesI18nStringEvaluator:: |
public | function |
Prepare the i18n-context string. Overrides RulesDataInputEvaluator:: |