Commit dbded3ab authored by japerry's avatar japerry
Browse files

Minor Coding Standards for the admin settings module.

parent 20aabb18
......@@ -6,6 +6,7 @@ use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Datetime\DateFormatter;
use Drupal\Core\Link;
use Drupal\Core\Messenger\MessengerTrait;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Url;
use Drupal\Component\Render\HtmlEscapedText;
......@@ -15,6 +16,7 @@ use Drupal\Component\Render\HtmlEscapedText;
class MemcacheStatisticsController extends ControllerBase {
use MessengerTrait;
use StringTranslationTrait;
/**
* Callback for the Memcache Stats page.
......@@ -39,7 +41,7 @@ class MemcacheStatisticsController extends ControllerBase {
// Failed to load statistics. Provide a useful error about where to get
// more information and help.
$this->messenger()->addError(
t(
$this->t(
'There may be a problem with your Memcache configuration. Please review @readme for more information.',
[
'@readme' => 'README.txt',
......@@ -53,25 +55,25 @@ class MemcacheStatisticsController extends ControllerBase {
$aggregate = array_pop($stats);
if ($memcache->getMemcache() instanceof \Memcached) {
$version = t('Memcached v@version', ['@version' => phpversion('Memcached')]);
$version = $this->t('Memcached v@version', ['@version' => phpversion('Memcached')]);
}
elseif ($memcache->getMemcache() instanceof \Memcache) {
$version = t('Memcache v@version', ['@version' => phpversion('Memcache')]);
$version = $this->t('Memcache v@version', ['@version' => phpversion('Memcache')]);
}
else {
$version = t('Unknown');
$this->messenger()->addError(t('Failed to detect the memcache PECL extension.'));
$version = $this->t('Unknown');
$this->messenger()->addError($this->t('Failed to detect the memcache PECL extension.'));
}
foreach ($stats as $server => $statistics) {
if (empty($statistics['uptime'])) {
$this->messenger()->addError(t('Failed to connect to server at :address.', [':address' => $server]));
$this->messenger()->addError($this->t('Failed to connect to server at :address.', [':address' => $server]));
}
else {
$servers[] = $server;
$data['server_overview'][$server] = t('v@version running @uptime', ['@version' => $statistics['version'], '@uptime' => \Drupal::service('date.formatter')->formatInterval($statistics['uptime'])]);
$data['server_pecl'][$server] = t('n/a');
$data['server_overview'][$server] = $this->t('v@version running @uptime', ['@version' => $statistics['version'], '@uptime' => \Drupal::service('date.formatter')->formatInterval($statistics['uptime'])]);
$data['server_pecl'][$server] = $this->t('n/a');
$data['server_time'][$server] = \Drupal::service('date.formatter')->format($statistics['time']);
$data['server_connections'][$server] = $this->statsConnections($statistics);
$data['cache_sets'][$server] = $this->statsSets($statistics);
......@@ -89,30 +91,30 @@ class MemcacheStatisticsController extends ControllerBase {
$report = [
'uptime' => [
'uptime' => [
'label' => t('Uptime'),
'label' => $this->t('Uptime'),
'servers' => $data['server_overview'],
],
'extension' => [
'label' => t('PECL extension'),
'label' => $this->t('PECL extension'),
'servers' => [$servers[0] => $version],
],
'time' => [
'label' => t('Time'),
'label' => $this->t('Time'),
'servers' => $data['server_time'],
],
'connections' => [
'label' => t('Connections'),
'label' => $this->t('Connections'),
'servers' => $data['server_connections'],
],
],
'stats' => [],
'memory' => [
'memory' => [
'label' => t('Available memory'),
'label' => $this->t('Available memory'),
'servers' => $data['memory_available'],
],
'evictions' => [
'label' => t('Evictions'),
'label' => $this->t('Evictions'),
'servers' => $data['memory_evictions'],
],
],
......@@ -120,10 +122,10 @@ class MemcacheStatisticsController extends ControllerBase {
// Don't display aggregate totals if there's only one server.
if (count($servers) > 1) {
$report['uptime']['uptime']['total'] = t('n/a');
$report['uptime']['uptime']['total'] = $this->t('n/a');
$report['uptime']['extension']['servers'] = $data['server_pecl'];
$report['uptime']['extension']['total'] = $version;
$report['uptime']['time']['total'] = t('n/a');
$report['uptime']['time']['total'] = $this->t('n/a');
$report['uptime']['connections']['total'] = $this->statsConnections($aggregate);
$report['memory']['memory']['total'] = $this->statsMemory($aggregate);
$report['memory']['evictions']['total'] = number_format($aggregate['evictions']);
......@@ -131,11 +133,11 @@ class MemcacheStatisticsController extends ControllerBase {
// Report on stats.
$stats = [
'sets' => t('Sets'),
'gets' => t('Gets'),
'counters' => t('Counters'),
'transfer' => t('Transferred'),
'average' => t('Per-connection average'),
'sets' => $this->t('Sets'),
'gets' => $this->t('Gets'),
'counters' => $this->t('Counters'),
'transfer' => $this->t('Transferred'),
'average' => $this->t('Per-connection average'),
];
foreach ($stats as $type => $label) {
......@@ -205,7 +207,7 @@ class MemcacheStatisticsController extends ControllerBase {
}
else {
$output = $this->statsTablesRawOutput($cluster, $server, [], $type);
$this->messenger()->addMessage(t('No @type statistics for this bin.', ['@type' => $type]));
$this->messenger()->addMessage($this->t('No @type statistics for this bin.', ['@type' => $type]));
}
return $output;
......@@ -415,7 +417,7 @@ class MemcacheStatisticsController extends ControllerBase {
}
if (count($servers) > 1) {
$headers = array_merge(['', t('Totals')], $links);
$headers = array_merge(['', $this->t('Totals')], $links);
}
else {
$headers = array_merge([''], $links);
......
......@@ -4,6 +4,7 @@ namespace Drupal\memcache_admin\EventSubscriber;
use Drupal\Core\Render\Element\HtmlTag;
use Drupal\Core\Render\Markup;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
......@@ -15,6 +16,8 @@ use Drupal\Core\Render\HtmlResponse;
*/
class MemcacheAdminSubscriber implements EventSubscriberInterface {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
......@@ -80,10 +83,10 @@ class MemcacheAdminSubscriber implements EventSubscriberInterface {
$build = [
'#theme' => 'table',
'#header' => [
t('operation'),
t('total ms'),
t('total hits'),
t('total misses'),
$this->t('operation'),
$this->t('total ms'),
$this->t('total hits'),
$this->t('total misses'),
],
'#rows' => $memcache_stats['ops'],
];
......@@ -94,11 +97,11 @@ class MemcacheAdminSubscriber implements EventSubscriberInterface {
$build = [
'#type' => 'table',
'#header' => [
t('ms'),
t('operation'),
t('bin'),
t('key'),
t('status'),
$this->t('ms'),
$this->t('operation'),
$this->t('bin'),
$this->t('key'),
$this->t('status'),
],
];
foreach ($memcache_stats['all'] as $row => $stats) {
......@@ -117,7 +120,7 @@ class MemcacheAdminSubscriber implements EventSubscriberInterface {
}
if (!empty($output)) {
$response->setContent($response->getContent() . '<div id="memcache-devel"><h2>' . t('Memcache statistics') . '</h2>' . $output . '</div>');
$response->setContent($response->getContent() . '<div id="memcache-devel"><h2>' . $this->t('Memcache statistics') . '</h2>' . $output . '</div>');
}
}
}
......
......@@ -2,14 +2,35 @@
namespace Drupal\memcache_admin\Form;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Memcache admin settings form.
*/
class MemcacheAdminSettingsForm extends ConfigFormBase {
/**
* Memcache Admin Settings constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The Configuration Factory.
*/
public function __construct(ConfigFactoryInterface $config_factory) {
parent::__construct($config_factory);
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory')
);
}
/**
* {@inheritdoc}
*/
......@@ -23,9 +44,9 @@ class MemcacheAdminSettingsForm extends ConfigFormBase {
public function buildForm(array $form, FormStateInterface $form_state) {
$form['show_memcache_statistics'] = [
'#type' => 'checkbox',
'#title' => t('Show memcache statistics at the bottom of each page'),
'#default_value' => \Drupal::config('memcache_admin.settings')->get('show_memcache_statistics'),
'#description' => t("These statistics will be visible to users with the 'access memcache statistics' permission."),
'#title' => $this->t('Show memcache statistics at the bottom of each page'),
'#default_value' => $this->config('memcache_admin.settings')->get('show_memcache_statistics'),
'#description' => $this->t("These statistics will be visible to users with the 'access memcache statistics' permission."),
];
return parent::buildForm($form, $form_state);
......
......@@ -3,4 +3,4 @@ type: module
description: 'Support module for memcache testing.'
package: Testing
dependencies:
- memcache
- memcache:memcache
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment