class RulesI18nStringEvaluator
A class implementing a rules input evaluator processing tokens.
Hierarchy
- class \RulesDataProcessor
- class \RulesDataInputEvaluator extends \RulesDataProcessor
- class \RulesI18nStringEvaluator extends \RulesDataInputEvaluator
 
 
 - class \RulesDataInputEvaluator extends \RulesDataProcessor
 
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  
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
| Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides | 
|---|---|---|---|---|---|
| RulesDataInputEvaluator::attachForm | public static | function | Overrides RulesDataProcessor::attachForm(). | Overrides RulesDataProcessor::attachForm | |
| RulesDataInputEvaluator::evaluators | public static | function | Returns all input evaluators that can be applied to the parameters type. | ||
| RulesDataInputEvaluator::getEvaluatorOptions | protected | function | Generates the evaluator $options. | ||
| RulesDataInputEvaluator::getPreparedValue | protected | function | Return $this or skip this processor by returning the next processor. | Overrides RulesDataProcessor::getPreparedValue | |
| RulesDataInputEvaluator::prepareSetting | public static | function | Overridden to prepare input evaluator processors. | Overrides RulesDataProcessor::prepareSetting | |
| RulesDataInputEvaluator::processors | public static | function | Overrides RulesDataProcessor::processors(). | Overrides RulesDataProcessor::processors | |
| RulesDataInputEvaluator::__construct | protected | function | Overridden to invoke prepare(). | Overrides RulesDataProcessor::__construct | |
| RulesDataProcessor::$processor | protected | property | Allows chaining processors. If set, the next processor to invoke. | ||
| RulesDataProcessor::$setting | protected | property | The processors' setting value. | ||
| RulesDataProcessor::dependencies | public | function | Returns an array of modules which we depend on. | ||
| RulesDataProcessor::editAccess | public | function | Determines whether the current user has permission to edit this chain of data processors.  | 
                            2 | |
| RulesDataProcessor::form | protected static | function | Defines the processor form element. | 3 | |
| RulesDataProcessor::getChainSettings | public | function | Gets the settings array for this and all contained chained processors. | ||
| RulesDataProcessor::getSetting | public | function | Gets the settings of this processor. | ||
| RulesDataProcessor::unchain | protected | function | |||
| RulesDataProcessor::_item_sort | public static | function | |||
| RulesI18nStringEvaluator::access | public static | function | Access callback. | Overrides RulesDataProcessor::access | |
| RulesI18nStringEvaluator::evaluate | public | function | Translate the value. | Overrides RulesDataInputEvaluator::evaluate | |
| RulesI18nStringEvaluator::help | public static | function | Overrides RulesDataInputEvaluator::help(). | Overrides RulesDataInputEvaluator::help | |
| RulesI18nStringEvaluator::prepare | public | function | Overrides RulesDataInputEvaluator::prepare(). | Overrides RulesDataInputEvaluator::prepare | |
| RulesI18nStringEvaluator::process | public | function | Prepare the i18n-context string. | Overrides RulesDataInputEvaluator::process |