RemoveDataFromSessionAction.php in Rules Session Variables 2.0.x
File
src/Plugin/RulesAction/RemoveDataFromSessionAction.php
View source
<?php
namespace Drupal\rules_session_vars\Plugin\RulesAction;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\rules\Core\RulesActionBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
class RemoveDataFromSessionAction extends RulesActionBase implements ContainerFactoryPluginInterface {
protected $session;
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;
}
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());
}
protected function doExecute($data_key) {
if ($this->session) {
$this->session
->remove($data_key);
}
}
}