Commit 05212a97 authored by Dries's avatar Dries

Issue #2271349 by Berdir, Arla, blueminds, larowlan, Dave Reid: Node and...

Issue #2271349 by Berdir, Arla, blueminds, larowlan, Dave Reid: Node and Comment ops links should be display components (which can be disabled).
parent 0ede95dd
......@@ -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;
......
......@@ -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()) {
......
<?php
/**
* @file
* Contains \Drupal\comment\Plugin\views\row\CommentRow.
*/
namespace Drupal\comment\Plugin\views\row;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\row\EntityRow;
/**
* Plugin which performs a comment_view on the resulting object.
*
* @ViewsRow(
* id = "entity:comment",
* )
*/
class CommentRow extends EntityRow {
/**
* {@inheritdoc}
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['links'] = array('default' => 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;
}
}
......@@ -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);
}
......
......@@ -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');
}
}
......@@ -107,5 +107,7 @@
</div>
{% endif %}
</div>
{{ content.links }}
{% if content.links %}
{{ content.links }}
{% endif %}
</article>
......@@ -68,7 +68,6 @@ display:
row:
type: 'entity:comment'
options:
links: true
view_mode: full
relationships:
node:
......
......@@ -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:
......
......@@ -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.
......
......@@ -116,7 +116,6 @@ display:
type: 'entity:node'
options:
view_mode: teaser
links: true
comments: false
provider: node
header: { }
......
......@@ -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
......@@ -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'
......@@ -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;
......
......@@ -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')) {
......
......@@ -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'],
);
}
}
......@@ -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);
}
......
<?php
/**
* @file
* Contains \Drupal\node\Tests\NodeLinksTest
*/
namespace Drupal\node\Tests;
/**
* Tests the output of node links (read more, add new comment, etc).
*
* @group node
*/
class NodeLinksTest extends NodeTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('views');
/**
* Tests that the links can be hidden in the view display settings.
*/
public function testHideLinks() {
$node = $this->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');
}
}
......@@ -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();
......
......@@ -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.');
}
}
}
......@@ -47,7 +47,6 @@ display:
options:
build_mode: teaser
comments: false
links: true
view_mode: teaser
style:
type: default
......
......@@ -33,7 +33,6 @@ display:
options:
build_mode: teaser
comments: false
links: true
type: 'entity:node'
sorts: { }
style:
......
......@@ -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
......
......@@ -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);
}
}
/**
......
......@@ -119,9 +119,11 @@
</div>
{% endif %}
<nav>
{{ content.links }}
</nav>
{% if content.links %}
<nav>
{{ content.links }}
</nav>
{% endif %}
</footer> <!-- /.comment-footer -->
</div> <!-- /.comment-text -->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment