I have a block that creates a private_tempstore value (which I understand works exactly like PHP sessions).
How do I unset that value.
This is the code I am using for the block.
class SsoSessionBlock extends BlockBase {
/**
* {@inheritdoc}
*/
public function build(){
$value = 'dav';
$session = \Drupal::service('user.private_tempstore')->get('achva_sso');
$session->set('name', $value);
return [
'#type' => 'markup',
'#markup' => $this->t('The output of super SsoSessionBlock block.'),
];
}
}
I saw this method, but I am not sure how I am supposed to use it.
I tried the following code, but I get an error.
namespace Drupal\achva_sso\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Routing\TrustedRedirectResponse;
use Drupal\user;
class SsoController extends ControllerBase{
public function ssoLogout(){
$session = \Drupal::service('user.private_tempstore')->get('achva_sso');
PrivateTempStore::delete('name');
if(isset($session)){
$status = $session .' is logged in';
}else{
$status = 'is logged out';
}
return[
'#type' => 'markup',
'#markup' => '<p>' . $status . '</p>' ,
];
}
}
How do I unset a value I previously set?