diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install index a4bbc9f..2f021d7 100644 --- a/core/modules/comment/comment.install +++ b/core/modules/comment/comment.install @@ -6,6 +6,8 @@ */ use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\StringTranslation\PluralTranslatableMarkup; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\field\Entity\FieldStorageConfig; /** @@ -129,11 +131,17 @@ function comment_update_8001() { */ /** + * @addtogroup updates-8.1.0 + * @{ + */ + +/** * Adds the new 'view_mode' setting to all view displays using the * 'comment_default' formatter. */ function comment_update_8101() { $config_factory = \Drupal::configFactory(); + $displays = []; // Iterate on all entity view displays. foreach ($config_factory->listAll('core.entity_view_display.') as $name) { $changed = FALSE; @@ -143,6 +151,7 @@ function comment_update_8101() { if (isset($component['type']) && ($component['type'] === 'comment_default')) { if (empty($display->get("content.{$field_name}.settings.view_mode"))) { $display->set("content.{$field_name}.settings.view_mode", 'default'); + $displays[] = $display->get('id'); $changed = TRUE; } } @@ -153,4 +162,14 @@ function comment_update_8101() { } } + if ($displays) { + return new PluralTranslatableMarkup(count($displays), '1 entity display updated: @displays.', '@count entity displays updated: @displays.', ['@displays', implode(', ', $displays)]); + } + else { + return new TranslatableMarkup('No entity view display updated.'); + } } + +/** + * @} End of "addtogroup updates-8.1.0". + */ diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 7086b17..06ea374 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -763,7 +763,7 @@ function comment_ranking() { */ function comment_entity_view_display_presave(EntityViewDisplayInterface $display) { // Act only on comment view displays being disabled. - if ($display->isNew() || $display->getTargetEntityTypeId() != 'comment' || $display->status()) { + if ($display->isNew() || $display->getTargetEntityTypeId() !== 'comment' || $display->status()) { return; } $storage = \Drupal::entityTypeManager()->getStorage('entity_view_display'); @@ -776,8 +776,8 @@ function comment_entity_view_display_presave(EntityViewDisplayInterface $display $changed = FALSE; /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $view_display */ foreach ($view_display->getComponents() as $field => $component) { - if (isset($component['type']) && ($component['type'] == 'comment_default')) { - if ($component['settings']['view_mode'] == $display->getMode()) { + if (isset($component['type']) && ($component['type'] === 'comment_default')) { + if ($component['settings']['view_mode'] === $display->getMode()) { $view_display->removeComponent($field); /** @var \Drupal\Core\Entity\EntityViewModeInterface $mode */ $mode = EntityViewMode::load($display->getTargetEntityTypeId() . '.' . $display->getMode()); @@ -787,7 +787,7 @@ function comment_entity_view_display_presave(EntityViewDisplayInterface $display '@display' => $mode->label(), '@mode' => $display->getMode(), ]; - \Drupal::logger('system')->warning("View display '@id': Comment field formatter '@name' was disabled because is using the comment view display '@display' (@mode) that was just disabled.", $arguments); + \Drupal::logger('system')->warning("View display '@id': Comment field formatter '@name' was disabled because it is using the comment view display '@display' (@mode) that was just disabled.", $arguments); $changed = TRUE; } } diff --git a/core/modules/comment/src/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php b/core/modules/comment/src/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php index cdd68f6..e32924f 100644 --- a/core/modules/comment/src/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php +++ b/core/modules/comment/src/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php @@ -209,22 +209,15 @@ public function viewElements(FieldItemListInterface $items, $langcode) { public function settingsForm(array $form, FormStateInterface $form_state) { $element = array(); $view_modes = $this->getViewModes(); - // Only show the select element when there are more than one options. - if (count($view_modes) > 1) { - $element['view_mode'] = [ - '#type' => 'select', - '#title' => $this->t('Comments view mode'), - '#description' => $this->t('Select the view mode used to show the list of comments.'), - '#default_value' => $this->getSetting('view_mode'), - '#options' => $view_modes, - ]; - } - else { - $element['view_mode'] = [ - '#type' => 'value', - '#value' => 'default', - ]; - } + $element['view_mode'] = [ + '#type' => 'select', + '#title' => $this->t('Comments view mode'), + '#description' => $this->t('Select the view mode used to show the list of comments.'), + '#default_value' => $this->getSetting('view_mode'), + '#options' => $view_modes, + // Only show the select element when there are more than one options. + '#access' => count($view_modes) > 1, + ]; $element['pager_id'] = array( '#type' => 'select', '#title' => $this->t('Pager ID'),