Commit 4f37ca65 authored by renatog's avatar renatog Committed by renatog
Browse files

Issue #3268060 by RenatoG: Remove cookie for Modal welcome when is deleted

parent 3aca9433
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -8,6 +8,8 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Response;

/**
 * Implements hook_form_alter().
@@ -192,13 +194,24 @@ function modal_page_entity_presave(EntityInterface $entity) {
 */
function modal_page_modal_submit($modal, $modal_state, $modal_id) {

  // If isn't the Modal for welcome, skip.
  if ($modal_id != 'thank_you_for_installing_modal_page') {
    return FALSE;
  }

  // If wasn't clicked on don't show again, skip.
  if (empty($modal_state['dont_show_again_option']) || $modal_state['dont_show_again_option'] == 'false') {
    return FALSE;
  }

  // Delete the Modal used on welcome Message.
  $modal->delete();

  // Delete cookie for welcome Modal.
  if (!empty(\Drupal::service('request_stack')->getCurrentRequest()->cookies->get('hide_modal_id_thank_you_for_installing_modal_page'))) {
    $response = new Response();
    $cookie = new Cookie('hide_modal_id_thank_you_for_installing_modal_page', '', time() - 3600, '/', NULL, FALSE);
    $response->headers->setCookie($cookie);
    $response->send();
  }
}