On this page
- Track your Drupal Site
- Usage
- Site State widget
- Site Status / About this Site
- Site State
- State Reason
- Site Properties
- Site Configuration & State Values
- Site History
- Site History Reports
- Site Data
- Site State
- Site Config History
- Site Fields
- Retrieving Site Entity Fields
- Site Settings
- State
- Site Reporting
- Remote Reporting
- Site Config
- Architecture
- Site Entity
- Site Definition
- Site Property
Site Module
This documentation needs work. See "Help improve this page" in the sidebar.
Site Module
Track your Drupal Site
This is the documentation for Site Module.
Any Drupal site can use it.
Usage
Site State widget
At the top right of your site is a "state" indicator. It will say "OK", "Warning", or "Error" depending on the state of your site.
To view the Site Status page, click the widget.
At the top left of the page, you will see a Drupal logo menu. (If not, click "Manage" to show the full menu.)
Hover over it to see the "About this site" link. It goes to the same page as the Site State Widget.
Site Status / About this Site
The Site Status page displays the state of your site, the reasons for that state, properties and configuration.
This information is saved over time in Site Reports. Press the Save Report button saves this information as a snapshot, viewable on the History tab.
Site State
Site State is a single value that represents the overall state of your Drupal site OK, WARNING, or ERROR.
The factors that affect state are configurable and other modules can provide plugins to affect state.
By default, State is determined by Drupal Core Status Report.
Site Audit module is also supported.
State Reason
Site State Reason is a renderable array of information explaining why the site is in the state it is in.
This information is saved in site reports for later review.
Site Properties
Site Properties are small bits of information that are attached to your site reports, generated by SiteReport plugins.
Examples include PHP & Drupal versions & Host Provider. See the SitePropery plugins folder to view all current property plugins.
On the Site Status page, the information is generated in real time. When a Site Report is saved, they are stored, attached to the Site Entity Revision.
Site Configuration & State Values
Site Reports will store the selected configuration and state values from your site.
Visit Settings to configure what config & state items to save in Site Reports.
Site History
The Site History page displays the "Revisions" of your Site Entity, known here as "Site Reports".
Each site report stores Site State, Reasons, and other properties, along with a log message describing how the report got created.
To view a Site Report in detail, click the Site Title on the History page.
Site History Reports
Each entry in the Site History page is a snapshot in time.
Technically, they are SiteEntity Revisions, but we call them Reports.
The fields shown on a Site Report are the same kind of data as on the Site Status page, but are saved in the report revision.
This allows you to go back in time and review the changes to these properties.
Site Data
The Site Data field is a serialized dump of arbitrary data, which includes the Drupal configuration and state values chosen in Site Settings
Site State
Just like on the Site Status page, site reports can display the state and reason at the time the report was filed.
Site Config History
If the "Save on Config Changes" box is checked in Site Settings, then you will get a new report saved everytime a Drupal config object is saved.
Additionally, the changes that took place are saved for comparison later.
Site Fields
Since the SiteEntity is an entity, it is fieldable.
Click "About this site" > "Fields" to configure this site's fields.
In this screenshot, there is an example field called "Welcome Message".
This makes it possible to store bits of information as fields attached to the site, so you don't have to create an additional entity or node type.
With the right permissions, customers could be given edit access to make small changes to their site using SiteEntity fields.
Retrieving Site Entity Fields
Loading the Site Entity to get it's fields is almost the same as any other entity.
Instead of loading it by ID, you can just get the site entity for the current site with SiteEntity::getSelf()
For example, to load a field and present a message, you can use this code.
<?php
use \Drupal\site\Entity\SiteEntity;
// Load the entity just like any other, but with loadSelf().
/** @var SiteEntity $site_entity */
$site_entity = SiteEntity::loadSelf();
// Load the field value just like any field.
$welcome_message = $site_entity->get('field_welcome_message')->value;
// Do something with the value.
\Drupal::messenger()->addStatus($welcome_message);
Site Settings
The Site Settings page controls how Site Status and Reports are handled.
State
The factors that affect Site State can be configured. Currently supported factors are Drupal Core Status report page, and [Site Audit](https://drupal. org/project/site_audit) module.
Choose the factors that make the most sense for your site.
Site Reporting
Site reports can be generated every time config changes, on cron, or manually.
Remote Reporting
Site reports can also be sent to remote destinations. Select "Send on Save" or set an interval to "Send site data".
Enter the URLs of any REST endpoints you wish to send the site entity to. See Site Manager.
Site Config
Select the Drupal configuration and state values to save in your site reports.
Architecture
The Site Module takes advantage of Drupal's Entity and Plugin APIs to create a system for viewing and tracking information about your site.
Site Entity
A Site Entity is a Content entity with the UUID being the UUID of your site.
That means that every site gets a single Site Entity.
Site Entities are Revisionable, which acts as a historical record. The module features a "Save Report" button and cronjob that can save Site Entity Revisions. (a.k.a. "Site Reports").
Site Entities can be saved on Config changes, storing a record of before and after values.
Site Entities are fieldable which means you can add fields to your Drupal site and Manage Display and Form just like any other Drupal site.
See SiteEntity Class.
Site Definition
A "Site Definition" is a Config Entity that has special methods for loading realtime information into the SiteDefinition class.
Each site gets a single SiteDefinition config item called site. site_definition.self. The config is managed on the Site Settings page.
The SiteDefinition entity represents real-time values for state and properties.
To save these properties for use later, SiteDefinition::saveEntity() is used to create and store a new revision of the Site's SiteEntity.
See SiteDefinition Class.
Site Property
The SiteProperty Plugin type is a simple class that defines a data point about the site.
This single class has methods for determining value both for the SiteDefinition entity and the SiteEntity content entity.
Properties can define first class Entity fields so that the value gets saved for later use.
See Plugins\SiteProperty folder in the Site module for examples.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion