diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 46a41f5257eadc39d5e6c150a8407441be461caf..5f6f906c93377cbfc14c09ccab2763562710bdcc 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -111,6 +111,12 @@ function comment_entity_extra_field_info() { ), ), ); + $return['comment'][$comment_type->id()]['display']['links'] = array( + 'label' => t('Links'), + 'description' => t('Comment operation links'), + 'weight' => 100, + 'visible' => TRUE, + ); } return $return; diff --git a/core/modules/comment/src/CommentViewBuilder.php b/core/modules/comment/src/CommentViewBuilder.php index fc8da5e984cef413b643ab23d2f2f1745099bc18..d2d6290c389c0ce0eb2a912b08a7b0f3c4f26aa5 100644 --- a/core/modules/comment/src/CommentViewBuilder.php +++ b/core/modules/comment/src/CommentViewBuilder.php @@ -111,24 +111,28 @@ public function buildComponents(array &$build, array $entities, array $displays, } $build[$id]['#entity'] = $entity; $build[$id]['#theme'] = 'comment__' . $entity->getFieldName() . '__' . $commented_entity->bundle(); - $callback = '\Drupal\comment\CommentViewBuilder::renderLinks'; - $context = array( - 'comment_entity_id' => $entity->id(), - 'view_mode' => $view_mode, - 'langcode' => $langcode, - 'commented_entity_type' => $commented_entity->getEntityTypeId(), - 'commented_entity_id' => $commented_entity->id(), - 'in_preview' => !empty($entity->in_preview), - ); - $placeholder = drupal_render_cache_generate_placeholder($callback, $context); - $build[$id]['links'] = array( - '#post_render_cache' => array( - $callback => array( - $context, + + $display = $displays[$entity->bundle()]; + if ($display->getComponent('links')) { + $callback = '\Drupal\comment\CommentViewBuilder::renderLinks'; + $context = array( + 'comment_entity_id' => $entity->id(), + 'view_mode' => $view_mode, + 'langcode' => $langcode, + 'commented_entity_type' => $commented_entity->getEntityTypeId(), + 'commented_entity_id' => $commented_entity->id(), + 'in_preview' => !empty($entity->in_preview), + ); + $placeholder = drupal_render_cache_generate_placeholder($callback, $context); + $build[$id]['links'] = array( + '#post_render_cache' => array( + $callback => array( + $context, + ), ), - ), - '#markup' => $placeholder, - ); + '#markup' => $placeholder, + ); + } $account = comment_prepare_author($entity); if (\Drupal::config('user.settings')->get('signatures') && $account->getSignature()) { diff --git a/core/modules/comment/src/Plugin/views/row/CommentRow.php b/core/modules/comment/src/Plugin/views/row/CommentRow.php deleted file mode 100644 index 5256b5662cce84bd53d1c483f6c6c37f403a61e5..0000000000000000000000000000000000000000 --- a/core/modules/comment/src/Plugin/views/row/CommentRow.php +++ /dev/null @@ -1,56 +0,0 @@ - TRUE); - $options['view_mode']['default'] = 'full'; - return $options; - } - - /** - * {@inheritdoc} - */ - public function buildOptionsForm(&$form, FormStateInterface $form_state) { - parent::buildOptionsForm($form, $form_state); - - $form['links'] = array( - '#type' => 'checkbox', - '#title' => t('Display links'), - '#default_value' => $this->options['links'], - ); - } - - /** - * {@inheritdoc} - */ - public function render($row) { - $build = parent::render($row); - if (!$this->options['links']) { - unset($build['links']); - } - return $build; - } - -} diff --git a/core/modules/comment/src/Plugin/views/row/Rss.php b/core/modules/comment/src/Plugin/views/row/Rss.php index d24eefe25d3ab2d7d4d44ac80beb88d43511b0f5..50354fbace3377f65d8d6d4797a91740349e81f7 100644 --- a/core/modules/comment/src/Plugin/views/row/Rss.php +++ b/core/modules/comment/src/Plugin/views/row/Rss.php @@ -32,7 +32,6 @@ protected function defineOptions() { $options = parent::defineOptions(); $options['view_mode'] = array('default' => 'default'); - $options['links'] = array('default' => FALSE, 'bool' => TRUE); return $options; } @@ -46,11 +45,6 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { '#options' => $this->options_form_summary_options(), '#default_value' => $this->options['view_mode'], ); - $form['links'] = array( - '#type' => 'checkbox', - '#title' => t('Display links'), - '#default_value' => $this->options['links'], - ); } public function preRender($result) { @@ -134,14 +128,8 @@ public function render($row) { $this->view->style_plugin->namespaces = array_merge($this->view->style_plugin->namespaces, $comment->rss_namespaces); } - // Hide the links if desired. - if (!$this->options['links']) { - hide($build['links']); - } - if ($view_mode != 'title') { - // We render comment contents and force links to be last. - $build['links']['#weight'] = 1000; + // We render comment contents. $item_text .= drupal_render($build); } diff --git a/core/modules/comment/src/Tests/CommentLinksTest.php b/core/modules/comment/src/Tests/CommentLinksTest.php index bc4f60dff37cbd0b3e3a8e4468e954c7cb592d01..00484b60b22f724d55f5445e2803820f884a52c4 100644 --- a/core/modules/comment/src/Tests/CommentLinksTest.php +++ b/core/modules/comment/src/Tests/CommentLinksTest.php @@ -10,6 +10,7 @@ use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\comment\CommentInterface; +use Drupal\entity\Entity\EntityViewDisplay; /** * Basic comment links tests to ensure markup present. @@ -42,16 +43,7 @@ class CommentLinksTest extends CommentTestBase { public static $modules = array('views'); /** - * Tests comment links. - * - * The output of comment links depends on various environment conditions: - * - Various Comment module configuration settings, user registration - * settings, and user access permissions. - * - Whether the user is authenticated or not, and whether any comments exist. - * - * To account for all possible cases, this test creates permutations of all - * possible conditions and tests the expected appearance of comment links in - * each environment. + * Tests that comment links are output and can be hidden. */ public function testCommentLinks() { // Bartik theme alters comment links, so use a different theme. @@ -112,6 +104,27 @@ public function testCommentLinks() { } $this->assertLink('Add new comment'); } + + // Make sure we can hide node links. + entity_get_display('node', $this->node->bundle(), 'default') + ->removeComponent('links') + ->save(); + $this->drupalGet($this->node->url()); + $this->assertNoLink('1 comment'); + $this->assertNoLink('Add new comment'); + + // Visit the full node, make sure there are links for the comment. + $this->drupalGet('node/' . $this->node->id()); + $this->assertText($comment->getSubject()); + $this->assertLink('Reply'); + + // Make sure we can hide comment links. + entity_get_display('comment', 'comment', 'default') + ->removeComponent('links') + ->save(); + $this->drupalGet('node/' . $this->node->id()); + $this->assertText($comment->getSubject()); + $this->assertNoLink('Reply'); } } diff --git a/core/modules/comment/templates/comment.html.twig b/core/modules/comment/templates/comment.html.twig index 7ffb7c006b867a18a63db007b9727f0554bf1ba7..575510fd7ddccb44130fe0ff4c9de0bc68823141 100644 --- a/core/modules/comment/templates/comment.html.twig +++ b/core/modules/comment/templates/comment.html.twig @@ -107,5 +107,7 @@ {% endif %} - {{ content.links }} + {% if content.links %} + {{ content.links }} + {% endif %} diff --git a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_row.yml b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_row.yml index c8e296491c96f17b70baa5c31ed14536087c9279..ad1e74e47611945fdbfd1a35333290265f0edf20 100644 --- a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_row.yml +++ b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_row.yml @@ -68,7 +68,6 @@ display: row: type: 'entity:comment' options: - links: true view_mode: full relationships: node: diff --git a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_field_filters.yml b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_field_filters.yml index aa730124edb5d28c4bcaed72848aca784cbf29a2..a743eea1b2fde4548f4f81766eb1ef8c6dd87ea6 100644 --- a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_field_filters.yml +++ b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_field_filters.yml @@ -63,8 +63,7 @@ display: row: type: 'entity:comment' options: - links: true - view_mode: full + view_mode: default rendering_language: translation_language_renderer relationships: node: diff --git a/core/modules/entity_reference/src/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php b/core/modules/entity_reference/src/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php index e52e0edf0f024ff58d5cc564950872dfc39668a8..f975b571c634b4a97ada634ece20cdb2b4926f10 100644 --- a/core/modules/entity_reference/src/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php +++ b/core/modules/entity_reference/src/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php @@ -48,12 +48,6 @@ public function settingsForm(array $form, FormStateInterface $form_state) { '#required' => TRUE, ); - $elements['links'] = array( - '#type' => 'checkbox', - '#title' => t('Show links'), - '#default_value' => $this->getSetting('links'), - ); - return $elements; } @@ -66,7 +60,6 @@ public function settingsSummary() { $view_modes = \Drupal::entityManager()->getViewModeOptions($this->getFieldSetting('target_type')); $view_mode = $this->getSetting('view_mode'); $summary[] = t('Rendered as @mode', array('@mode' => isset($view_modes[$view_mode]) ? $view_modes[$view_mode] : $view_mode)); - $summary[] = $this->getSetting('links') ? t('Display links') : t('Do not display links'); return $summary; } @@ -76,9 +69,6 @@ public function settingsSummary() { */ public function viewElements(FieldItemListInterface $items) { $view_mode = $this->getSetting('view_mode'); - $links = $this->getSetting('links'); - - $target_type = $this->getFieldSetting('target_type'); $elements = array(); @@ -97,10 +87,6 @@ public function viewElements(FieldItemListInterface $items) { if (!empty($item->target_id)) { $elements[$delta] = entity_view($item->entity, $view_mode, $item->getLangcode()); - if (empty($links) && isset($result[$delta][$target_type][$item->target_id]['links'])) { - // Hide the element links. - $elements[$delta][$target_type][$item->target_id]['links']['#access'] = FALSE; - } // Add a resource attribute to set the mapping property's value to the // entity's url. Since we don't know what the markup of the entity will // be, we shouldn't rely on it for structured data such as RDFa. diff --git a/core/modules/node/config/install/views.view.archive.yml b/core/modules/node/config/install/views.view.archive.yml index f8dd979929f898488118df2a05e5f6509ebbabe0..450868f34de04557f3743214b74435b0a52085e9 100644 --- a/core/modules/node/config/install/views.view.archive.yml +++ b/core/modules/node/config/install/views.view.archive.yml @@ -116,7 +116,6 @@ display: type: 'entity:node' options: view_mode: teaser - links: true comments: false provider: node header: { } diff --git a/core/modules/node/config/install/views.view.frontpage.yml b/core/modules/node/config/install/views.view.frontpage.yml index 3a3dbcb546555d27bcc18803a18dcac8835b3001..f178b968a723889e6224900e11afebafe60c0aca 100644 --- a/core/modules/node/config/install/views.view.frontpage.yml +++ b/core/modules/node/config/install/views.view.frontpage.yml @@ -196,7 +196,6 @@ display: options: build_mode: teaser comments: false - links: true view_mode: teaser provider: views sorts: @@ -284,7 +283,6 @@ display: options: relationship: none view_mode: rss - links: false provider: views field_langcode: '***LANGUAGE_language_content***' field_langcode_add_to_query: null diff --git a/core/modules/node/config/schema/node.views.schema.yml b/core/modules/node/config/schema/node.views.schema.yml index bc95945ef330fb2e1424da1f59ee9e0c6b03aa0d..a672177a091813b303e02b9622835e368425ae8c 100644 --- a/core/modules/node/config/schema/node.views.schema.yml +++ b/core/modules/node/config/schema/node.views.schema.yml @@ -4,9 +4,6 @@ type: views_entity_row label: 'Entity options' mapping: - links: - type: boolean - label: 'Display links' comments: type: boolean label: 'Show comments' @@ -253,6 +250,3 @@ views.row.node_rss: view_mode: type: string label: 'Display type' - links: - type: boolean - label: 'Display links' diff --git a/core/modules/node/node.module b/core/modules/node/node.module index d96052d3200fcea8d770f47b41abfb66ea20c4ec..d8882ccc6182e8d82aa7e821a8342b2da3481022 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -432,6 +432,12 @@ function node_entity_extra_field_info() { 'weight' => 0, 'visible' => FALSE, ); + $extra['node'][$bundle->type]['display']['links'] = array( + 'label' => t('Links'), + 'description' => $description, + 'weight' => 100, + 'visible' => TRUE, + ); } return $extra; diff --git a/core/modules/node/src/NodeViewBuilder.php b/core/modules/node/src/NodeViewBuilder.php index 606ef36a7b7ae65bac76aea184a36c6d44ef37c0..74c79c746a3e2ace0f753465d5c90ff9bc178766 100644 --- a/core/modules/node/src/NodeViewBuilder.php +++ b/core/modules/node/src/NodeViewBuilder.php @@ -34,23 +34,24 @@ public function buildComponents(array &$build, array $entities, array $displays, $bundle = $entity->bundle(); $display = $displays[$bundle]; - $callback = '\Drupal\node\NodeViewBuilder::renderLinks'; - $context = array( - 'node_entity_id' => $entity->id(), - 'view_mode' => $view_mode, - 'langcode' => $langcode, - 'in_preview' => !empty($entity->in_preview), - ); - $placeholder = drupal_render_cache_generate_placeholder($callback, $context); - $build[$id]['links'] = array( - '#post_render_cache' => array( - $callback => array( - $context, + if ($display->getComponent('links')) { + $callback = '\Drupal\node\NodeViewBuilder::renderLinks'; + $context = array( + 'node_entity_id' => $entity->id(), + 'view_mode' => $view_mode, + 'langcode' => $langcode, + 'in_preview' => !empty($entity->in_preview), + ); + $placeholder = drupal_render_cache_generate_placeholder($callback, $context); + $build[$id]['links'] = array( + '#post_render_cache' => array( + $callback => array( + $context, + ), ), - ), - '#markup' => $placeholder, - ); - + '#markup' => $placeholder, + ); + } // Add Language field text element to node render array. if ($display->getComponent('langcode')) { diff --git a/core/modules/node/src/Plugin/views/row/NodeRow.php b/core/modules/node/src/Plugin/views/row/NodeRow.php index c79691fd39a975efece6be483c2ba23d7c11b26d..c8cd7c0117ea8c59e0501bd5709ae92432e8ef09 100644 --- a/core/modules/node/src/Plugin/views/row/NodeRow.php +++ b/core/modules/node/src/Plugin/views/row/NodeRow.php @@ -7,7 +7,6 @@ namespace Drupal\node\Plugin\views\row; -use Drupal\Core\Form\FormStateInterface; use Drupal\views\Plugin\views\row\EntityRow; /** @@ -31,22 +30,7 @@ protected function defineOptions() { $options['view_mode']['default'] = 'teaser'; - $options['links'] = array('default' => TRUE, 'bool' => TRUE); - return $options; } - /** - * {@inheritdoc} - */ - public function buildOptionsForm(&$form, FormStateInterface $form_state) { - parent::buildOptionsForm($form, $form_state); - - $form['links'] = array( - '#type' => 'checkbox', - '#title' => t('Display links'), - '#default_value' => $this->options['links'], - ); - } - } diff --git a/core/modules/node/src/Plugin/views/row/Rss.php b/core/modules/node/src/Plugin/views/row/Rss.php index 9d3db7b16c1c84afd75e2cf3d26671a5828c5d01..820f9fbfe469f3bb6185f41f48c41d3ec49a26f2 100644 --- a/core/modules/node/src/Plugin/views/row/Rss.php +++ b/core/modules/node/src/Plugin/views/row/Rss.php @@ -40,7 +40,6 @@ protected function defineOptions() { $options = parent::defineOptions(); $options['view_mode'] = array('default' => 'default'); - $options['links'] = array('default' => FALSE, 'bool' => TRUE); return $options; } @@ -54,11 +53,6 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { '#options' => $this->buildOptionsForm_summary_options(), '#default_value' => $this->options['view_mode'], ); - $form['links'] = array( - '#type' => 'checkbox', - '#title' => t('Display links'), - '#default_value' => $this->options['links'], - ); } /** @@ -152,14 +146,8 @@ public function render($row) { $this->view->style_plugin->namespaces += $xml_rdf_namespaces; } - // Hide the links if desired. - if (!$this->options['links']) { - hide($build['links']); - } - if ($display_mode != 'title') { - // We render node contents and force links to be last. - $build['links']['#weight'] = 1000; + // We render node contents. $item_text .= drupal_render($build); } diff --git a/core/modules/node/src/Tests/NodeLinksTest.php b/core/modules/node/src/Tests/NodeLinksTest.php new file mode 100644 index 0000000000000000000000000000000000000000..4c0efa7c3b00b6f0c12034878da95764e9efa5c9 --- /dev/null +++ b/core/modules/node/src/Tests/NodeLinksTest.php @@ -0,0 +1,47 @@ +drupalCreateNode(array( + 'type' => 'article', + 'promote' => NODE_PROMOTED, + )); + + // Links are displayed by default. + $this->drupalGet('node'); + $this->assertText($node->getTitle()); + $this->assertLink('Read more'); + + // Hide links. + entity_get_display('node', 'article', 'teaser') + ->removeComponent('links') + ->save(); + + $this->drupalGet('node'); + $this->assertText($node->getTitle()); + $this->assertNoLink('Read more'); + } + +} diff --git a/core/modules/node/src/Tests/Views/NodeFieldFilterTest.php b/core/modules/node/src/Tests/Views/NodeFieldFilterTest.php index d7ffc0374ef7d9cfb5048f54faf3a41b3c48a4a4..9460c7b80b97075efc6c8655dbb095dc05656147 100644 --- a/core/modules/node/src/Tests/Views/NodeFieldFilterTest.php +++ b/core/modules/node/src/Tests/Views/NodeFieldFilterTest.php @@ -112,6 +112,9 @@ public function testFilters() { * Message suffix to display. */ protected function assertPageCounts($path, $counts, $message) { + // Disable read more links. + entity_get_display('node', 'page', 'teaser')->removeComponent('links')->save(); + // Get the text of the page. $this->drupalGet($path); $text = $this->getTextContent(); diff --git a/core/modules/node/src/Tests/Views/RowPluginTest.php b/core/modules/node/src/Tests/Views/RowPluginTest.php index 4813bd68280e9b7e832f29fc87fe4ca40595fa64..c9dd7f1bc987303230ff2149c689eadc2507018e 100644 --- a/core/modules/node/src/Tests/Views/RowPluginTest.php +++ b/core/modules/node/src/Tests/Views/RowPluginTest.php @@ -125,27 +125,6 @@ public function testRowPlugin() { $this->assertTrue(strpos($output, $node->body->summary) !== FALSE, 'Make sure the teaser appears in the output of the view.'); $this->assertFalse(strpos($output, $node->body->value) !== FALSE, 'Make sure the full text does not appears in the output of the view if teaser is set as viewmode.'); } - - // Test with links disabled. - $view->rowPlugin->options['links'] = FALSE; - \Drupal::entityManager()->getViewBuilder('node')->resetCache(); - $output = $view->preview(); - $output = drupal_render($output); - $this->drupalSetContent($output); - foreach ($this->nodes as $node) { - $this->assertFalse($this->xpath('//li[contains(@class, :class)]/a[contains(@href, :href)]', array(':class' => 'node-readmore', ':href' => "node/{$node->id()}")), 'Make sure no readmore link appears.'); - } - - // Test with links enabled. - $view->rowPlugin->options['links'] = TRUE; - \Drupal::entityManager()->getViewBuilder('node')->resetCache(); - $output = $view->preview(); - $output = drupal_render($output); - $this->drupalSetContent($output); - foreach ($this->nodes as $node) { - $this->assertTrue($this->xpath('//li[contains(@class, :class)]/a[contains(@href, :href)]', array(':class' => 'node-readmore', ':href' => "node/{$node->id()}")), 'Make sure no readmore link appears.'); - } - } } diff --git a/core/modules/node/tests/modules/node_test_views/test_views/views.view.test_contextual_links.yml b/core/modules/node/tests/modules/node_test_views/test_views/views.view.test_contextual_links.yml index 8aaab2c2b3bccf533b2fe571c4c94472a930579a..1850ce6a8f151f27b91379e69284422161e94814 100644 --- a/core/modules/node/tests/modules/node_test_views/test_views/views.view.test_contextual_links.yml +++ b/core/modules/node/tests/modules/node_test_views/test_views/views.view.test_contextual_links.yml @@ -47,7 +47,6 @@ display: options: build_mode: teaser comments: false - links: true view_mode: teaser style: type: default diff --git a/core/modules/node/tests/modules/node_test_views/test_views/views.view.test_node_row_plugin.yml b/core/modules/node/tests/modules/node_test_views/test_views/views.view.test_node_row_plugin.yml index 4efc395a86fb8493fba8c51fb912b28eeeb824b1..036b80bbb4fa9f35c05ebb4503d2a0094726c6dd 100644 --- a/core/modules/node/tests/modules/node_test_views/test_views/views.view.test_node_row_plugin.yml +++ b/core/modules/node/tests/modules/node_test_views/test_views/views.view.test_node_row_plugin.yml @@ -33,7 +33,6 @@ display: options: build_mode: teaser comments: false - links: true type: 'entity:node' sorts: { } style: diff --git a/core/modules/taxonomy/config/install/views.view.taxonomy_term.yml b/core/modules/taxonomy/config/install/views.view.taxonomy_term.yml index b008800f93e11d67b0af6f34a05a2da34a0e6e67..db374a8f89f74f16b6dd79559f3c35c203e8a2f4 100644 --- a/core/modules/taxonomy/config/install/views.view.taxonomy_term.yml +++ b/core/modules/taxonomy/config/install/views.view.taxonomy_term.yml @@ -171,7 +171,6 @@ display: type: 'entity:node' options: view_mode: teaser - links: true comments: false provider: views header: { } @@ -238,7 +237,6 @@ display: options: relationship: none view_mode: default - links: false provider: views label: 'Taxonomy term' module: taxonomy diff --git a/core/modules/views/views.module b/core/modules/views/views.module index 5a30bf09c19798719b1b95f52049815bbefb3c7c..b4da2d954e804b325487f6eb51d865bf31d8368a 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -246,11 +246,6 @@ function views_preprocess_node(&$variables) { $variables['page'] = FALSE; } } - - // Allow to alter comments and links based on the settings in the row plugin. - if (!empty($variables['view']->rowPlugin) && $variables['view']->rowPlugin->getPluginId() == 'entity:node') { - node_row_node_view_preprocess_node($variables); - } } /** diff --git a/core/themes/bartik/templates/comment.html.twig b/core/themes/bartik/templates/comment.html.twig index c00a9c5287476ceb29a5960c8a8e4b6b66dc889a..7a22fc000cd5266242ead9c97e20035f55f1a4cf 100644 --- a/core/themes/bartik/templates/comment.html.twig +++ b/core/themes/bartik/templates/comment.html.twig @@ -119,9 +119,11 @@ {% endif %} - + {% if content.links %} + + {% endif %}