diff --git a/cache_pilot.install b/cache_pilot.install index efefca202abce441021737452fb9911c7b64b0fc..5a09a21de837fade61cfe618987e5e5dc7b36cf9 100644 --- a/cache_pilot.install +++ b/cache_pilot.install @@ -4,6 +4,7 @@ declare(strict_types=1); use Drupal\cache_pilot\Cache\ApcuCache; use Drupal\cache_pilot\Client\Client; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\StringTranslation\TranslatableMarkup; /** @@ -15,11 +16,15 @@ function cache_pilot_requirements(string $phase): array { if ($phase === 'runtime') { $fast_cgi_client = \Drupal::service(Client::class); $is_connected = $fast_cgi_client->isConnected(); + $connection_dsn =\Drupal::configFactory()->get('cache_pilot.settings')->get('connection_dsn'); $requirements['cache_pilot_connection'] = [ - 'title' => new TranslatableMarkup('Cache Pilot connection'), - 'description' => $is_connected ? new TranslatableMarkup('Connected') : new TranslatableMarkup('Not connected'), - 'severity' => $is_connected ? REQUIREMENT_OK : REQUIREMENT_WARNING, + 'title' => new TranslatableMarkup('Cache Pilot'), + 'value' => $is_connected ? new TranslatableMarkup('Connected') : new TranslatableMarkup('Not connected'), + 'description' => $connection_dsn, + 'severity' => $is_connected + ? \REQUIREMENT_OK + : ($connection_dsn === NULL ? \REQUIREMENT_WARNING : \REQUIREMENT_ERROR), ]; } diff --git a/cache_pilot.links.task.yml b/cache_pilot.links.task.yml index 108cdc77905f0bdb27b80496f7e5044eedaf9984..bf50ed7267b2b505d325972f6fd58b27dd375f54 100644 --- a/cache_pilot.links.task.yml +++ b/cache_pilot.links.task.yml @@ -2,3 +2,15 @@ cache_pilot.settings: title: 'Cache Pilot settings' route_name: cache_pilot.settings base_route: system.performance_settings + +cache_pilot.dashboard.apcu: + title: 'APCu' + route_name: cache_pilot.dashboard + base_route: cache_pilot.dashboard + +cache_pilot.dashboard.opcache: + title: 'OPcache' + route_name: cache_pilot.dashboard.statistics + base_route: cache_pilot.dashboard + route_parameters: + cache_type: 'opcache' diff --git a/cache_pilot.module b/cache_pilot.module index ded4d0a7e51a1326c8e8156b73a0c5f7f63ddf2c..6ef379834f0d35a65203b2020183362bcd7fe17f 100644 --- a/cache_pilot.module +++ b/cache_pilot.module @@ -19,12 +19,6 @@ function cache_pilot_cache_flush(): void { */ function cache_pilot_theme(): array { return [ - 'cache_pilot_dashboard' => [ - 'variables' => [ - 'apcu' => [], - 'opcache' => [], - ], - ], 'cache_pilot_apcu_statistics' => [ 'variables' => [ 'statistics' => [], diff --git a/cache_pilot.routing.yml b/cache_pilot.routing.yml index 1b6acc582e8e96657d246d0245020e9c86f3173b..0eb2c83c042bbbe67cd01091a89411159b79b01e 100644 --- a/cache_pilot.routing.yml +++ b/cache_pilot.routing.yml @@ -11,7 +11,17 @@ cache_pilot.dashboard: path: '/admin/reports/cache-pilot' methods: ['GET'] defaults: - _controller: '\Drupal\cache_pilot\Controller\DashboardController' - _title: 'Cache Pilot dashboard' + _controller: \Drupal\cache_pilot\Controller\DashboardController + _title_callback: \Drupal\cache_pilot\Controller\DashboardController::pageTitle + cache_type: 'apcu' requirements: _permission: 'cache_pilot.administer' + +cache_pilot.dashboard.statistics: + path: '/admin/reports/cache-pilot/{cache_type}' + methods: ['GET'] + defaults: + _controller: \Drupal\cache_pilot\Controller\DashboardController + _title_callback: \Drupal\cache_pilot\Controller\DashboardController::pageTitle + requirements: + _permission: 'cache_pilot.administer' \ No newline at end of file diff --git a/css/cache-pilot-fragmentation-bar.css b/css/cache-pilot-fragmentation-bar.css index cd3cd837c456ce756173c002cba9ecff51344487..4b569591eb1b77b6da191c4d1e9f5d1a15e61d89 100644 --- a/css/cache-pilot-fragmentation-bar.css +++ b/css/cache-pilot-fragmentation-bar.css @@ -2,9 +2,10 @@ display: flex; flex-direction: column; gap: var(--space-s, 0.5rem); + margin: 0; } -.cache-pilot-fragmentation-bar__progress { +.cache-pilot-fragmentation-bar__indicator { border-radius: var(--progress-bar-default-size-radius, 1.5rem); overflow: hidden; display: flex; diff --git a/src/Controller/DashboardController.php b/src/Controller/DashboardController.php index 6c4451f1c29db9f1e9658ef6aedd2deebde6cb41..e5f81eb237fec684d2219823632e4d8e41831699 100644 --- a/src/Controller/DashboardController.php +++ b/src/Controller/DashboardController.php @@ -34,36 +34,52 @@ final readonly class DashboardController implements ContainerInjectionInterface ) {} /** - * Returns the cache statistics dashboard. + * Builds a page title. + * + * @param string $cache_type + * The requested cache type. + * + * @return \Drupal\Core\StringTranslation\TranslatableMarkup + * The page title. */ - public function __invoke(): array { - $build = [ - '#theme' => 'cache_pilot_dashboard', - ]; - - $apcu_statistics = $this->apcu->statistics(); - if ($apcu_statistics) { - $build['#apcu'] = [ - '#theme' => 'cache_pilot_apcu_statistics', - '#statistics' => $apcu_statistics, - ]; - } + public function pageTitle(string $cache_type): TranslatableMarkup { + return match ($cache_type) { + 'apcu' => new TranslatableMarkup('APCu statistics'), + 'opcache' => new TranslatableMarkup('Zend OPcache statistics'), + default => new TranslatableMarkup('Cache Pilot dashboard'), + }; + } - $opcache_statistics = $this->opcache->statistics(); - if ($opcache_statistics) { - $build['#opcache'] = [ - '#theme' => 'cache_pilot_opcache_statistics', - '#statistics' => $opcache_statistics, - ]; - } + /** + * Returns the cache statistics dashboard. + * + * @param string $cache_type + * The requested cache type. + * + * @return array + * The page contents. + */ + public function __invoke(string $cache_type): array { + $statistics = match ($cache_type) { + 'apcu' => $this->apcu->statistics(), + 'opcache' => $this->opcache->statistics(), + default => NULL, + }; - if (!isset($build['#apcu']) && !isset($build['#opcache'])) { + if (!$statistics) { return [ '#markup' => new TranslatableMarkup('Looks like there is a problem with the connection to FastCGI.'), ]; } - return $build; + return [ + '#theme' => match($cache_type) { + 'apcu' => 'cache_pilot_apcu_statistics', + 'opcache' => 'cache_pilot_opcache_statistics', + default => throw new \InvalidArgumentException(\sprintf('Unexpected cache type %s', $cache_type)), + }, + '#statistics' => $statistics, + ]; } } diff --git a/src/Form/SettingsForm.php b/src/Form/SettingsForm.php index a8f2a40ec54bbf22146f353d85bbb874e3818a63..98b99a77e3f02486bf26221fda08f2b3c83cbc6e 100644 --- a/src/Form/SettingsForm.php +++ b/src/Form/SettingsForm.php @@ -89,8 +89,7 @@ final class SettingsForm extends ConfigFormBase { '#type' => 'textfield', '#title' => new TranslatableMarkup('Connection DSN'), '#description' => new TranslatableMarkup('The connection string in the format <code>tcp://[host]:[port]</code> for TCP or <code>unix://[socket_path]</code> for a Unix socket.'), - '#default_value' => $this->config('cache_pilot.settings')->get('connection_dsn'), - '#placeholder' => 'tcp://127.0.0.1:9000 or unix:///var/run/php/php-fpm.sock', + '#config_target' => 'cache_pilot.settings:connection_dsn', ]; } @@ -140,7 +139,7 @@ final class SettingsForm extends ConfigFormBase { } /** - * Attempts to clear Zend OPCache. + * Attempts to clear Zend OPcache. */ public function clearOpcache(): void { $this->opcacheCache->clear(); @@ -168,13 +167,6 @@ final class SettingsForm extends ConfigFormBase { } } - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state): void { - $this->config('cache_pilot.settings')->set('connection_dsn', $form_state->getValue('connection_dsn'))->save(); - } - /** * {@inheritdoc} */ diff --git a/src/Hook/Theme/PreprocessCachePilotOpcacheStatistics.php b/src/Hook/Theme/PreprocessCachePilotOpcacheStatistics.php index 0684050093b71599cc220907dcffe5272ca17260..4d06638f1915594e69417873db9fa85c46132ae5 100644 --- a/src/Hook/Theme/PreprocessCachePilotOpcacheStatistics.php +++ b/src/Hook/Theme/PreprocessCachePilotOpcacheStatistics.php @@ -160,7 +160,7 @@ final readonly class PreprocessCachePilotOpcacheStatistics { } /** - * Prepares OPCache stats information. + * Prepares OPcache stats information. */ private function prepareOpcacheStatsInformation(array &$variables): void { $statistics = $variables['statistics']; diff --git a/templates/cache-pilot-dashboard.html.twig b/templates/cache-pilot-dashboard.html.twig deleted file mode 100644 index 7fc585a734e2f03e60e43a117acc3bf115331b02..0000000000000000000000000000000000000000 --- a/templates/cache-pilot-dashboard.html.twig +++ /dev/null @@ -1,29 +0,0 @@ -{# -/** - * @file - * Default theme implementation to display Cache Pilot dashboard items. - * - * Available variables: - * - attributes: The main wrapper element attributes. - * - apcu: (optional) The APCu statistics pane. - * - opcache: (optional) The Zend OPCache statistics pane. - */ -#} -<div{{ attributes.addClass('cache-pilot-dashboard') }}> - {% if apcu %} - {{ _self.section('APCu statistics'|t, apcu) }} - {% endif %} - - {% if opcache %} - {{ _self.section('Zend OPCache statistics'|t, opcache) }} - {% endif %} -</div> - -{% macro section(title, content) %} - <div class="cache-pilot-dashboard__section"> - <h2 class="cache-pilot-dashboard__header">{{ title }}</h2> - <div class="cache-pilot-dashboard__pane"> - {{ content }} - </div> - </div> -{% endmacro %} diff --git a/templates/cache-pilot-fragmentation-bar.html.twig b/templates/cache-pilot-fragmentation-bar.html.twig index 13f8cb3a058c3507cf54c9da3d41d397cbfaba28..22f5786dce93633fc05beaaa2d1801ce47f6af68 100644 --- a/templates/cache-pilot-fragmentation-bar.html.twig +++ b/templates/cache-pilot-fragmentation-bar.html.twig @@ -13,8 +13,8 @@ */ #} {{ attach_library('cache_pilot/fragmentation-bar') }} -<div{{ attributes.addClass('cache-pilot-fragmentation-bar') }}> - <div class="cache-pilot-fragmentation-bar__progress"> +<figure{{ attributes.addClass('cache-pilot-fragmentation-bar') }}> + <div class="cache-pilot-fragmentation-bar__indicator"> {% for fragment in fragments %} <div class="cache-pilot-fragmentation-bar__fragment" style="--fragment-background-color: {{ fragment.color }}; --fragment-percentage: {{ fragment.percentage }}%;"> @@ -34,4 +34,4 @@ </div> {% endfor %} </div> -</div> +</figure> diff --git a/templates/cache-pilot-opcache-statistics.html.twig b/templates/cache-pilot-opcache-statistics.html.twig index c4771fc3256aced080bd9b2b8ec189ba31070c57..032c81ca2974db0eaff29abf63fbe74207a2307b 100644 --- a/templates/cache-pilot-opcache-statistics.html.twig +++ b/templates/cache-pilot-opcache-statistics.html.twig @@ -8,7 +8,7 @@ * - statistics: An array with raw data from opcache_get_status(). * - general: The general information. * - strings: The information about strings cache. - * - opcache_stats: The OPCache statistics information. + * - opcache_stats: The OPcache statistics information. */ #} <div{{ attributes.addClass('cache-pilot-opcache-statistics') }}>