Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CAC Base Latest #2

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
Binary file removed cac_base/.DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions cac_base/cac_base.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ config_cac_base.description:
_controller: '\Drupal\cac_base\Controller\NodeTypeCompanyRegistration::description'
requirements:
_permission: 'access content'

cac_base.anony_login_prompt_dispatcher_form:
path: 'anony-login-prompt-dispatch-form'
defaults:
_form: '\Drupal\cac_base\Form\AnonyLoginPromptDispatchForm'
_title: 'AnonyLoginPrompt Dispatcher Form'
requirements:
_permission: 'access content'
24 changes: 24 additions & 0 deletions cac_base/src/AnonyLoginPrompt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Drupal\example_events;

use Symfony\Component\EventDispatcher\Event;

class ExampleEvent 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 "AnonyLoginPrompt event";
}
}
4 changes: 3 additions & 1 deletion cac_base/src/EventSubscriber/AnonyLoginPromptSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class AnonyLoginPromptSubscriber implements EventSubscriberInterface {
public function anonymousLoginPrompt(FilterResponseEvent $event) {
$request = $event->getRequest();
$redirect_url = $request->server->get('REQUEST_URI', null);
drupal_set_message(t('fffffffffff'), 'warning');
if (\Drupal::currentUser()->isAnonymous()) {
drupal_set_message(t('Please <a href="/user/login">Login</a> or <a href="/user/register"><strong>Register</strong></a> to access all the services we offer.'), 'warning');
}
}

/**
Expand Down
49 changes: 49 additions & 0 deletions cac_base/src/Form/AnonyLoginPromptDispatchForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* @file
* Contains \Drupal\cac_base\Form\AnonyLoginPromptDispatchForm.
*/
namespace Drupal\cac_base\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\cac_base\AnonyLoginPrompt;
/**
* Class AnonyLoginPromptDispatchForm.
*
* @package Drupal\cac_base\Form
*/
class AnonyLoginPromptDispatchForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'anony_login_prompt_dispatch_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['name'] = array(
'#type' => 'url',
'#title' => $this->t('Reference'),
'#maxlength' => 64,
'#size' => 64,
);
$form['dispatch'] = array(
'#type' => 'submit',
'#value' => $this->t('Dispatch'),
);
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Dispatching the event
$dispatcher = \Drupal::service('event_dispatcher');
$event = new AnonyLoginPrompt($form_state->getValue('name'));
$dispatcher->dispatch(AnonyLoginPrompt::SUBMIT, $event);

drupal_set_message(t('Please <a href="/user/login">Login</a> or <a href="/user/register"><strong>Register</strong></a> to access all the services we offer.'), 'warning');
}
}