Add "system.site" service and SiteProperty plugins to improve the Status Report page and provide structured data about the site.

Created on 11 May 2024, about 1 month ago
Updated 14 May 2024, about 1 month ago

Problem/Motivation

Need a central location for loading information about the site.

This extends ✨ Add "Main URL" to "Basic site settings" and "Status Report" page. Needs review

See diff: https://git.drupalcode.org/issue/drupal-3446677/-/compare/11.x...3446677...

Example implementation

The Status Report page in this branch is updated to show this information:

    $site_name = \Drupal::service('system.site')->getName();
    $site_slogan = \Drupal::service('system.site')->getSlogan();

    $current_url = $this->siteManager->getCurrentUrl();
    $current_url_description = '';

    $main_url = $this->siteManager->getMainUrl();
    $main_url_description = t('The <em>Main URL</em> is where the live production site is hosted.');
    if (empty($main_url)) {
      $main_url = $current_url;
    }

    if (!$this->siteManager->isMain()) {
      $current_url_description = t('This site is a replica of <a href=":main_url" target="_blank">:main_url</a>.', [
        ':main_url' => $main_url,
      ]);
    }

SiteProperty Plugins

The individual items that are currently handled by "hook_requirements" can now be provided by "SiteProperty" plugins.

For example: Last Cron:

class DrupalCronLast extends SitePropertyPluginBase {
  public function value() {
    return \Drupal::state()->get('system.cron_last');
  }

  public function view() {
    return [
      '#type' => 'item',
      '#title' => t('Last cron run'),
      '#markup' => \Drupal::service('date.formatter')->format($this->value()),
      '#description' => t(":interval ago", [
        ':interval' => \Drupal::service('date.formatter')->formatInterval(time() - $this->value()),
      ]),
      '#description_display' => 'after'
    ];
  }
}

Screenshots

✨ Feature request
Status

Active

Version

11.0 πŸ”₯

Component
SystemΒ  β†’

Last updated 2 days ago

No maintainer
Created by

πŸ‡ΊπŸ‡ΈUnited States Jon Pugh Newburgh, NY

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

Comments & Activities

Production build 0.69.0 2024