class AddDataToSessionAction in Rules Session Variables 2.x
Same name and namespace in other branches
- 2.0.x src/Plugin/RulesAction/AddDataToSessionAction.php \Drupal\rules_session_vars\Plugin\RulesAction\AddDataToSessionAction
Provides a 'Add data to session' action.
Plugin annotation
@RulesAction(
id = "add_data_to_session",
label = @Translation("Store value to $_SESSION"),
category = @Translation("Session"),
context_definitions = {
"session_key" = @ContextDefinition("string",
label = @Translation("Key to identify your session data")
),
"session_value" = @ContextDefinition("string",
label = @Translation("Data to be saved with the key provided")
)
}
)
Hierarchy
- class \Drupal\rules_session_vars\Plugin\RulesAction\AddDataToSessionAction extends \Drupal\rules\Core\RulesActionBase implements ContainerFactoryPluginInterface
Expanded class hierarchy of AddDataToSessionAction
File
- src/
Plugin/ RulesAction/ AddDataToSessionAction.php, line 27
Namespace
Drupal\rules_session_vars\Plugin\RulesActionView source
class AddDataToSessionAction extends RulesActionBase implements ContainerFactoryPluginInterface {
/**
* The session.
*
* @var \Symfony\Component\HttpFoundation\Session\SessionInterface|null
*/
protected $session;
/**
* Constructor for AddDataToSessionAction.
*
* @param array $configuration
* The configuration.
* @param string $plugin_id
* The plugin ID.
* @param mixed $plugin_definition
* The plugin definition.
* @param \Symfony\Component\HttpFoundation\Request|null $request
* The request.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, Request $request = NULL) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->session = $request ? $request
->getSession() : NULL;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('request_stack')
->getCurrentRequest());
}
/**
* {@inheritdoc}
*/
protected function doExecute($data_key, $data_value) {
if ($this->session) {
$this->session
->set($data_key, $data_value);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AddDataToSessionAction:: |
protected | property | The session. | |
AddDataToSessionAction:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
AddDataToSessionAction:: |
protected | function | ||
AddDataToSessionAction:: |
public | function | Constructor for AddDataToSessionAction. |