Provide option to add External Site URL

Created on 8 June 2023, about 1 year ago
Updated 10 June 2023, about 1 year ago

Problem/Motivation

When a Drupal CMS provides subsites (pulti-site, sub-site, micro-site, ...) solution that allows a group of affiliated sites to run from one Drupal installation and a single shared database and allows to publish/share content and configurations across a group of sites such as via Micro Sites, frequently, each subsite is a sub-organizational unit of a larger institution/organization. However, not all sub-organizational units have a valid reason to migrate to the Drupal CMS (such as Library websites at Universities that use CMS tailored for a specific purpose, such as DSpace for hosting research-related data). Instead of creating a custom field on Nodes, Taxonomy Terms, ..., that provides an option to link to "external" sub-organizational units that do not use the Drupal CMS, a Site entity could provide an additional "External Site Link" field that would be used the primary canonical URL for the Site. This way creating a link to a Site entity, the URL would take the site visitors the respective external site link.

Proposed resolution

Add a field to the Site entity for configuring an external site link.

Remaining tasks

  1. Create a patch for adding a new base field for external site link, such as field_site_link.
  2. Patch processOutbound function in src/PathProcessor/SiteFrontPageProcessor.php such as from:
  /**
   * {@inheritdoc}
   */
  public function processOutbound($path, &$options = [], Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
    if (preg_match('/^\/site\/([0-9]+)$/i', $path, $matches)) {
      $site_id = $matches['1'];
      $site = $this->negotiator->loadById($site_id);
      $active_site = $this->negotiator->getActiveSite();
      if ($site instanceof SiteInterface && $active_site && $active_site->id() == $site->id()) {
        $path = '/';
      }
    }
    return $path;
  }

}

to:

  /**
   * {@inheritdoc}
   */
  public function processOutbound($path, &$options = [], Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
    if (preg_match('/^\/site\/([0-9]+)$/i', $path, $matches)) {
      $site_id = $matches['1'];
      $site = $this->negotiator->loadById($site_id);
      $active_site = $this->negotiator->getActiveSite();
      if ($site instanceof SiteInterface && $active_site && $active_site->id() == $site->id()) {
        $path = '/';
      } else {
        $site_bundle_fields = \Drupal::service('entity_field.manager')->getFieldDefinitions($site->getEntityTypeId(), $site->bundle());
        if (isset($site_bundle_fields['field_site_link'])) {
          $site_url = $site->get('field_site_link');
          if ($site_url) {
            $parsedUrl = parse_url($site_url->first()->getUrl()->toString());
            $options['base_url'] = rtrim($parsedUrl["scheme"].'://'.$parsedUrl["host"], '/');
            $path = isset($parsedUrl["path"]) ? $parsedUrl["path"] : '/';
          }
        } else {
          $options['base_url'] = $site->getSitePath();
          $path = '/';
        }
      }
    }
    return $path;
  }

}

User interface changes

New Site entity base field for the external site link that can be configured when creating a Site entity.

API changes

New Site entity base field for the external site link.

Data model changes

Add schema for the new Site entity base field for the external site link.

✨ Feature request
Status

Needs work

Version

1.0

Component

Code

Created by

πŸ‡ΈπŸ‡¦Saudi Arabia martins.bruvelis Thuwal

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

