diff --git a/core/lib/Drupal/Core/Database/Database.php b/core/lib/Drupal/Core/Database/Database.php index d13ea80862..13e018fa58 100644 --- a/core/lib/Drupal/Core/Database/Database.php +++ b/core/lib/Drupal/Core/Database/Database.php @@ -366,7 +366,7 @@ } $namespace = static::getDatabaseDriverNamespace(self::$databaseInfo[$key][$target]); - $driver_class = $namespace . '\\Connection'; + $driver_class = self::$databaseInfo[$key][$target]['namespace'] . '\\Connnection'; $pdo_connection = $driver_class::open(self::$databaseInfo[$key][$target]); $new_connection = new $driver_class($pdo_connection, self::$databaseInfo[$key][$target]); @@ -488,7 +488,7 @@ public static function getConnectionInfoAsUrl($key = 'default') { if (empty($db_info) || empty($db_info['default'])) { throw new \RuntimeException("Database connection $key not defined or missing the 'default' settings"); } - $connection_class = static::getDatabaseDriverNamespace($db_info['default']) . '\\Connection'; + $connection_class = $db_info['default']['namespace'] . '\\Connection'; return $connection_class::createUrlFromConnectionOptions($db_info['default']); } diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index db68f43cd8..1b0e45eac0 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -190,7 +190,6 @@ function comment_node_links_alter(array &$links, NodeInterface $node, array &$co // can do so by implementing a new field formatter. // @todo Make this configurable from the formatter. See // https://www.drupal.org/node/1901110. - $comment_links = \Drupal::service('comment.link_builder')->buildCommentedEntityLinks($node, $context); $links += $comment_links; } diff --git a/core/modules/comment/src/CommentForm.php b/core/modules/comment/src/CommentForm.php index 48c72712df..2330ab8051 100644 --- a/core/modules/comment/src/CommentForm.php +++ b/core/modules/comment/src/CommentForm.php @@ -74,6 +74,8 @@ public static function create(ContainerInterface $container) { * The entity type bundle service. * @param \Drupal\Component\Datetime\TimeInterface $time * The time service. + * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager + * The entity field manager. */ public function __construct(EntityRepositoryInterface $entity_repository, AccountInterface $current_user, RendererInterface $renderer, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL, EntityFieldManagerInterface $entity_field_manager = NULL) { parent::__construct($entity_repository, $entity_type_bundle_info, $time); @@ -115,10 +117,14 @@ public function form(array $form, FormStateInterface $form_state) { $form['#attributes']['data-user-info-from-browser'] = TRUE; } - // If not replying to a comment, use our dedicated page callback for new - // Comments on entities. + // If not replying to a comment, use our dedicated page callback for new. if (!$comment->id() && !$comment->hasParentComment()) { - $form['#action'] = Url::fromRoute('comment.reply', ['entity_type' => $entity->getEntityTypeId(), 'entity' => $entity->id(), 'field_name' => $field_name])->toString(); + $form['#action'] = Url::fromRoute('comment.reply', + [ + 'entity_type' => $entity->getEntityTypeId(), + 'entity' => $entity->id(), + 'field_name' => $field_name, + ])->toString(); } $comment_preview = $form_state->get('comment_preview'); @@ -380,9 +386,9 @@ public function save(array $form, FormStateInterface $form_state) { // Add a log entry. $logger->notice('Comment posted: %subject.', [ - '%subject' => $comment->getSubject(), - 'link' => Link::fromTextAndUrl(t('View'), $comment->toUrl()->setOption('fragment', 'comment-' . $comment->id()))->toString(), - ]); + '%subject' => $comment->getSubject(), + 'link' => Link::fromTextAndUrl($this->t('View'), $comment->toUrl()->setOption('fragment', 'comment-' . $comment->id()))->toString(), + ]); // Explain the approval queue if necessary. if (!$comment->isPublished()) { diff --git a/core/modules/comment/src/CommentStatistics.php b/core/modules/comment/src/CommentStatistics.php index 95d8a123ba..ab4daa84f4 100644 --- a/core/modules/comment/src/CommentStatistics.php +++ b/core/modules/comment/src/CommentStatistics.php @@ -10,8 +10,14 @@ use Drupal\Core\State\StateInterface; use Drupal\Core\Session\AccountInterface; use Drupal\user\EntityOwnerInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; +/** + * {@inheritdoc} + */ class CommentStatistics implements CommentStatisticsInterface { + + use StringTranslationTrait; /** * The current database connection. @@ -163,7 +169,7 @@ public function getMaximumCount($entity_type) { public function getRankingInfo() { return [ 'comments' => [ - 'title' => t('Number of comments'), + 'title' => $this->t('Number of comments'), 'join' => [ 'type' => 'LEFT', 'table' => 'comment_entity_statistics', @@ -179,7 +185,7 @@ public function getRankingInfo() { // values in as strings instead of numbers in complex expressions like // this. 'score' => '2.0 - 2.0 / (1.0 + ces.comment_count * (ROUND(:comment_scale, 4)))', - 'arguments' => [':comment_scale' => \Drupal::state()->get('comment.node_comment_statistics_scale') ?: 0], + 'arguments' => [':comment_scale' => $this->state->get('comment.node_comment_statistics_scale') ?: 0], ], ]; } diff --git a/core/modules/comment/src/CommentTranslationHandler.php b/core/modules/comment/src/CommentTranslationHandler.php index a0abe4b710..433d0571bc 100644 --- a/core/modules/comment/src/CommentTranslationHandler.php +++ b/core/modules/comment/src/CommentTranslationHandler.php @@ -30,7 +30,7 @@ public function entityFormAlter(array &$form, FormStateInterface $form_state, En * {@inheritdoc} */ protected function entityFormTitle(EntityInterface $entity) { - return t('Edit comment @subject', ['@subject' => $entity->label()]); + return $this->t('Edit comment @subject', ['@subject' => $entity->label()]); } /** diff --git a/core/modules/comment/src/CommentTypeForm.php b/core/modules/comment/src/CommentTypeForm.php index ff7be1c1bd..7a0f4563ad 100644 --- a/core/modules/comment/src/CommentTypeForm.php +++ b/core/modules/comment/src/CommentTypeForm.php @@ -50,7 +50,7 @@ public static function create(ContainerInterface $container) { } /** - * Constructs a CommentTypeFormController + * Constructs a CommentTypeFormController. * * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * The entity type manager service. @@ -75,7 +75,7 @@ public function form(array $form, FormStateInterface $form_state) { $form['label'] = [ '#type' => 'textfield', - '#title' => t('Label'), + '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $comment_type->label(), '#required' => TRUE, @@ -93,8 +93,8 @@ public function form(array $form, FormStateInterface $form_state) { $form['description'] = [ '#type' => 'textarea', '#default_value' => $comment_type->getDescription(), - '#description' => t('Describe this comment type. The text will be displayed on the Comment types administration overview page.'), - '#title' => t('Description'), + '#description' => $this->t('Describe this comment type. The text will be displayed on the Comment types administration overview page.'), + '#title' => $this->t('Description'), ]; if ($comment_type->isNew()) { @@ -109,23 +109,23 @@ public function form(array $form, FormStateInterface $form_state) { $form['target_entity_type_id'] = [ '#type' => 'select', '#default_value' => $comment_type->getTargetEntityTypeId(), - '#title' => t('Target entity type'), + '#title' => $this->t('Target entity type'), '#options' => $options, - '#description' => t('The target entity type can not be changed after the comment type has been created.'), + '#description' => $this->t('The target entity type can not be changed after the comment type has been created.'), ]; } else { $form['target_entity_type_id_display'] = [ '#type' => 'item', '#markup' => $this->entityTypeManager->getDefinition($comment_type->getTargetEntityTypeId())->getLabel(), - '#title' => t('Target entity type'), + '#title' => $this->t('Target entity type'), ]; } if ($this->moduleHandler->moduleExists('content_translation')) { $form['language'] = [ '#type' => 'details', - '#title' => t('Language settings'), + '#title' => $this->t('Language settings'), '#group' => 'additional_settings', ]; @@ -145,7 +145,7 @@ public function form(array $form, FormStateInterface $form_state) { $form['actions'] = ['#type' => 'actions']; $form['actions']['submit'] = [ '#type' => 'submit', - '#value' => t('Save'), + '#value' => $this->t('Save'), ]; return $form; @@ -160,12 +160,12 @@ public function save(array $form, FormStateInterface $form_state) { $edit_link = $this->entity->toLink($this->t('Edit'), 'edit-form')->toString(); if ($status == SAVED_UPDATED) { - $this->messenger()->addStatus(t('Comment type %label has been updated.', ['%label' => $comment_type->label()])); + $this->messenger()->addStatus($this->t('Comment type %label has been updated.', ['%label' => $comment_type->label()])); $this->logger->notice('Comment type %label has been updated.', ['%label' => $comment_type->label(), 'link' => $edit_link]); } else { $this->commentManager->addBodyField($comment_type->id()); - $this->messenger()->addStatus(t('Comment type %label has been added.', ['%label' => $comment_type->label()])); + $this->messenger()->addStatus($this->t('Comment type %label has been added.', ['%label' => $comment_type->label()])); $this->logger->notice('Comment type %label has been added.', ['%label' => $comment_type->label(), 'link' => $edit_link]); } diff --git a/core/modules/comment/src/CommentTypeListBuilder.php b/core/modules/comment/src/CommentTypeListBuilder.php index 53bf4c9e76..ffc367a1fe 100644 --- a/core/modules/comment/src/CommentTypeListBuilder.php +++ b/core/modules/comment/src/CommentTypeListBuilder.php @@ -29,8 +29,8 @@ public function getDefaultOperations(EntityInterface $entity) { * {@inheritdoc} */ public function buildHeader() { - $header['type'] = t('Comment type'); - $header['description'] = t('Description'); + $header['type'] = $this->t('Comment type'); + $header['description'] = $this->t('Description'); return $header + parent::buildHeader(); } diff --git a/core/modules/comment/src/Plugin/Field/FieldType/CommentItem.php b/core/modules/comment/src/Plugin/Field/FieldType/CommentItem.php index 255b5ab7c1..7f5d5cf21f 100644 --- a/core/modules/comment/src/Plugin/Field/FieldType/CommentItem.php +++ b/core/modules/comment/src/Plugin/Field/FieldType/CommentItem.php @@ -108,13 +108,13 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) { $element['default_mode'] = [ '#type' => 'checkbox', - '#title' => t('Threading'), + '#title' => $this->t('Threading'), '#default_value' => $settings['default_mode'], - '#description' => t('Show comment replies in a threaded list.'), + '#description' => $this->t('Show comment replies in a threaded list.'), ]; $element['per_page'] = [ '#type' => 'number', - '#title' => t('Comments per page'), + '#title' => $this->t('Comments per page'), '#default_value' => $settings['per_page'], '#required' => TRUE, '#min' => 1, @@ -122,28 +122,28 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) { ]; $element['anonymous'] = [ '#type' => 'select', - '#title' => t('Anonymous commenting'), + '#title' => $this->t('Anonymous commenting'), '#default_value' => $settings['anonymous'], '#options' => [ - CommentInterface::ANONYMOUS_MAYNOT_CONTACT => t('Anonymous posters may not enter their contact information'), - CommentInterface::ANONYMOUS_MAY_CONTACT => t('Anonymous posters may leave their contact information'), - CommentInterface::ANONYMOUS_MUST_CONTACT => t('Anonymous posters must leave their contact information'), + CommentInterface::ANONYMOUS_MAYNOT_CONTACT => $this->t('Anonymous posters may not enter their contact information'), + CommentInterface::ANONYMOUS_MAY_CONTACT => $this->t('Anonymous posters may leave their contact information'), + CommentInterface::ANONYMOUS_MUST_CONTACT => $this->t('Anonymous posters must leave their contact information'), ], '#access' => $anonymous_user->hasPermission('post comments'), ]; $element['form_location'] = [ '#type' => 'checkbox', - '#title' => t('Show reply form on the same page as comments'), + '#title' => $this->t('Show reply form on the same page as comments'), '#default_value' => $settings['form_location'], ]; $element['preview'] = [ '#type' => 'radios', - '#title' => t('Preview comment'), + '#title' => $this->t('Preview comment'), '#default_value' => $settings['preview'], '#options' => [ - DRUPAL_DISABLED => t('Disabled'), - DRUPAL_OPTIONAL => t('Optional'), - DRUPAL_REQUIRED => t('Required'), + DRUPAL_DISABLED => $this->t('Disabled'), + DRUPAL_OPTIONAL => $this->t('Optional'), + DRUPAL_REQUIRED => $this->t('Required'), ], ]; @@ -185,7 +185,7 @@ public function storageSettingsForm(array &$form, FormStateInterface $form_state } $element['comment_type'] = [ '#type' => 'select', - '#title' => t('Comment type'), + '#title' => $this->t('Comment type'), '#options' => $options, '#required' => TRUE, '#description' => $this->t('Select the Comment type to use for this comment field. Manage the comment types from the administration overview page.', [':url' => Url::fromRoute('entity.comment_type.collection')->toString()]), diff --git a/core/modules/comment/src/Plugin/Field/FieldWidget/CommentWidget.php b/core/modules/comment/src/Plugin/Field/FieldWidget/CommentWidget.php index c9478f622c..a7159513be 100644 --- a/core/modules/comment/src/Plugin/Field/FieldWidget/CommentWidget.php +++ b/core/modules/comment/src/Plugin/Field/FieldWidget/CommentWidget.php @@ -29,22 +29,22 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen $element['status'] = [ '#type' => 'radios', - '#title' => t('Comments'), + '#title' => $this->t('Comments'), '#title_display' => 'invisible', '#default_value' => $items->status, '#options' => [ - CommentItemInterface::OPEN => t('Open'), - CommentItemInterface::CLOSED => t('Closed'), - CommentItemInterface::HIDDEN => t('Hidden'), + CommentItemInterface::OPEN => $this->t('Open'), + CommentItemInterface::CLOSED => $this->t('Closed'), + CommentItemInterface::HIDDEN => $this->t('Hidden'), ], CommentItemInterface::OPEN => [ - '#description' => t('Users with the "Post comments" permission can post comments.'), + '#description' => $this->t('Users with the "Post comments" permission can post comments.'), ], CommentItemInterface::CLOSED => [ - '#description' => t('Users cannot post comments, but existing comments will be displayed.'), + '#description' => $this->t('Users cannot post comments, but existing comments will be displayed.'), ], CommentItemInterface::HIDDEN => [ - '#description' => t('Comments are hidden from view.'), + '#description' => $this->t('Comments are hidden from view.'), ], ]; // If the entity doesn't have any comments, the "hidden" option makes no @@ -53,7 +53,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen if (!$this->isDefaultValueWidget($form_state) && !$items->comment_count) { $element['status'][CommentItemInterface::HIDDEN]['#access'] = FALSE; // Also adjust the description of the "closed" option. - $element['status'][CommentItemInterface::CLOSED]['#description'] = t('Users cannot post comments.'); + $element['status'][CommentItemInterface::CLOSED]['#description'] = $this->t('Users cannot post comments.'); } // If the advanced settings tabs-set is available (normally rendered in the // second column on wide-resolutions), place the field as a details element