Problem/Motivation

On the "Status report", the five boxes in the "General System Information" are hard-coded in status-report-general-info.html.twig. This means that if a developer wants to add a box, they need to override this template. There should be an easier way.

Example use case: We are making a custom web app for a client. We want the version and other information about the app prominently displayed on the status page. We currently use hook_requirements() to add this to the "Checked" section of "Status Details". We would like something more prominent.

Proposed resolution

Refactor status-report-general-info.html.twig so that it is looping through an array of items. Setup the items in a preprocess function. This allows developers to add to this section in their own preprocess function.

Remaining tasks

Agree on how it should work. Implement.

User interface changes

None.

API changes

None, except that sections can be added via preprocess.

Data model changes

None.

Release notes snippet

Issue fork drupal-3423531

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Liam Morland created an issue. See original summary.

govind_giri_goswami made their first commit to this issue’s fork.

oo0shiny made their first commit to this issue’s fork.

I took a first shot at this since I needed it for a project. I added a add_to_general_info field. If a module adds this field to their $requirements array in hook_requirements() it will add it to the General System Information block.

$requirements['example_module'] = [
    'title' => 'Example Module',
    'value' => t(' Example Module description.'),
    'severity' => REQUIREMENT_OK,
    'add_to_general_info' => TRUE,
  ];

I updated core/modules/system/src/Element/StatusReportPage.php and core/themes/claro/templates/status-report-general-info.html.twig to add any modules with the add_to_general_info flag into the section.

Also, adding new blocks to the section broke the flex layout, so I reworked it using grid so that it would have correct spacing between all of the blocks, regardless of how many were in the section.

Patch: https://git.drupalcode.org/project/drupal/-/merge_requests/9610.patch

kumudb’s picture

While checkout to this current branch, getting this below error, Drupal version 11.x

The website encountered an unexpected error. Try again later.

Error: Class "Drupal\system\Element\RenderElementBase" not found in include() (line 14 of core/modules/system/src/Element/StatusReportPage.php).
Composer\Autoload\{closure}() (Line: 427)
Composer\Autoload\ClassLoader->loadClass()
class_exists() (Line: 96)
Drupal\Component\Plugin\Factory\DefaultFactory::getPluginClass() (Line: 17)
Drupal\Core\Plugin\Factory\ContainerFactory->createInstance() (Line: 83)
Drupal\Component\Plugin\PluginManagerBase->createInstance() (Line: 166)
Drupal\Core\Render\ElementInfoManager->createInstance() (Line: 135)
Drupal\Core\Render\ElementInfoManager->buildInfo() (Line: 91)
Drupal\Core\Render\ElementInfoManager->getInfo() (Line: 356)
Drupal\Core\Render\Renderer->doRender() (Line: 240)
Drupal\Core\Render\Renderer->render() (Line: 238)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 231)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare() (Line: 128)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse() (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
call_user_func() (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 186)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 60)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 736)
Drupal\Core\DrupalKernel->handle() (Line: 19)
oo0shiny’s picture

I've updated the code to reflect the change in D11 that was causing the error. I think this should be working now.

oo0shiny’s picture

Created a version for 10.3 as well.

oo0shiny’s picture

StatusFileSize
new4.3 KB

Here's the 10.3.x patch for anyone who needs it.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

jigarius’s picture

I was facing a similar problem which made me realized that there are certain things in the General Info that are not dynamic. It would be good to make them dynamic so that other modules can introduce their own cards for the top of the Status Report.

1. status-report-general-info.html.twig: Instead of hard-coding elements like #drupal, #cron, #webserver, etc, consider having a "general_info" or "cards" that can contain multiple sub-elements.
2. status_report_card: Use hook_theme() to define a "system_report_card" (or "status-report-general-info-item") that will contain: title, description, icon, footer.
3. Lastly, each entry introduced by hook_requirement() could contain a flag to decide whether it's a card, e.g. card = true or highlight = true similar to what this issue attempts to do. The "weight" of the cards decide the order of appearance.

Thinking aloud, doesn't core make use of SDCs? It would be good to have a SDC for status_report_card. Those cards are cool and making them reusable will open the doors for some cool reporting features.