Comments & Activities

  • Issue created by @martins.bruvelis
  • πŸ‡ΈπŸ‡¦Saudi Arabia martins.bruvelis Thuwal
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.3 & MariaDB 10.3.22
    last update about 1 year ago
    PHPLint Failed
  • @martinsbruvelis opened merge request.
  • Status changed to Needs work about 1 year ago
  • πŸ‡ΈπŸ‡¦Saudi Arabia martins.bruvelis Thuwal
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.3 & MariaDB 10.3.22
    last update about 1 year ago
    3 pass
  • πŸ‡«πŸ‡·France flocondetoile Lyon

    I don't undestand why you need an external link field. If you have an external site of a suborganisation, then why create a micro site for this external site ? this seems obscure to me and sounds like a very specific use case.

  • πŸ‡«πŸ‡·France flocondetoile Lyon

    > sounds like a very specific use case.

    based on a custom field added on the micro site entity ^^

    And in this case this should be "fixed" using a custom SiteFrontPageProcessor which overrides the native SiteFrontPageProcessor.

  • πŸ‡ΈπŸ‡¦Saudi Arabia martins.bruvelis Thuwal

    If you have an external site of a suborganisation, then why create a micro site for this external site?

    Universities, Societies, and Government institutions, etc., typically have tens to hundreds of various departments (sub-organizational units) responsible for specific areas of business functions or representing various geographic office locations.

    > sounds like a very specific use case.
    It is more common than it might seem. For example, 71% of the top 100 Universities use Drupal. In such cases, each "Micro Site" can represent not only a publicly hosted website but also an affiliation. It is essential to provide navigational links to respective affiliations.

    Most medium to large organizations have physical offices across various local or global regions. Each location typically represents a branch of a larger organization. Then news, events, people profiles, pages, etc. have a clear content grouping with one primary Micro Site and with one or more secondary affiliated Micro Sites.

    Currently, Micro Site allows publishing and linking content (Nodes) only to such affiliations that use the Drupal CMS with the Micro Site module and leaving all other non-Drupal websites from the same institution/organization inaccessible from the Drupal CMS with the Micro Site.

    As such, adding the option to provide a link to non-Drupal CMS website for a Micro Site entity would address one of the key reasons why organizations opt for a multi-site solution, without enforcing all of the existing organization websites to migrate to the Druplal CMS and not requiring some other solution such as manual linking to non-Drupal CMS related websites from the same ogranization.

  • πŸ‡ΈπŸ‡¦Saudi Arabia martins.bruvelis Thuwal

    Comment #5 ✨ Provide option to add External Site URL Needs work

    Another simpler way to look at a Micro Site entity is by comparing it to core Drupal Link Fields that provide "Allowed link type" options:

    • Internal links only
    • External links only
    • Both internal and external links

    Currently, Micro Site only provides the Internal links only option (i.e., publish and link to Micro Site entities that are hosted on Drupal CMS) and excludes the ability to provide Both internal and external links (i.e., link to Micro Site entities that are not hosted on Drupal CMS). From the business logic, to avoid accidentally publishing content primarily on a Micro Site entity that links to a non-Drupal website, it would be necessary to exclude the non-Drupal website Micro Site entities from autocompletion of the primary "site_id" field.

  • πŸ‡«πŸ‡·France flocondetoile Lyon

    > to avoid accidentally publishing content primarily on a Micro Site entity that links to a non-Drupal website

    But the thing I don't understand is why create a micro site for an External Site, as the external site is external and lives elsewhere than on the Drupal hosting all the micro sites. Addind a link in a menu towards this external site doesn't do the job ?

    If you create a micro site on the Drupal for an "external site" means you want host this site (with its URL) on the Drupal, and publish some content or anything relatid to this micro site

  • πŸ‡ΈπŸ‡¦Saudi Arabia martins.bruvelis Thuwal

    > Comment #9 ✨ Provide option to add External Site URL Needs work
    >

    Addind a link in a menu towards this external site doesn't do the job ?

    Indeed, adding extra links to non-Drupal sites doesn't do the job. Why do organizations choose to have multiple sites instead of having a single website?

    • Out of 23 related department/organiztaional unit mentions on https://profiles.stanford.edu/jelena-vuckovic profile page, only six have added links to the respective website front pages. Why has it been so hard to add links to the related websites? If all related websites were part of Drupal CMS, then Micro Sites entities would provide an easy and consistent UX for and related sites.
    • Website content items may relate to Drupal CMS and non-Drupal CMS sites hosted by the same organization. The sites typically represent departments or specific business functions (e.g., administrative organization units), or one-off or repeating activities (e.g., a website for a yearly conference or one-off workshop). How can such relationships be managed in a consistent standard approach?
    • For example, if an event (created as a dedicated Node bundle content type for events) has affiliation to Department A (using Drupal Micro Site), Department B (using non-drupal site), and Department C (using Drupal Micro Site). How would you build a consistent UX to specify department affiliations and and each affiliated department? A simple link field does not provide a reliable, easy-to-use way to manage affiliations. Instead, there would have to be a custom entity type that creates and stores entities for each department and website within an organization. When Micro Site entities already make up the majority of websites within an organization, why create another custom entity type in addition to Micro Site?

    Profile page example, where over 50% of related department/organizational unit websites are missing links.

Production build 0.69.0 2024