You are here

class RemoveDataFromSessionAction in Rules Session Variables 2.x

Same name and namespace in other branches
  1. 2.0.x src/Plugin/RulesAction/RemoveDataFromSessionAction.php \Drupal\rules_session_vars\Plugin\RulesAction\RemoveDataFromSessionAction

Provides a 'Remove data from session' action.

Plugin annotation


@RulesAction(
  id = "remove_data_from_session",
  label = @Translation("Remove value from $_SESSION"),
  category = @Translation("Session"),
  context_definitions = {
    "session_key" = @ContextDefinition("string",
      label = @Translation("Key to identify your session data")
    )
  }
)

Hierarchy

Expanded class hierarchy of RemoveDataFromSessionAction

File

src/Plugin/RulesAction/RemoveDataFromSessionAction.php, line 24

Namespace

Drupal\rules_session_vars\Plugin\RulesAction
View source
class RemoveDataFromSessionAction extends RulesActionBase implements ContainerFactoryPluginInterface {

  /**
   * The session.
   *
   * @var \Symfony\Component\HttpFoundation\Session\SessionInterface|null
   */
  protected $session;

  /**
   * Constructor for RemoveDataFromSessionAction.
   *
   * @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) {
    if ($this->session) {
      $this->session
        ->remove($data_key);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RemoveDataFromSessionAction::$session protected property The session.
RemoveDataFromSessionAction::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
RemoveDataFromSessionAction::doExecute protected function
RemoveDataFromSessionAction::__construct public function Constructor for RemoveDataFromSessionAction.