diff --git a/core/lib/Drupal/Core/Entity/EntityDisplayRepositoryInterface.php b/core/lib/Drupal/Core/Entity/EntityDisplayRepositoryInterface.php index 7354869c53..ca7ab71ae1 100644 --- a/core/lib/Drupal/Core/Entity/EntityDisplayRepositoryInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityDisplayRepositoryInterface.php @@ -127,11 +127,11 @@ public function clearDisplayModeInfo(); * @code * \Drupal::service('entity_display.repository') * ->getViewDisplay('node', 'article', 'default') - * ->setComponent('body', array( + * ->setComponent('body', [ * 'type' => 'text_summary_or_trimmed', - * 'settings' => array('trim_length' => '200') + * 'settings' => ['trim_length' => '200'], * 'weight' => 1, - * )) + * ]) * ->removeComponent('field_image') * ->save(); * @endcode @@ -164,13 +164,13 @@ public function getViewDisplay($entity_type, $bundle, $view_mode = self::DEFAULT * @code * \Drupal::service('entity_display.repository') * ->getFormDisplay('node', 'article', 'default') - * ->setComponent('body', array( + * ->setComponent('body', [ * 'type' => 'text_textarea_with_summary', * 'weight' => 1, - * )) - * ->setComponent('field_image', array( + * ]) + * ->setComponent('field_image', [ * 'region' => 'hidden', - * )) + * ]) * ->save(); * @endcode * diff --git a/core/lib/Drupal/Core/Render/Element/Hidden.php b/core/lib/Drupal/Core/Render/Element/Hidden.php index 3864e8389f..32edb6ff87 100644 --- a/core/lib/Drupal/Core/Render/Element/Hidden.php +++ b/core/lib/Drupal/Core/Render/Element/Hidden.php @@ -17,7 +17,7 @@ * * Usage example: * @code - * $form['entity_id'] = array('#type' => 'hidden', '#value' => $entity_id); + * $form['entity_id'] = ['#type' => 'hidden', '#value' => $entity_id]; * @endcode * * @see \Drupal\Core\Render\Element\Value diff --git a/core/lib/Drupal/Core/Render/Element/Link.php b/core/lib/Drupal/Core/Render/Element/Link.php index adbd38584a..9ec68c45e7 100644 --- a/core/lib/Drupal/Core/Render/Element/Link.php +++ b/core/lib/Drupal/Core/Render/Element/Link.php @@ -126,31 +126,31 @@ public static function preRenderLink($element) { * A typical example comes from node links, which are stored in a renderable * array similar to this: * @code - * $build['links'] = array( + * $build['links'] = [ * '#theme' => 'links__node', - * '#pre_render' => array(Link::class, 'preRenderLinks'), - * 'comment' => array( + * '#pre_render' => [Link::class, 'preRenderLinks'], + * 'comment' => [ * '#theme' => 'links__node__comment', - * '#links' => array( + * '#links' => [ * // An array of links associated with node comments, suitable for * // passing in to links.html.twig. - * ), - * ), - * 'statistics' => array( + * ], + * ], + * 'statistics' => [ * '#theme' => 'links__node__statistics', - * '#links' => array( + * '#links' => [ * // An array of links associated with node statistics, suitable for * // passing in to links.html.twig. - * ), - * ), - * 'translation' => array( + * ], + * ], + * 'translation' => [ * '#theme' => 'links__node__translation', - * '#links' => array( + * '#links' => [ * // An array of links associated with node translation, suitable for * // passing in to links.html.twig. - * ), - * ), - * ); + * ], + * ], + * ]; * @endcode * * In this example, the links are grouped by functionality, which can be diff --git a/core/lib/Drupal/Core/Render/Element/Number.php b/core/lib/Drupal/Core/Render/Element/Number.php index 8f7efca552..d16802f295 100644 --- a/core/lib/Drupal/Core/Render/Element/Number.php +++ b/core/lib/Drupal/Core/Render/Element/Number.php @@ -19,10 +19,10 @@ * * Usage example: * @code - * $form['quantity'] = array( + * $form['quantity'] = [ * '#type' => 'number', * '#title' => $this->t('Quantity'), - * ); + * ]; * @endcode * * @see \Drupal\Core\Render\Element\Range diff --git a/core/lib/Drupal/Core/Render/theme.api.php b/core/lib/Drupal/Core/Render/theme.api.php index ce20efa960..462a182461 100644 --- a/core/lib/Drupal/Core/Render/theme.api.php +++ b/core/lib/Drupal/Core/Render/theme.api.php @@ -1288,24 +1288,24 @@ function hook_theme($existing, $type, $theme, $path) { * * For example: * @code - * $theme_registry['block_content_add_list'] = array ( + * $theme_registry['block_content_add_list'] = [ * 'template' => 'block-content-add-list', * 'path' => 'core/themes/claro/templates', * 'type' => 'theme_engine', * 'theme path' => 'core/themes/claro', - * 'includes' => array ( + * 'includes' => [ * 0 => 'core/modules/block_content/block_content.pages.inc', - * ), - * 'variables' => array ( + * ], + * 'variables' => [ * 'content' => NULL, - * ), - * 'preprocess functions' => array ( + * ], + * 'preprocess functions' => [ * 0 => 'template_preprocess', * 1 => 'template_preprocess_block_content_add_list', * 2 => 'contextual_preprocess', * 3 => 'claro_preprocess_block_content_add_list', - * ), - * ); + * ], + * ]; * @endcode * * @param $theme_registry diff --git a/core/lib/Drupal/Core/Site/SettingsEditor.php b/core/lib/Drupal/Core/Site/SettingsEditor.php index e9a8c4c99f..2a131cf876 100644 --- a/core/lib/Drupal/Core/Site/SettingsEditor.php +++ b/core/lib/Drupal/Core/Site/SettingsEditor.php @@ -27,10 +27,10 @@ private function __construct() {} * clutter up the file. * * @code - * $settings['settings']['config_sync_directory'] = (object) array( + * $settings['settings']['config_sync_directory'] = (object) [ * 'value' => 'config_hash/sync', * 'required' => TRUE, - * ); + * ]; * @endcode * gets dumped as: * @code diff --git a/core/lib/Drupal/Core/Test/TestDiscovery.php b/core/lib/Drupal/Core/Test/TestDiscovery.php index 9e394a4342..8bc6a8d51c 100644 --- a/core/lib/Drupal/Core/Test/TestDiscovery.php +++ b/core/lib/Drupal/Core/Test/TestDiscovery.php @@ -137,14 +137,14 @@ public function registerTestNamespaces() { * to. * * @code - * $groups['block'] => array( - * 'Drupal\Tests\block\Functional\BlockTest' => array( + * $groups['block'] => [ + * 'Drupal\Tests\block\Functional\BlockTest' => [ * 'name' => 'Drupal\Tests\block\Functional\BlockTest', * 'description' => 'Tests block UI CRUD functionality.', * 'group' => 'block', * 'groups' => ['block', 'group2', 'group3'], - * ), - * ); + * ], + * ]; * @endcode * * @todo Remove singular grouping; retain list of groups in 'group' key. diff --git a/core/lib/Drupal/Core/Utility/Token.php b/core/lib/Drupal/Core/Utility/Token.php index 689e5e57a1..a9957c5176 100644 --- a/core/lib/Drupal/Core/Utility/Token.php +++ b/core/lib/Drupal/Core/Utility/Token.php @@ -45,7 +45,7 @@ * * // [date:...] tokens use the current date automatically. * $token_service = \Drupal::token(); - * $data = array('node' => $node, 'user' => $user); + * $data = ['node' => $node, 'user' => $user]; * $result = $token_service->replace($text, $data); * return $result * @endcode diff --git a/core/modules/book/src/Controller/BookController.php b/core/modules/book/src/Controller/BookController.php index d84a8d15c3..bb09ae9719 100644 --- a/core/modules/book/src/Controller/BookController.php +++ b/core/modules/book/src/Controller/BookController.php @@ -8,7 +8,6 @@ use Drupal\Core\Link; use Drupal\Core\Render\RendererInterface; use Drupal\Core\Url; -use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\node\NodeInterface; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -20,8 +19,6 @@ */ class BookController extends ControllerBase { - use StringTranslationTrait; - /** * The book manager. * @@ -79,7 +76,7 @@ public static function create(ContainerInterface $container) { public function adminOverview() { $rows = []; - $headers = [$this->t('Book'), $this->t('Operations')]; + $headers = [t('Book'), t('Operations')]; // Add any recognized books to the table list. foreach ($this->bookManager->getAllBooks() as $book) { /** @var \Drupal\Core\Url $url */ @@ -92,7 +89,7 @@ public function adminOverview() { ]; $links = []; $links['edit'] = [ - 'title' => $this->t('Edit order and titles'), + 'title' => t('Edit order and titles'), 'url' => Url::fromRoute('book.admin_edit', ['node' => $book['nid']]), ]; $row[] = [ @@ -107,7 +104,7 @@ public function adminOverview() { '#type' => 'table', '#header' => $headers, '#rows' => $rows, - '#empty' => $this->t('No books available.'), + '#empty' => t('No books available.'), ]; } @@ -158,7 +155,7 @@ public function bookExport($type, NodeInterface $node) { // @todo Convert the custom export functionality to serializer. if (!method_exists($this->bookExport, $method)) { - $this->messenger()->addStatus($this->t('Unknown export format.')); + $this->messenger()->addStatus(t('Unknown export format.')); throw new NotFoundHttpException(); } diff --git a/core/modules/config/src/Controller/ConfigController.php b/core/modules/config/src/Controller/ConfigController.php index c1cd7e50fb..0c0f486865 100644 --- a/core/modules/config/src/Controller/ConfigController.php +++ b/core/modules/config/src/Controller/ConfigController.php @@ -12,7 +12,6 @@ use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Serialization\Yaml; use Drupal\Core\Url; -use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\system\FileDownloadController; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; diff --git a/core/modules/field/tests/modules/field_test/field_test.module b/core/modules/field/tests/modules/field_test/field_test.module index 91ca8c0f90..b48f096634 100644 --- a/core/modules/field/tests/modules/field_test/field_test.module +++ b/core/modules/field/tests/modules/field_test/field_test.module @@ -50,7 +50,7 @@ * * // make sure hook_field_storage_config_create() is invoked correctly * assertEquals(1, count($mem['field_test_field_storage_config_create'])); - * assertEquals(array($field), $mem['field_test_field_storage_config_create'][0]); + * assertEquals([$field], $mem['field_test_field_storage_config_create'][0]); * @endcode * * @param $key diff --git a/core/modules/system/src/Controller/SystemController.php b/core/modules/system/src/Controller/SystemController.php index 1e2d077f41..afb715dad9 100644 --- a/core/modules/system/src/Controller/SystemController.php +++ b/core/modules/system/src/Controller/SystemController.php @@ -15,7 +15,6 @@ use Drupal\Core\Menu\MenuTreeParameters; use Drupal\Core\Theme\ThemeAccessCheck; use Drupal\Core\Url; -use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\system\SystemManager; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -25,7 +24,6 @@ class SystemController extends ControllerBase { use ModuleDependencyMessageTrait; - use StringTranslationTrait; /** * System Manager Service. @@ -337,7 +335,7 @@ public function themesPage() { 'attributes' => ['title' => $this->t('Set @theme as default theme', ['@theme' => $theme->info['name']])], ]; } - $admin_theme_options[$theme->getName()] = $theme->info['name'] . ($theme->isExperimental() ? ' (' . $this->t('Experimental') . ')' : ''); + $admin_theme_options[$theme->getName()] = $theme->info['name'] . ($theme->isExperimental() ? ' (' . t('Experimental') . ')' : ''); } else { $theme->operations[] = [ diff --git a/core/modules/system/src/Controller/SystemInfoController.php b/core/modules/system/src/Controller/SystemInfoController.php index 27ed5ea906..16f8bf946b 100644 --- a/core/modules/system/src/Controller/SystemInfoController.php +++ b/core/modules/system/src/Controller/SystemInfoController.php @@ -6,7 +6,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Response; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; -use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\system\SystemManager; use Drupal\Core\StringTranslation\StringTranslationTrait; diff --git a/core/modules/tracker/src/Controller/TrackerController.php b/core/modules/tracker/src/Controller/TrackerController.php index 5aecc38ca9..aeb65755ee 100644 --- a/core/modules/tracker/src/Controller/TrackerController.php +++ b/core/modules/tracker/src/Controller/TrackerController.php @@ -11,7 +11,6 @@ use Drupal\Core\Datetime\DateFormatterInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Session\AccountInterface; -use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\user\UserInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -20,8 +19,6 @@ */ class TrackerController extends ControllerBase { - use StringTranslationTrait; - /** * The database connection. * @@ -214,7 +211,7 @@ public function buildContent(UserInterface $user = NULL) { 'data-history-node-last-comment-timestamp' => $tracker_data[$node->id()]->last_comment_timestamp ?? 0, ], 'last updated' => [ - 'data' => $this->t('@time ago', [ + 'data' => t('@time ago', [ '@time' => $this->dateFormatter->formatTimeDiffSince($last_activity), ]), ], diff --git a/core/modules/views/src/Plugin/views/cache/CachePluginBase.php b/core/modules/views/src/Plugin/views/cache/CachePluginBase.php index d372baedc2..9624d6b270 100644 --- a/core/modules/views/src/Plugin/views/cache/CachePluginBase.php +++ b/core/modules/views/src/Plugin/views/cache/CachePluginBase.php @@ -179,7 +179,7 @@ public function cacheFlush() { * go there: * * @code - * strtr($output, array('', 'output for FIELD of nid 1'); + * strtr($output, ['', 'output for FIELD of nid 1']); * @endcode * * All of the cached result data will be available in $view->result, as well, diff --git a/core/modules/views/src/Views.php b/core/modules/views/src/Views.php index 2373ebbc21..a7feae2c34 100644 --- a/core/modules/views/src/Views.php +++ b/core/modules/views/src/Views.php @@ -200,10 +200,10 @@ public static function getEnabledDisplayExtenders() { * A list of arrays containing the $view_id and $display_id. * * @code - * array( - * array($view_id, $display_id), - * array($view_id, $display_id), - * ); + * [ + * [$view_id, $display_id], + * [$view_id, $display_id], + * ]; * @endcode */ public static function getApplicableViews($type) { diff --git a/core/modules/views_ui/src/Controller/ViewsUIController.php b/core/modules/views_ui/src/Controller/ViewsUIController.php index e731bef825..b81bf43175 100644 --- a/core/modules/views_ui/src/Controller/ViewsUIController.php +++ b/core/modules/views_ui/src/Controller/ViewsUIController.php @@ -16,7 +16,6 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Ajax\ReplaceCommand; -use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Component\Utility\Html; /** @@ -24,8 +23,6 @@ */ class ViewsUIController extends ControllerBase { - use StringTranslationTrait; - /** * Stores the Views data cache object. * @@ -86,7 +83,7 @@ public function reportFields() { } } - $header = [$this->t('Field name'), $this->t('Used in')]; + $header = [t('Field name'), t('Used in')]; $rows = []; foreach ($fields as $field_name => $views) { $rows[$field_name]['data'][0]['data']['#plain_text'] = $field_name; @@ -107,7 +104,7 @@ public function reportFields() { '#type' => 'table', '#header' => $header, '#rows' => $rows, - '#empty' => $this->t('No fields have been used in views yet.'), + '#empty' => t('No fields have been used in views yet.'), ]; return $output; @@ -139,9 +136,9 @@ public function reportPlugins() { ksort($rows); return [ '#type' => 'table', - '#header' => [$this->t('Type'), $this->t('Name'), $this->t('Provided by'), $this->t('Used in')], + '#header' => [t('Type'), t('Name'), t('Provided by'), t('Used in')], '#rows' => $rows, - '#empty' => $this->t('There are no enabled views.'), + '#empty' => t('There are no enabled views.'), ]; } diff --git a/core/phpcs.xml.dist b/core/phpcs.xml.dist index ed5acf2e73..905d523bde 100644 --- a/core/phpcs.xml.dist +++ b/core/phpcs.xml.dist @@ -61,6 +61,7 @@ + diff --git a/core/profiles/demo_umami/tests/src/Functional/DemoUmamiProfileTest.php b/core/profiles/demo_umami/tests/src/Functional/DemoUmamiProfileTest.php index 246b555153..180a4a166f 100644 --- a/core/profiles/demo_umami/tests/src/Functional/DemoUmamiProfileTest.php +++ b/core/profiles/demo_umami/tests/src/Functional/DemoUmamiProfileTest.php @@ -260,7 +260,7 @@ protected function testDemonstrationWarningMessage() { * For example: * @code * // Create a user. - * $account = $this->drupalCreateUser(array()); + * $account = $this->drupalCreateUser([]); * $this->drupalLogin($account); * // Load real user object. * $pass_raw = $account->passRaw; diff --git a/core/tests/Drupal/Tests/UiHelperTrait.php b/core/tests/Drupal/Tests/UiHelperTrait.php index e811de7ede..b60951c9a4 100644 --- a/core/tests/Drupal/Tests/UiHelperTrait.php +++ b/core/tests/Drupal/Tests/UiHelperTrait.php @@ -134,7 +134,7 @@ protected function submitForm(array $edit, $submit, $form_html_id = NULL) { * For example: * @code * // Create a user. - * $account = $this->drupalCreateUser(array()); + * $account = $this->drupalCreateUser([]); * $this->drupalLogin($account); * // Load real user object. * $pass_raw = $account->passRaw;