Skip to content

Commit

Permalink
EventSub updates
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonlarsson committed Aug 29, 2017
1 parent adad4da commit e797538
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 36 deletions.
26 changes: 0 additions & 26 deletions auth_prompt/auth_prompt.api.php

This file was deleted.

4 changes: 2 additions & 2 deletions auth_prompt/auth_prompt.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ name: Auth Prompt
type: module
description: Auth Prompt Message
package: message
core: '8.x'
project: 'auth_prompt'
core: 8.x
project: Auth Prompt
14 changes: 14 additions & 0 deletions auth_prompt/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "drupal/auth_prompt",
"type": "drupal-module",
"description": "Auth prompt module for prompting users in Drupal 8.",
"keywords": ["Drupal"],
"license": "GPL-2.0+",
"homepage": "https://www.drupal.org/project/auth_prompt",
"minimum-stability": "dev",
"support": {
"issues": "http://drupal.org/project/issues/auth_prompt",
"source": "http://cgit.drupalcode.org/auth_prompt"
},
"require": { }
}
28 changes: 28 additions & 0 deletions auth_prompt/src/AuthPrompt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Drupal\auth_prompt;

use Symfony\Component\EventDispatcher\Event;


class AuthPrompt extends Event {

const SUBMIT = 'event.submit';

protected $referenceID;

public function __construct($referenceID)
{
$this->referenceID = $referenceID;
}

public function getReferenceID()
{
return $this->referenceID;
}

public function myEventDescription() {
return "This is as an auth prompt event";
}

}
24 changes: 16 additions & 8 deletions auth_prompt/src/EventSubscriber/AuthPromptSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,28 @@
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class auth_prompt_Subscriber implements EventSubscriberInterface {

public function checkForRedirection(GetResponseEvent $event) {
if ($event->getRequest()->query->get('redirect-me')) {
$event->setResponse(new RedirectResponse('/user/login'));
}
}
/**
* Class ExampleEventSubScriber.
*
* @package Drupal\auth_prompt
*/
class AuthPromptSubscriber implements EventSubscriberInterface {

/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[KernelEvents::REQUEST][] = array('checkForRedirection');
$events[KernelEvents::REQUEST][] = array('onKernelRequestAuthenticate', 300);
return $events;
}


/**
* Subscriber Callback for the event.
* @param AuthPrompt $event
*/
public function checkForAnonUser(KernelEvents $event) {
drupal_set_message(t('Please <a href="/user/login">Login</a> or <a href="/user/register">Register</a> to access all the services.'), 'warning');
}

}

0 comments on commit e797538

Please sign in to comment.