Basic Site Info

Created on 2 February 2025, 2 months ago

As a long time user of Drupal I think a lot of people expect certain info available such as:

  $site_config = \Drupal::config('system.site');
  $data['site_info'] = [
    'name' => $site_config->get('name'),
    'slogan' => $site_config->get('slogan'),
    'mail' => $site_config->get('mail'),
  ];

For us this works super well as then can we add the name, slogan and email as defaults within the Nuxt theme.

Feature request
Status

Active

Version

1.0

Component

Code

Created by

🇺🇸United States glynster

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

Merge Requests

Comments & Activities

  • Issue created by @glynster
  • 🇦🇹Austria fago Vienna

    While I can see the use-case for needing this information, I don't think it makes sense to ship this information on every ce-api page response, since it would grow all the responses, while the information is usually only needed once. Thus, it seems to be better solved with a dedicated endpoint + a separate request to fetch it from nuxt. When done so, we shuold be able to leverage caching in nuxt such that the request is done only once in the server instance, and cached then.

    On how to providing the information, I don't think there is a pre-existing API for it. So it makes sense to add it.

    However, when adding it: The question becomes, what exactly shall we add? It seems very use-case specific what shall be added, there are definitely more config-settings that one might want to use in the frontend, for example a configured google analytics key.

    Thus, I feel like we could build a solution for exposing any kind of config as "Site-info" and make it configurable, e.g. by specifying the keys you want:
    system.site:name
    system.site:slogan
    system.site:mail

    and just output a data structure like
    { system.site : {
    name: "..",
    slogan: "..",
    mail: "..."
    }}

    and make the result a public API, e.g. at /lupus/site-info

    I guess, that would make sense to provide as a new optional module, Lupus Decoupled Site Info ?

  • 🇺🇸United States glynster

    Sounds like a perfect idea to me, and as you say it can be added to depending on your needs. Totally agree on the lookup once and cached on Nuxt end. We can achieve this via useState

  • First commit to issue fork.
  • Merge request !1213504890: New module Lupus Decoupled Site Info. → (Merged) created by useernamee
  • 🇸🇮Slovenia useernamee Ljubljana

    I created the Lupus Decoupled Site Info module and added some initial configuration.

  • 🇺🇸United States glynster

    @useernamee great news. This will be very helpful. My only suggesting is the API route /api/lupus/site-info changes to /api/site-info seems more appropriate to me. Great job!

  • 🇦🇹Austria fago Vienna

    that seems pretty good already, thank you!

    A few remarks:
    - please check the MR comment
    - I am not sure about the /api/lupus prefix also, what about just /api/site-info or /lupus-site-info ?
    - We need some configuration form or README that documents how to use it
    - We need some basic test coverage before merge!

  • 🇸🇮Slovenia useernamee Ljubljana

    > I am not sure about the /api/lupus prefix also, what about just /api/site-info or /lupus-site-info ?

    I went with the /api/site-info but this is also a limitation of the Rest resource which I picked for the task, since it would seem nicer to have a resource at the endpoint of /site-info, for uniformity.

  • 🇦🇹Austria fago Vienna

    thank you! that looks pretty good now. I've added one remark with this missing value though, please check MR review.

  • 🇸🇮Slovenia useernamee Ljubljana

    I removed the missing config option and added a watchdog error for that case instead:

    {"system.site":{"name":"Drush Site-Install","slogan":"lupus.digital Publishing","mail":"admin@example.com","missing":null},"missing":{"missing":null}}
    
  • 🇦🇹Austria fago Vienna

    thank you! Reviewed it and edited a bit. Seems good to go now!

    However, I did not test it yet. So it still needs a manual test before it's ready for merge!

  • 🇦🇹Austria arthur_lorenz Vienna

    Test failed, cache is not being invalidated after config changes.

    To reproduce:

    • Install lupus_decoupled_site_info module
    • Go to /api/site-info -> Info is correct
    • Go to /admin/config/system/site-information and update the slogan
    • Go to /api/site-info -> Info is outdated
  • 🇸🇮Slovenia useernamee Ljubljana

    Thank you @arthur. I wasn't paying attention to caching.

    - Added cacheable dependencies to the response.
    - Cache is tested.

  • 🇦🇹Austria arthur_lorenz Vienna

    Great, thank you :)

    Tested it locally -> RTBC ✅

  • Pipeline finished with Skipped
    11 days ago
    #461685
  • 🇦🇹Austria fago Vienna

    Thank you! Merged!

Production build 0.71.5 2024