You are here

class RouteEnhancer in Janrain Registration 8

The route enhancer.

Hierarchy

Expanded class hierarchy of RouteEnhancer

1 string reference to 'RouteEnhancer'
janrain_capture.services.yml in ./janrain_capture.services.yml
janrain_capture.services.yml
1 service uses RouteEnhancer
janrain_capture.route_enhancer in ./janrain_capture.services.yml
Drupal\janrain_capture\RouteEnhancer

File

src/RouteEnhancer.php, line 13

Namespace

Drupal\janrain_capture
View source
class RouteEnhancer implements EnhancerInterface {

  /**
   * The property to set to route's defaults and request's attributes.
   */
  public const JANRAIN_ACCOUNT_PROPERTY = '_janrain_account';

  /**
   * An instance of the "janrain_capture.capture_api" service.
   *
   * @var \Drupal\janrain_capture\JanrainCaptureApi
   */
  protected $captureApi;

  /**
   * {@inheritdoc}
   */
  public function __construct(JanrainCaptureApiInterface $capture_api) {
    $this->captureApi = $capture_api;
  }

  /**
   * {@inheritdoc}
   */
  public function enhance(array $defaults, Request $request) {
    if (isset($defaults['user'])) {
      if ($defaults['user'] instanceof UserInterface) {
        $janrain_account = $this->captureApi
          ->isJanrainAccount($defaults['user']);

        // The "self" is used since the name of the property
        // is closed for modifications.
        $defaults[self::JANRAIN_ACCOUNT_PROPERTY] = $janrain_account;
        $request->attributes
          ->set(self::JANRAIN_ACCOUNT_PROPERTY, $janrain_account);
      }
    }
    return $defaults;
  }

  /**
   * {@inheritdoc}
   */
  public function applies(Route $route) {
    return $route
      ->getOption('parameters')['user'] ?? FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RouteEnhancer::$captureApi protected property An instance of the "janrain_capture.capture_api" service.
RouteEnhancer::applies public function
RouteEnhancer::enhance public function
RouteEnhancer::JANRAIN_ACCOUNT_PROPERTY public constant The property to set to route's defaults and request's attributes.
RouteEnhancer::__construct public function