class EloquaEventSubscriber in Eloqua 8
Provides a response event subscriber for Eloqua. Sets config value for use in eloqua.module.
Hierarchy
- class \Drupal\eloqua\EventSubscriber\EloquaEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of EloquaEventSubscriber
1 string reference to 'EloquaEventSubscriber'
1 service uses EloquaEventSubscriber
File
- src/
EventSubscriber/ EloquaEventSubscriber.php, line 22 - Contains Drupal\eloqua\EventSubscriber\EloquaEventSubscriber
Namespace
Drupal\eloqua\EventSubscriberView source
class EloquaEventSubscriber implements EventSubscriberInterface {
/**
* The Eloqua config.
*
* @var \Drupal\Core\Config\Config
*/
protected $config;
/**
* The condition manager.
*
* @var \Drupal\Core\Executable\ExecutableManagerInterface
*/
protected $conditionManager;
/**
* Creates a new EloquaEventSubscriber.
*
* @param \Drupal\Core\Session\AccountInterface $account
* The current user.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
*
* @param \Drupal\Core\Executable\ExecutableManagerInterface $condition_manager
* The condition manager.
*/
public function __construct(AccountInterface $account, EntityManagerInterface $entity_manager, ConfigFactoryInterface $config_factory, ExecutableManagerInterface $condition_manager) {
$this->account = $account;
$this->userStorage = $entity_manager
->getStorage('user');
$this->config = $config_factory
->get('eloqua.settings');
$this->conditionManager = $condition_manager;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[KernelEvents::REQUEST][] = array(
'evaluateTrackingScope',
);
return $events;
}
/**
* Evaluates tracking scoping conditions and sets state setting.
*
* @param GetResponseEvent $event
*/
public function evaluateTrackingScope(GetResponseEvent $event) {
if (null !== $this->config
->get('site_identifier')) {
$user_role_config = $this->config
->get('user_roles');
$current_user = $this->userStorage
->load($this->account
->id());
/* @var \Drupal\user\Plugin\Condition\UserRole $condition */
$user_role = $this->conditionManager
->createInstance('user_role')
->setConfig('roles', $user_role_config['roles'])
->setContextValue('user', $current_user);
$user_role_result = $user_role
->evaluate();
/* @var \Drupal\system\Plugin\Condition\RequestPath $request_path */
$request_path = $this->conditionManager
->createInstance('request_path');
$request_path
->setConfiguration($this->config
->get('request_path'));
// Negate request_path if applicable.
$request_path_result = $request_path
->isNegated() ? !$request_path
->evaluate() : $request_path
->evaluate();
if ($user_role_result && $request_path_result) {
\Drupal::state()
->set('eloqua.condition_result', 1);
}
else {
\Drupal::state()
->set('eloqua.condition_result', 0);
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EloquaEventSubscriber:: |
protected | property | The condition manager. | |
EloquaEventSubscriber:: |
protected | property | The Eloqua config. | |
EloquaEventSubscriber:: |
public | function | Evaluates tracking scoping conditions and sets state setting. | |
EloquaEventSubscriber:: |
public static | function | ||
EloquaEventSubscriber:: |
public | function | Creates a new EloquaEventSubscriber. |