コード例 #1
0
 /**
  * Maps provided context values from the plugin to the Rules state.
  *
  * @param ContextProviderInterface $plugin
  *   The plugin where the context values are extracted.
  * @param \Drupal\rules\Engine\ExecutionStateInterface $state
  *   The Rules state where the context variables are added.
  */
 protected function mapProvidedContext(ContextProviderInterface $plugin, ExecutionStateInterface $state)
 {
     $provides = $plugin->getProvidedContextDefinitions();
     foreach ($provides as $name => $provided_definition) {
         // Avoid name collisions in the rules state: provided variables can be
         // renamed.
         if (isset($this->configuration['provides_mapping'][$name])) {
             $state->setVariableData($this->configuration['provides_mapping'][$name], $plugin->getProvidedContext($name)->getContextData());
         } else {
             $state->setVariableData($name, $plugin->getProvidedContext($name)->getContextData());
         }
     }
 }
コード例 #2
0
ファイル: RulesLoop.php プロジェクト: DrupalTV/DrupalTV
 /**
  * {@inheritdoc}
  */
 public function executeWithState(ExecutionStateInterface $state)
 {
     $list_data = $state->fetchDataByPropertyPath($this->configuration['list']);
     // Use a configured list item variable name, otherwise fall back to just
     // 'list_item' as variable name.
     $list_item_name = isset($this->configuration['list_item']) ? $this->configuration['list_item'] : 'list_item';
     foreach ($list_data as $item) {
         $state->setVariableData($list_item_name, $item);
         foreach ($this->actions as $action) {
             $action->executeWithState($state);
         }
     }
     // After the loop the list item is out of scope and cannot be used by any
     // following actions.
     $state->removeVariable($list_item_name);
 }
コード例 #3
0
 /**
  * Adds provided context values from the plugin to the execution state.
  *
  * @param CoreContextAwarePluginInterface $plugin
  *   The context aware plugin of which to add provided context.
  * @param \Drupal\rules\Engine\ExecutionStateInterface $state
  *   The Rules state where the context variables are added.
  */
 protected function addProvidedContext(CoreContextAwarePluginInterface $plugin, ExecutionStateInterface $state)
 {
     // If the plugin does not support providing context, there is nothing to do.
     if (!$plugin instanceof ContextProviderInterface) {
         return;
     }
     $provides = $plugin->getProvidedContextDefinitions();
     foreach ($provides as $name => $provided_definition) {
         // Avoid name collisions in the rules state: provided variables can be
         // renamed.
         if (isset($this->configuration['provides_mapping'][$name])) {
             $state->setVariableData($this->configuration['provides_mapping'][$name], $plugin->getProvidedContext($name)->getContextData());
         } else {
             $state->setVariableData($name, $plugin->getProvidedContext($name)->getContextData());
         }
     }
 }