From 58c6687aa22a32c0f1bc0476d611e0264150f833 Mon Sep 17 00:00:00 2001 From: Dave Long <dave@longwaveconsulting.com> Date: Thu, 22 Aug 2024 18:13:47 +0100 Subject: [PATCH] Issue #3464595 by quietone: Fix DrupalPractice.Objects.GlobalFunction in ListBuilders (cherry picked from commit 0b17a5749201e556b0d1826c445f6ea30b4c669b) --- .../comment/src/CommentTypeListBuilder.php | 6 +++--- .../contact/src/ContactFormListBuilder.php | 12 ++++++------ .../image/src/ImageStyleListBuilder.php | 2 +- .../language/src/LanguageListBuilder.php | 8 ++++---- core/modules/menu_ui/src/MenuListBuilder.php | 10 +++++----- core/modules/node/src/NodeTypeListBuilder.php | 4 ++-- .../src/ResponsiveImageStyleListBuilder.php | 4 ++-- .../taxonomy/src/VocabularyListBuilder.php | 18 +++++++++--------- core/modules/user/src/RoleListBuilder.php | 4 ++-- core/modules/user/src/UserListBuilder.php | 2 +- core/phpcs.xml.dist | 1 + 11 files changed, 36 insertions(+), 35 deletions(-) diff --git a/core/modules/comment/src/CommentTypeListBuilder.php b/core/modules/comment/src/CommentTypeListBuilder.php index 578bc70a5ef8..05158bc9b3bb 100644 --- a/core/modules/comment/src/CommentTypeListBuilder.php +++ b/core/modules/comment/src/CommentTypeListBuilder.php @@ -58,9 +58,9 @@ public function getDefaultOperations(EntityInterface $entity) { * {@inheritdoc} */ public function buildHeader() { - $header['type'] = t('Comment type'); - $header['description'] = t('Description'); - $header['target'] = t('Target entity type'); + $header['type'] = $this->t('Comment type'); + $header['description'] = $this->t('Description'); + $header['target'] = $this->t('Target entity type'); return $header + parent::buildHeader(); } diff --git a/core/modules/contact/src/ContactFormListBuilder.php b/core/modules/contact/src/ContactFormListBuilder.php index 9a4d6cc32773..1d2bf159ecdb 100644 --- a/core/modules/contact/src/ContactFormListBuilder.php +++ b/core/modules/contact/src/ContactFormListBuilder.php @@ -16,9 +16,9 @@ class ContactFormListBuilder extends ConfigEntityListBuilder { * {@inheritdoc} */ public function buildHeader() { - $header['form'] = t('Form'); - $header['recipients'] = t('Recipients'); - $header['selected'] = t('Selected'); + $header['form'] = $this->t('Form'); + $header['recipients'] = $this->t('Recipients'); + $header['selected'] = $this->t('Selected'); return $header + parent::buildHeader(); } @@ -29,8 +29,8 @@ public function buildRow(EntityInterface $entity) { // Special case the personal form. if ($entity->id() == 'personal') { $row['form'] = $entity->label(); - $row['recipients'] = t('Selected user'); - $row['selected'] = t('No'); + $row['recipients'] = $this->t('Selected user'); + $row['selected'] = $this->t('No'); } else { $row['form'] = $entity->toLink(NULL, 'canonical')->toString(); @@ -40,7 +40,7 @@ public function buildRow(EntityInterface $entity) { '#context' => ['list_style' => 'comma-list'], ]; $default_form = \Drupal::config('contact.settings')->get('default_form'); - $row['selected'] = ($default_form == $entity->id() ? t('Yes') : t('No')); + $row['selected'] = ($default_form == $entity->id() ? $this->t('Yes') : $this->t('No')); } return $row + parent::buildRow($entity); } diff --git a/core/modules/image/src/ImageStyleListBuilder.php b/core/modules/image/src/ImageStyleListBuilder.php index 00a0ec197029..fb7bb0ea379a 100644 --- a/core/modules/image/src/ImageStyleListBuilder.php +++ b/core/modules/image/src/ImageStyleListBuilder.php @@ -34,7 +34,7 @@ public function buildRow(EntityInterface $entity) { */ public function getDefaultOperations(EntityInterface $entity) { $flush = [ - 'title' => t('Flush'), + 'title' => $this->t('Flush'), 'weight' => 200, 'url' => $entity->toUrl('flush-form'), ]; diff --git a/core/modules/language/src/LanguageListBuilder.php b/core/modules/language/src/LanguageListBuilder.php index 290e699c232d..25cd63d87234 100644 --- a/core/modules/language/src/LanguageListBuilder.php +++ b/core/modules/language/src/LanguageListBuilder.php @@ -103,8 +103,8 @@ public function getFormId() { */ public function buildHeader() { $header = [ - 'label' => t('Name'), - 'default' => t('Default'), + 'label' => $this->t('Name'), + 'default' => $this->t('Default'), ] + parent::buildHeader(); return $header; } @@ -117,7 +117,7 @@ public function buildRow(EntityInterface $entity) { $row['default'] = [ '#type' => 'radio', '#parents' => ['site_default_language'], - '#title' => t('Set @title as default', ['@title' => $entity->label()]), + '#title' => $this->t('Set @title as default', ['@title' => $entity->label()]), '#title_display' => 'invisible', '#return_value' => $entity->id(), '#id' => 'edit-site-default-language-' . $entity->id(), @@ -136,7 +136,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { $form = parent::buildForm($form, $form_state); $form[$this->entitiesKey]['#languages'] = $this->entities; - $form['actions']['submit']['#value'] = t('Save configuration'); + $form['actions']['submit']['#value'] = $this->t('Save configuration'); return $form; } diff --git a/core/modules/menu_ui/src/MenuListBuilder.php b/core/modules/menu_ui/src/MenuListBuilder.php index 2d6c286fd5d7..e0ac874c5b97 100644 --- a/core/modules/menu_ui/src/MenuListBuilder.php +++ b/core/modules/menu_ui/src/MenuListBuilder.php @@ -23,9 +23,9 @@ class MenuListBuilder extends ConfigEntityListBuilder { * {@inheritdoc} */ public function buildHeader() { - $header['title'] = t('Title'); + $header['title'] = $this->t('Title'); $header['description'] = [ - 'data' => t('Description'), + 'data' => $this->t('Description'), 'class' => [RESPONSIVE_PRIORITY_MEDIUM], ]; return $header + parent::buildHeader(); @@ -50,9 +50,9 @@ public function getDefaultOperations(EntityInterface $entity) { $operations = parent::getDefaultOperations($entity); if (isset($operations['edit'])) { - $operations['edit']['title'] = t('Edit menu'); + $operations['edit']['title'] = $this->t('Edit menu'); $operations['add'] = [ - 'title' => t('Add link'), + 'title' => $this->t('Add link'), 'weight' => 20, 'url' => $entity->toUrl('add-link-form'), 'query' => [ @@ -61,7 +61,7 @@ public function getDefaultOperations(EntityInterface $entity) { ]; } if (isset($operations['delete'])) { - $operations['delete']['title'] = t('Delete menu'); + $operations['delete']['title'] = $this->t('Delete menu'); } return $operations; } diff --git a/core/modules/node/src/NodeTypeListBuilder.php b/core/modules/node/src/NodeTypeListBuilder.php index c99f3a545c91..327c858b0d3f 100644 --- a/core/modules/node/src/NodeTypeListBuilder.php +++ b/core/modules/node/src/NodeTypeListBuilder.php @@ -17,9 +17,9 @@ class NodeTypeListBuilder extends ConfigEntityListBuilder { * {@inheritdoc} */ public function buildHeader() { - $header['title'] = t('Name'); + $header['title'] = $this->t('Name'); $header['description'] = [ - 'data' => t('Description'), + 'data' => $this->t('Description'), 'class' => [RESPONSIVE_PRIORITY_MEDIUM], ]; return $header + parent::buildHeader(); diff --git a/core/modules/responsive_image/src/ResponsiveImageStyleListBuilder.php b/core/modules/responsive_image/src/ResponsiveImageStyleListBuilder.php index cb69bb6250da..b10a72051e77 100644 --- a/core/modules/responsive_image/src/ResponsiveImageStyleListBuilder.php +++ b/core/modules/responsive_image/src/ResponsiveImageStyleListBuilder.php @@ -14,7 +14,7 @@ class ResponsiveImageStyleListBuilder extends ConfigEntityListBuilder { * {@inheritdoc} */ public function buildHeader() { - $header['label'] = t('Label'); + $header['label'] = $this->t('Label'); return $header + parent::buildHeader(); } @@ -32,7 +32,7 @@ public function buildRow(EntityInterface $entity) { public function getDefaultOperations(EntityInterface $entity) { $operations = parent::getDefaultOperations($entity); $operations['duplicate'] = [ - 'title' => t('Duplicate'), + 'title' => $this->t('Duplicate'), 'weight' => 15, 'url' => $entity->toUrl('duplicate-form'), ]; diff --git a/core/modules/taxonomy/src/VocabularyListBuilder.php b/core/modules/taxonomy/src/VocabularyListBuilder.php index ee058c9cfcf0..d5536f54a757 100644 --- a/core/modules/taxonomy/src/VocabularyListBuilder.php +++ b/core/modules/taxonomy/src/VocabularyListBuilder.php @@ -109,7 +109,7 @@ public function getDefaultOperations(EntityInterface $entity) { $operations = parent::getDefaultOperations($entity); if (isset($operations['edit'])) { - $operations['edit']['title'] = t('Edit vocabulary'); + $operations['edit']['title'] = $this->t('Edit vocabulary'); } if (isset($operations['delete'])) { $operations['delete']['title'] = $this->t('Delete vocabulary'); @@ -117,7 +117,7 @@ public function getDefaultOperations(EntityInterface $entity) { if ($entity->access('access taxonomy overview')) { $operations['list'] = [ - 'title' => t('List terms'), + 'title' => $this->t('List terms'), 'weight' => 0, 'url' => $entity->toUrl('overview-form'), ]; @@ -126,7 +126,7 @@ public function getDefaultOperations(EntityInterface $entity) { $taxonomy_term_access_control_handler = $this->entityTypeManager->getAccessControlHandler('taxonomy_term'); if ($taxonomy_term_access_control_handler->createAccess($entity->id())) { $operations['add'] = [ - 'title' => t('Add terms'), + 'title' => $this->t('Add terms'), 'weight' => 10, 'url' => Url::fromRoute('entity.taxonomy_term.add_form', ['taxonomy_vocabulary' => $entity->id()]), ]; @@ -139,11 +139,11 @@ public function getDefaultOperations(EntityInterface $entity) { * {@inheritdoc} */ public function buildHeader() { - $header['label'] = t('Vocabulary name'); - $header['description'] = t('Description'); + $header['label'] = $this->t('Vocabulary name'); + $header['description'] = $this->t('Description'); if ($this->currentUser->hasPermission('administer vocabularies') && !empty($this->weightKey)) { - $header['weight'] = t('Weight'); + $header['weight'] = $this->t('Weight'); } return $header + parent::buildHeader(); @@ -179,12 +179,12 @@ public function render() { $create_access = $access_control_handler->createAccess(NULL, NULL, [], TRUE); $this->renderer->addCacheableDependency($build['table'], $create_access); if ($create_access->isAllowed()) { - $build['table']['#empty'] = t('No vocabularies available. <a href=":link">Add vocabulary</a>.', [ + $build['table']['#empty'] = $this->t('No vocabularies available. <a href=":link">Add vocabulary</a>.', [ ':link' => Url::fromRoute('entity.taxonomy_vocabulary.add_form')->toString(), ]); } else { - $build['table']['#empty'] = t('No vocabularies available.'); + $build['table']['#empty'] = $this->t('No vocabularies available.'); } } @@ -197,7 +197,7 @@ public function render() { public function buildForm(array $form, FormStateInterface $form_state) { $form = parent::buildForm($form, $form_state); $form['vocabularies']['#attributes'] = ['id' => 'taxonomy']; - $form['actions']['submit']['#value'] = t('Save'); + $form['actions']['submit']['#value'] = $this->t('Save'); return $form; } diff --git a/core/modules/user/src/RoleListBuilder.php b/core/modules/user/src/RoleListBuilder.php index 24e81e5c1c6a..295700e7b576 100644 --- a/core/modules/user/src/RoleListBuilder.php +++ b/core/modules/user/src/RoleListBuilder.php @@ -65,7 +65,7 @@ public function getFormId() { * {@inheritdoc} */ public function buildHeader() { - $header['label'] = t('Name'); + $header['label'] = $this->t('Name'); return $header + parent::buildHeader(); } @@ -85,7 +85,7 @@ public function getDefaultOperations(EntityInterface $entity) { if ($entity->hasLinkTemplate('edit-permissions-form')) { $operations['permissions'] = [ - 'title' => t('Edit permissions'), + 'title' => $this->t('Edit permissions'), 'weight' => 20, 'url' => $entity->toUrl('edit-permissions-form'), ]; diff --git a/core/modules/user/src/UserListBuilder.php b/core/modules/user/src/UserListBuilder.php index 512e1b66960c..d7ef00f9865d 100644 --- a/core/modules/user/src/UserListBuilder.php +++ b/core/modules/user/src/UserListBuilder.php @@ -144,7 +144,7 @@ public function buildRow(EntityInterface $entity) { CacheableMetadata::createFromObject($last_access)->applyTo($row['access']['data']); } else { - $row['access']['data']['#markup'] = t('never'); + $row['access']['data']['#markup'] = $this->t('never'); } return $row + parent::buildRow($entity); } diff --git a/core/phpcs.xml.dist b/core/phpcs.xml.dist index 0466d99f9bae..d6690674dbdf 100644 --- a/core/phpcs.xml.dist +++ b/core/phpcs.xml.dist @@ -169,6 +169,7 @@ <rule ref="DrupalPractice.InfoFiles.NamespacedDependency"/> <rule ref="DrupalPractice.Objects.GlobalFunction"> <include-pattern>*/Plugin/*</include-pattern> + <include-pattern>*/ListBuilder/*</include-pattern> </rule> <!-- Generic sniffs --> -- GitLab