materio expo use now cookie instead of session
This commit is contained in:
@@ -5,24 +5,35 @@ namespace Drupal\materio_expo\Controller;
|
||||
use Drupal\Core\Controller\ControllerBase;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Drupal\Core\Url;
|
||||
use Symfony\Component\HttpFoundation\Cookie;
|
||||
|
||||
/**
|
||||
* Class QRController.
|
||||
*/
|
||||
class QRController extends ControllerBase {
|
||||
|
||||
public function setcookie($ref) {
|
||||
//? https://drupal.stackexchange.com/questions/278203/how-do-i-set-a-cookie-using-response-headers-setcookie-in-a-form-submission
|
||||
|
||||
// $form_state->setRedirect('materio_expo.qr_controller_getfile', ['ref'=>$ref]);
|
||||
// $response = new RedirectResponse(!empty($destination) ? $destination : '/');
|
||||
|
||||
$url = Url::fromRoute('materio_expo.qr_controller_getfile', ['ref'=>$ref]);
|
||||
$response = new RedirectResponse($url->toString());
|
||||
$response->headers->setCookie(new Cookie('materio_expo_email', true, strtotime( '+3 days' ), '/'));
|
||||
$response->send();
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hello.
|
||||
*
|
||||
* @return string
|
||||
* Return Hello string.
|
||||
*/
|
||||
public function getfile($ref) {
|
||||
//? https://drupal.stackexchange.com/questions/255216/how-to-do-a-redirectresponse-with-a-destination-query-parameter
|
||||
|
||||
//* check if email cookie is present (form submitted)
|
||||
$session = \Drupal::request()->getSession();
|
||||
$alreadysetemail = $session->get('materio_expo_email');
|
||||
// $session = \Drupal::request()->getSession();
|
||||
// $alreadysetemail = $session->get('materio_expo_email');
|
||||
$alreadysetemail = \Drupal::request()->cookies->get('materio_expo_email', false);
|
||||
if($alreadysetemail){
|
||||
|
||||
//* get node from ref
|
||||
|
Reference in New Issue
Block a user