You are here

class LtiToolProviderEvent in LTI Tool Provider 8

Same name and namespace in other branches
  1. 2.x src/LtiToolProviderEvent.php \Drupal\lti_tool_provider\LtiToolProviderEvent

Hierarchy

  • class \Drupal\lti_tool_provider\LtiToolProviderEvent extends \Symfony\Component\EventDispatcher\Event

Expanded class hierarchy of LtiToolProviderEvent

17 files declare their use of LtiToolProviderEvent
LTIToolProvider.php in src/Authentication/Provider/LTIToolProvider.php
LtiToolProviderAttributesEvent.php in modules/lti_tool_provider_attributes/src/Event/LtiToolProviderAttributesEvent.php
LtiToolProviderAttributesEventSubscriber.php in modules/lti_tool_provider_attributes/src/EventSubscriber/LtiToolProviderAttributesEventSubscriber.php
LtiToolProviderAuthenticatedEvent.php in src/Event/LtiToolProviderAuthenticatedEvent.php
LTIToolProviderController.php in src/Controller/LTIToolProviderController.php

... See full list

File

src/LtiToolProviderEvent.php, line 11

Namespace

Drupal\lti_tool_provider
View source
class LtiToolProviderEvent extends Event {
  const EVENT_NAME = 'LTI_TOOL_PROVIDER_EVENT';

  /**
   * @var bool
   */
  private $cancelled = false;

  /**
   * @var string
   */
  private $message;

  /**
   * @return bool
   */
  public function isCancelled() : bool {
    return $this->cancelled;
  }
  public function cancel(string $message = 'Launch has been cancelled.') : void {
    $this->cancelled = true;
    $this->message = $message;
    $this
      ->stopPropagation();
  }

  /**
   * @return string
   */
  public function getMessage() : string {
    return $this->message;
  }

  /**
   * Dispatch an LTI Tool Provider event.
   *
   * @param EventDispatcherInterface $eventDispatcher
   *   The event dispatcher.
   * @param LtiToolProviderEvent $event
   *   The event to dispatch.
   * @throws Exception
   */
  static function dispatchEvent(EventDispatcherInterface $eventDispatcher, LtiToolProviderEvent &$event) {
    $event = $eventDispatcher
      ->dispatch($event::EVENT_NAME, $event);
    if ($event instanceof LtiToolProviderEvent && $event
      ->isCancelled()) {
      throw new Exception($event
        ->getMessage());
    }
  }

  /**
   * Send an error back to the LMS.
   *
   * @param array $context
   *   The LTI context.
   * @param string $message
   *   The error message to send.
   */
  public function sendLtiError(array $context, string $message) {
    if (isset($context['launch_presentation_return_url']) && !empty($context['launch_presentation_return_url'])) {
      $url = Url::fromUri($context['launch_presentation_return_url'])
        ->setOption('query', [
        'lti_errormsg' => $message,
      ])
        ->setAbsolute(true)
        ->toString();
      $response = new RedirectResponse($url);
      $response
        ->send();
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LtiToolProviderEvent::$cancelled private property
LtiToolProviderEvent::$message private property
LtiToolProviderEvent::cancel public function
LtiToolProviderEvent::dispatchEvent static function Dispatch an LTI Tool Provider event.
LtiToolProviderEvent::EVENT_NAME constant 11
LtiToolProviderEvent::getMessage public function
LtiToolProviderEvent::isCancelled public function
LtiToolProviderEvent::sendLtiError public function Send an error back to the LMS.