You are here

class LoginDestinationToolbarLinkBuilder in Login Destination 8

Same name and namespace in other branches
  1. 8.2 src/LoginDestinationToolbarLinkBuilder.php \Drupal\login_destination\LoginDestinationToolbarLinkBuilder

ToolbarLinkBuilder fills out the placeholders generated in user_toolbar().

Hierarchy

Expanded class hierarchy of LoginDestinationToolbarLinkBuilder

1 string reference to 'LoginDestinationToolbarLinkBuilder'
login_destination.services.yml in ./login_destination.services.yml
login_destination.services.yml
1 service uses LoginDestinationToolbarLinkBuilder
login_destination.toolbar_link_builder in ./login_destination.services.yml
Drupal\login_destination\LoginDestinationToolbarLinkBuilder

File

src/LoginDestinationToolbarLinkBuilder.php, line 11

Namespace

Drupal\login_destination
View source
class LoginDestinationToolbarLinkBuilder extends ToolbarLinkBuilder {

  /**
   * The decorated service.
   *
   * @var \Drupal\user\ToolbarLinkBuilder
   */
  protected $innerService;

  /**
   * ToolbarHandler constructor.
   *
   * @param \Drupal\user\ToolbarLinkBuilder $inner_service
   *   The decorated service.
   * @param \Drupal\Core\Session\AccountProxyInterface $account
   *   The current user.
   */
  public function __construct(ToolbarLinkBuilder $inner_service, AccountProxyInterface $account) {
    $this->innerService = $inner_service;
    parent::__construct($account);
  }

  /**
   * Pass any undefined method calls onto the inner service.
   *
   * @param string $method
   *   The method being called.
   * @param array $args
   *   The arguments passed to the method.
   *
   * @return mixed
   *   The inner services response.
   */
  public function __call($method, array $args = []) {
    return call_user_func_array([
      $this->innerService,
      $method,
    ], $args);
  }

  /**
   * Lazy builder callback for rendering toolbar links.
   *
   * @return array
   *   A renderable array as expected by the renderer service.
   */
  public function renderToolbarLinks() {
    $build = $this->innerService
      ->renderToolbarLinks();
    if ($this->account
      ->getAccount()
      ->isAuthenticated()) {
      $url =& $build['#links']['logout']['url'];
      $current = \Drupal::service('path.current')
        ->getPath();

      // Add current param to be able to evaluate previous page.
      $url
        ->setOptions([
        'query' => [
          'current' => $current,
        ],
      ]);
    }
    return $build;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LoginDestinationToolbarLinkBuilder::$innerService protected property The decorated service.
LoginDestinationToolbarLinkBuilder::renderToolbarLinks public function Lazy builder callback for rendering toolbar links. Overrides ToolbarLinkBuilder::renderToolbarLinks
LoginDestinationToolbarLinkBuilder::__call public function Pass any undefined method calls onto the inner service.
LoginDestinationToolbarLinkBuilder::__construct public function ToolbarHandler constructor. Overrides ToolbarLinkBuilder::__construct
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
ToolbarLinkBuilder::$account protected property The current user.
ToolbarLinkBuilder::renderDisplayName public function Lazy builder callback for rendering the username.
ToolbarLinkBuilder::trustedCallbacks public static function Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface::trustedCallbacks
TrustedCallbackInterface::THROW_EXCEPTION constant Untrusted callbacks throw exceptions.
TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION constant Untrusted callbacks trigger silenced E_USER_DEPRECATION errors.
TrustedCallbackInterface::TRIGGER_WARNING constant Untrusted callbacks trigger E_USER_WARNING errors.