Country path not managed in domain navigation block

Created on 16 April 2018, about 6 years ago
Updated 12 March 2024, 4 months ago

Hi

when I use country path on a D8 website, with "domain", I do not have the country path on the "domain navigation" block provided by "domain" module.

The code from "domain", located on DomainNavBlock.php (line 111):

foreach (\Drupal::service('entity_type.manager')->getStorage('domain')->loadMultipleSorted() as $domain) {
      // Set the URL.
      $options = ['absolute' => TRUE, 'https' => ($domain->getScheme() == 'https')];
      if ($add_path) {
        $url = Url::fromUri($domain->getUrl(), $options);
      }
      else {
        $url = Url::fromUri($domain->getPath(), $options);
      }

...
}

does not manage the country path provided in the "thirdParty" attribute.

This results the domain URL list does not display the country path.

My proposed patch: add, at the end of the "CountryPathDomain.php" the setPath() and setUrl() with a test on the $this->getThirdPartySetting('country_path', 'domain_path'):

  /**
   * {@inheritdoc}
   */
  public function setPath() {
    parent::setPath();
    if ($countryPath = $this->getThirdPartySetting('country_path', 'domain_path')) {
      $this->path .= $countryPath . '/';
    }
  }

  /**
   * {@inheritdoc}
   */
  public function setUrl() {
    $uri = \Drupal::request()->getRequestUri();
    if ($countryPath = $this->getThirdPartySetting('country_path', 'domain_path')) {
      $this->url = $this->getScheme() . $this->getHostname() . '/' . $countryPath . $uri;
    }
    else {
      $this->url = $this->getScheme() . $this->getHostname() . $uri;
    }
  }

Tested on my configuration and works fine.

My Domain configuration:

  Domain                                  Country path (country_path)                                       Enabled
  Domain                                  Domain (domain)                                                   Enabled    8.x-1.0-alpha13
  Domain                                  Domain Access (domain_access)                                     Enabled    8.x-1.0-alpha13
  Domain                                  Domain Configuration (domain_config)                              Enabled    8.x-1.0-alpha13
  Domain                                  Domain Content (domain_content)                                   Enabled    8.x-1.0-alpha13
  Domain                                  Domain Language (domain_language)                                 Enabled    8.x-1.0-alpha1
  Domain                                  Domain Source (domain_source)                                     Enabled    8.x-1.0-alpha13

Could you please review my patch, and apply it if it's good !

Thanks
Nicolas.

πŸ› Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡«πŸ‡·France nbourdial

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ͺπŸ‡ΈSpain guiu.rocafort.ferrer Barcelona

    guiu.rocafort.ferrer β†’ made their first commit to this issue’s fork.

  • πŸ‡ͺπŸ‡ΈSpain guiu.rocafort.ferrer Barcelona

    I applied patch #3, and found the fatal error is caused by an infinite loop.

    The setUrl calls getActiveDomain(), which loads the domain entity for the active domain. There was a domain_entity_load hook in the main domain, which calls the setUrl method for the loaded domain, thus creating the loop.

    The getUrl() and getPath() methods already check if the value is set, and if not, they call setUrl and setPath, so i am quite sure removing this load hook in the main domain module is safe to do. I will create a follow up issue there.

    Until this gets solved in the domain module, i added a hacky solution to stop the infinite loop from happening. In the setUrl i am checking if the function is being called from the domain_entity_load method, and in that case, it does nothing and just returns.

  • Status changed to Needs review 4 months ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update 4 months ago
    2 pass
  • πŸ‡ͺπŸ‡ΈSpain guiu.rocafort.ferrer Barcelona

    Setting the issue as needs review, so we can merge the branch and solve the issue.

  • πŸ‡ͺπŸ‡ΈSpain guiu.rocafort.ferrer Barcelona

    Changing issue Priority to Major as per issue priorities β†’

Production build 0.69.0 2024