Loading l10n_community/src/Plugin/Block/TopContributorsBlock.php +22 −2 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ namespace Drupal\l10n_community\Plugin\Block; use Drupal\Core\Block\BlockBase; use Drupal\Core\Cache\Cache; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\l10n_community\L10nStatistics; use Symfony\Component\DependencyInjection\ContainerInterface; Loading Loading @@ -75,12 +76,20 @@ class TopContributorsBlock extends BlockBase implements ContainerFactoryPluginIn * {@inheritdoc} */ public function build() { $people = $this->statistics->getPeopleStringCount('en'); $current_path = \Drupal::service('path.current')->getPath(); $path_items = explode('/', $current_path); $languages = \Drupal::languageManager()->getLanguages(); if (!isset($languages[$path_items[1]])) { return []; } $language = $languages[$path_items[1]]; $people = $this->statistics->getPeopleStringCount($language->getId()); $rows = []; foreach ($people as $translator) { $rows[] = [ $translator['name'], $translator['sum'], $translator['name'], $translator['sum'], $language->getId(), ]; } if ($rows) { Loading @@ -89,6 +98,7 @@ class TopContributorsBlock extends BlockBase implements ContainerFactoryPluginIn '#header' => [ $this->t('Name'), $this->t('Translation count'), $this->t('Langcode'), ], '#rows' => $rows, ]; Loading @@ -101,4 +111,14 @@ class TopContributorsBlock extends BlockBase implements ContainerFactoryPluginIn return $build; } /** * {@inheritdoc} */ public function getCacheContexts() { return Cache::mergeContexts( parent::getCacheContexts(), ['url.path'] ); } } Loading
l10n_community/src/Plugin/Block/TopContributorsBlock.php +22 −2 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ namespace Drupal\l10n_community\Plugin\Block; use Drupal\Core\Block\BlockBase; use Drupal\Core\Cache\Cache; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\l10n_community\L10nStatistics; use Symfony\Component\DependencyInjection\ContainerInterface; Loading Loading @@ -75,12 +76,20 @@ class TopContributorsBlock extends BlockBase implements ContainerFactoryPluginIn * {@inheritdoc} */ public function build() { $people = $this->statistics->getPeopleStringCount('en'); $current_path = \Drupal::service('path.current')->getPath(); $path_items = explode('/', $current_path); $languages = \Drupal::languageManager()->getLanguages(); if (!isset($languages[$path_items[1]])) { return []; } $language = $languages[$path_items[1]]; $people = $this->statistics->getPeopleStringCount($language->getId()); $rows = []; foreach ($people as $translator) { $rows[] = [ $translator['name'], $translator['sum'], $translator['name'], $translator['sum'], $language->getId(), ]; } if ($rows) { Loading @@ -89,6 +98,7 @@ class TopContributorsBlock extends BlockBase implements ContainerFactoryPluginIn '#header' => [ $this->t('Name'), $this->t('Translation count'), $this->t('Langcode'), ], '#rows' => $rows, ]; Loading @@ -101,4 +111,14 @@ class TopContributorsBlock extends BlockBase implements ContainerFactoryPluginIn return $build; } /** * {@inheritdoc} */ public function getCacheContexts() { return Cache::mergeContexts( parent::getCacheContexts(), ['url.path'] ); } }