You are here

class SocialLanguageMetadataBubblingUrlGenerator in Open Social 8.7

Same name and namespace in other branches
  1. 8.9 modules/custom/social_language/src/SocialLanguageMetadataBubblingUrlGenerator.php \Drupal\social_language\SocialLanguageMetadataBubblingUrlGenerator
  2. 8 modules/custom/social_language/src/SocialLanguageMetadataBubblingUrlGenerator.php \Drupal\social_language\SocialLanguageMetadataBubblingUrlGenerator
  3. 8.2 modules/custom/social_language/src/SocialLanguageMetadataBubblingUrlGenerator.php \Drupal\social_language\SocialLanguageMetadataBubblingUrlGenerator
  4. 8.3 modules/custom/social_language/src/SocialLanguageMetadataBubblingUrlGenerator.php \Drupal\social_language\SocialLanguageMetadataBubblingUrlGenerator
  5. 8.4 modules/custom/social_language/src/SocialLanguageMetadataBubblingUrlGenerator.php \Drupal\social_language\SocialLanguageMetadataBubblingUrlGenerator
  6. 8.5 modules/custom/social_language/src/SocialLanguageMetadataBubblingUrlGenerator.php \Drupal\social_language\SocialLanguageMetadataBubblingUrlGenerator
  7. 8.6 modules/custom/social_language/src/SocialLanguageMetadataBubblingUrlGenerator.php \Drupal\social_language\SocialLanguageMetadataBubblingUrlGenerator
  8. 8.8 modules/custom/social_language/src/SocialLanguageMetadataBubblingUrlGenerator.php \Drupal\social_language\SocialLanguageMetadataBubblingUrlGenerator
  9. 10.3.x modules/custom/social_language/src/SocialLanguageMetadataBubblingUrlGenerator.php \Drupal\social_language\SocialLanguageMetadataBubblingUrlGenerator
  10. 10.0.x modules/custom/social_language/src/SocialLanguageMetadataBubblingUrlGenerator.php \Drupal\social_language\SocialLanguageMetadataBubblingUrlGenerator
  11. 10.1.x modules/custom/social_language/src/SocialLanguageMetadataBubblingUrlGenerator.php \Drupal\social_language\SocialLanguageMetadataBubblingUrlGenerator
  12. 10.2.x modules/custom/social_language/src/SocialLanguageMetadataBubblingUrlGenerator.php \Drupal\social_language\SocialLanguageMetadataBubblingUrlGenerator

Class SocialLanguageMetadataBubblingUrlGenerator.

@package Drupal\social_language

Hierarchy

Expanded class hierarchy of SocialLanguageMetadataBubblingUrlGenerator

File

modules/custom/social_language/src/SocialLanguageMetadataBubblingUrlGenerator.php, line 16

Namespace

Drupal\social_language
View source
class SocialLanguageMetadataBubblingUrlGenerator extends MetadataBubblingUrlGenerator {

  /**
   * The language manager.
   *
   * @var \Drupal\Core\Language\LanguageManagerInterface
   */
  protected $languageManager;

  /**
   * Constructs a new bubbling URL generator service.
   *
   * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator
   *   The non-bubbling URL generator.
   * @param \Drupal\Core\Render\RendererInterface $renderer
   *   The renderer.
   * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
   *   The language manager.
   */
  public function __construct(UrlGeneratorInterface $url_generator, RendererInterface $renderer, LanguageManagerInterface $language_manager) {
    parent::__construct($url_generator, $renderer);
    $this->languageManager = $language_manager;
  }

  /**
   * {@inheritdoc}
   */
  public function generateFromRoute($name, $parameters = [], $options = [], $collect_bubbleable_metadata = FALSE) {
    if (isset($options['language']) && $options['language'] instanceof LanguageInterface) {
      $language = $this->languageManager
        ->getCurrentLanguage();
      if ($options['language']
        ->getId() != $language
        ->getId()) {
        $reset_language = TRUE;
        $unmodified_pages = [
          'content_translation_overview',
        ];
        $current_route = \Drupal::routeMatch()
          ->getRouteName();
        \Drupal::moduleHandler()
          ->alter('social_language_unmodified_pages', $unmodified_pages);
        $route_parts = explode('.', $current_route);
        foreach ($unmodified_pages as $page) {
          if (in_array($page, $route_parts)) {
            $reset_language = FALSE;
            break;
          }
        }
        if ($reset_language) {
          $options['language'] = $language;
        }
      }
    }
    return parent::generateFromRoute($name, $parameters, $options, $collect_bubbleable_metadata);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MetadataBubblingUrlGenerator::$renderer protected property The renderer.
MetadataBubblingUrlGenerator::$urlGenerator protected property The non-bubbling URL generator.
MetadataBubblingUrlGenerator::bubble protected function Bubbles the bubbleable metadata to the current render context.
MetadataBubblingUrlGenerator::generate public function Generates a URL or path for a specific route based on the given parameters.
MetadataBubblingUrlGenerator::getContext public function Gets the request context.
MetadataBubblingUrlGenerator::getPathFromRoute public function Gets the internal path (system path) for a route. Overrides UrlGeneratorInterface::getPathFromRoute
MetadataBubblingUrlGenerator::getRouteDebugMessage public function Convert a route identifier (name, content object etc) into a string usable for logging and other debug/error messages
MetadataBubblingUrlGenerator::setContext public function Sets the request context.
MetadataBubblingUrlGenerator::supports public function Whether this generator supports the supplied $name.
SocialLanguageMetadataBubblingUrlGenerator::$languageManager protected property The language manager.
SocialLanguageMetadataBubblingUrlGenerator::generateFromRoute public function Generates a URL or path for a specific route based on the given parameters. Overrides MetadataBubblingUrlGenerator::generateFromRoute
SocialLanguageMetadataBubblingUrlGenerator::__construct public function Constructs a new bubbling URL generator service. Overrides MetadataBubblingUrlGenerator::__construct