reverted: --- b/lib/Drupal/views/Tests/Node/RowPlugin.php +++ /dev/null @@ -1,145 +0,0 @@ - 'Node: Row plugin', - 'description' => 'Tests the node row plugin.', - 'group' => 'Views Modules', - ); - } - - protected function setUp() { - parent::setUp(); - - $this->drupalCreateContentType(array('type' => 'article')); - // Create two nodes, with 5 comments on all of them. - for ($i = 0; $i < 2; $i++) { - $this->nodes[] = $this->drupalCreateNode( - array( - 'type' => 'article', - 'body' => array( - LANGUAGE_NOT_SPECIFIED => array( - array( - 'value' => $this->randomName() . '' . $this->randomName(42), - 'format' => 'filtered_html' - ) - ) - ) - ) - ); - } - - foreach ($this->nodes as $node) { - for ($i = 0; $i < 5; $i++) { - $this->comments[$node->id()][] = $this->drupalCreateComment(array('nid' => $node->id())); - } - } - } - - /** - * Helper function to create a random comment. - */ - public function drupalCreateComment(array $settings = array()) { - $node = node_load($settings['nid']); - $settings += array( - 'subject' => $this->randomName(), - 'bundle' => "comment_node_{$node->type}", - 'comment_body' => array(LANGUAGE_NOT_SPECIFIED => array(array('value' => $this->randomName(40)))) - ); - - return entity_create('comment', $settings); - } - - /** - * Tests the node row plugin. - */ - public function testRowPlugin() { - $view = views_get_view('test_node_row_plugin'); - $view->initDisplay(); - $view->setDisplay('page'); - $view->initStyle(); - $view->style_plugin->row_plugin->options['view_mode'] = 'full'; - - $output = $view->preview(); - foreach ($this->nodes as $node) { - $body = $node->body; - list($teaser, $full) = explode('', $body[LANGUAGE_NOT_SPECIFIED][0]['value']); - $this->assertTrue(strpos($output, $teaser) !== FALSE. 'Make sure the teaser appears in the output of the view.'); - $this->assertTrue(strpos($output, $full) !== FALSE. 'Make sure the full text appears in the output of the view.'); - } - - $view->style_plugin->row_plugin->options['view_mode'] = 'teaser'; - $output = $view->preview(); - foreach ($this->nodes as $node) { - $body = $node->body; - list($teaser, $full) = explode('', $body[LANGUAGE_NOT_SPECIFIED][0]['value']); - $this->assertTrue(strpos($output, $teaser) !== FALSE. 'Make sure the teaser appears in the output of the view.'); - $this->assertFalse(strpos($output, $full) !== FALSE. 'Make sure the full text does not appears in the output of the view if teaser is set as viewmode.'); - } - - $view->style_plugin->row_plugin->options['links'] = FALSE; - $output = $view->preview(); - foreach ($this->nodes as $node) { - $this->assertFalse($this->xpathContent($output, '//li[contains(@class, :class)]/a[contains(@href, :href)]', array(':class' => 'node-readmore', ':href' => "node/{$node->id()}")), 'Make sure no readmore link appears.'); - } - - $view->style_plugin->row_plugin->options['links'] = TRUE; - $output = $view->preview(); - foreach ($this->nodes as $node) { - $this->assertTrue($this->xpathContent($output, '//li[contains(@class, :class)]/a[contains(@href, :href)]', array(':class' => 'node-readmore', ':href' => "node/{$node->id()}")), 'Make sure no readmore link appears.'); - } - - $view->style_plugin->row_plugin->options['comments'] = TRUE; - $output = $view->preview(); - debug($output); - foreach ($this->nodes as $node) { - foreach ($this->comments[$node->id()] as $comment) { - $this->assertTrue(strpos($output, $comment->comment_body[LANGUAGE_NOT_SPECIFIED][0]['value']) !== FALSE, 'Make sure the comment appears in the output.'); - } - } - - $view->style_plugin->row_plugin->options['comments'] = FALSE; - $output = $view->preview(); - foreach ($this->nodes as $node) { - foreach ($this->comments[$node->id()] as $comment) { - $this->assertFalse(strpos($output, $comment->comment_body[LANGUAGE_NOT_SPECIFIED][0]['value']) !== FALSE, 'Make sure the comment does not appears in the output when the comments option disabled.'); - } - } - } - -} reverted: --- b/lib/Views/node/Plugin/views/row/View.php +++ a/lib/Views/node/Plugin/views/row/View.php @@ -38,6 +38,18 @@ // Stores the nodes loaded with pre_render. var $nodes = array(); + public function init(ViewExecutable $view, &$display, $options = NULL) { + parent::init($view, $display, $options); + // Handle existing views with the deprecated 'teaser' option. + if (isset($this->options['teaser'])) { + $this->options['build_mode'] = $this->options['teaser'] ? 'teaser' : 'full'; + } + // Handle existing views which has used build_mode instead of view_mode. + if (isset($this->options['build_mode'])) { + $this->options['view_mode'] = $this->options['build_mode']; + } + } + protected function defineOptions() { $options = parent::defineOptions(); diff -u b/views.module b/views.module --- b/views.module +++ b/views.module @@ -406,6 +406,7 @@ * node portion of the theme registry. */ function views_preprocess_node(&$vars) { + module_load_include('inc', 'views', 'modules/node.views'); // The 'view' attribute of the node is added in views_preprocess_node() if (!empty($vars['node']->view) && !empty($vars['node']->view->storage->name)) { $vars['view'] = $vars['node']->view; @@ -416,14 +417,13 @@ * node portion of the theme registry. */ function views_preprocess_node(&$vars) { - module_load_include('inc', 'views', 'modules/node'); // The 'view' attribute of the node is added in views_preprocess_node() if (!empty($vars['node']->view) && !empty($vars['node']->view->storage->name)) { $vars['view'] = $vars['node']->view; } // Allow to alter comments and links based on the settings in the row plugin. - if (!empty($vars['view']->style_plugin->row_plugin) && get_class($vars['view']->style_plugin->row_plugin) == 'views_plugin_row_node_view') { + if (!empty($vars['view']->style_plugin->row_plugin) && $vars['view']->style_plugin->row_plugin->getPluginId() == 'node') { node_row_node_view_preprocess_node($vars); } } @@ -433,7 +433,7 @@ } // Allow to alter comments and links based on the settings in the row plugin. - if (!empty($vars['view']->style_plugin->row_plugin) && $vars['view']->style_plugin->row_plugin->getPluginId() == 'node') { + if (!empty($vars['view']->style_plugin->row_plugin) && get_class($vars['view']->style_plugin->row_plugin) == 'views_plugin_row_node_view') { node_row_node_view_preprocess_node($vars); } } only in patch2: unchanged: --- /dev/null +++ b/lib/Drupal/views/Tests/Node/RowPluginTest.php @@ -0,0 +1,194 @@ + 'Node: Row plugin', + 'description' => 'Tests the node row plugin.', + 'group' => 'Views Modules', + ); + } + + protected function setUp() { + parent::setUp(); + + $this->drupalCreateContentType(array('type' => 'article')); + + // Create two nodes, with 5 comments on all of them. + for ($i = 0; $i < 2; $i++) { + $this->nodes[] = $this->drupalCreateNode( + array( + 'type' => 'article', + 'body' => array( + LANGUAGE_NOT_SPECIFIED => array( + array( + 'value' => $this->randomName(42), + 'format' => 'filtered_html', + 'summary' => $this->randomName() + ) + ) + ) + ) + ); + } + + foreach ($this->nodes as $node) { + for ($i = 0; $i < 5; $i++) { + $this->comments[$node->id()][] = $this->drupalCreateComment(array('nid' => $node->id())); + } + } + + // Add text formats. + $filtered_html_format = array( + 'format' => 'filtered_html', + 'name' => 'Filtered HTML', + 'weight' => 0, + 'filters' => array( + // URL filter. + 'filter_url' => array( + 'weight' => 0, + 'status' => 1, + ), + // HTML filter. + 'filter_html' => array( + 'weight' => 1, + 'status' => 1, + ), + // Line break filter. + 'filter_autop' => array( + 'weight' => 2, + 'status' => 1, + ), + // HTML corrector filter. + 'filter_htmlcorrector' => array( + 'weight' => 10, + 'status' => 1, + ), + ), + ); + $filtered_html_format = (object) $filtered_html_format; + filter_format_save($filtered_html_format); + } + + /** + * Helper function to create a random comment. + * + * @return Drupal\comment\Comment + * Returns teh created comment. + */ + public function drupalCreateComment(array $settings = array()) { + $node = node_load($settings['nid']); + $settings += array( + 'subject' => $this->randomName(), + 'bundle' => "comment_node_{$node->type}", + 'comment_body' => array(LANGUAGE_NOT_SPECIFIED => array(array('value' => $this->randomName(40)))) + ); + + $comment = entity_create('comment', $settings); + $comment->save(); + return $comment; + } + + /** + * Tests the node row plugin. + */ + public function testRowPlugin() { + $view = views_get_view('test_node_row_plugin'); + $view->initDisplay(); + $view->setDisplay('page'); + $view->initStyle(); + $view->style_plugin->row_plugin->options['view_mode'] = 'full'; + + // Test with view_mode full. + $output = $view->preview(); + foreach ($this->nodes as $node) { + $body = $node->body; + $teaser = $body[LANGUAGE_NOT_SPECIFIED][0]['summary']; + $full = $body[LANGUAGE_NOT_SPECIFIED][0]['value']; + $this->assertFalse(strpos($output, $teaser) !== FALSE, 'Make sure the teaser appears in the output of the view.'); + $this->assertTrue(strpos($output, $full) !== FALSE, 'Make sure the full text appears in the output of the view.'); + } + + // Test with teasers. + $view->style_plugin->row_plugin->options['view_mode'] = 'teaser'; + $output = $view->preview(); + foreach ($this->nodes as $node) { + $body = $node->body; + $teaser = $body[LANGUAGE_NOT_SPECIFIED][0]['summary']; + $full = $body[LANGUAGE_NOT_SPECIFIED][0]['value']; + $this->assertTrue(strpos($output, $teaser) !== FALSE, 'Make sure the teaser appears in the output of the view.'); + $this->assertFalse(strpos($output, $full) !== 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->style_plugin->row_plugin->options['links'] = FALSE; + $output = $view->preview(); + foreach ($this->nodes as $node) { + $this->assertFalse($this->xpathContent($output, '//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->style_plugin->row_plugin->options['links'] = TRUE; + $output = $view->preview(); + foreach ($this->nodes as $node) { + $this->assertTrue($this->xpathContent($output, '//li[contains(@class, :class)]/a[contains(@href, :href)]', array(':class' => 'node-readmore', ':href' => "node/{$node->id()}")), 'Make sure no readmore link appears.'); + } + + // Tests with comments enabled. + $view->style_plugin->row_plugin->options['comments'] = TRUE; + $output = $view->preview(); + debug($output); + debug($this->comments); + foreach ($this->nodes as $node) { + foreach ($this->comments[$node->id()] as $comment) { + debug($comment->comment_body[LANGUAGE_NOT_SPECIFIED][0]['value']); + $this->assertTrue(strpos($output, $comment->comment_body[LANGUAGE_NOT_SPECIFIED][0]['value']) !== FALSE, 'Make sure the comment appears in the output.'); + } + } + + // Test with comments disabled. + $view->style_plugin->row_plugin->options['comments'] = FALSE; + $output = $view->preview(); + foreach ($this->nodes as $node) { + foreach ($this->comments[$node->id()] as $comment) { + $this->assertFalse(strpos($output, $comment->comment_body[LANGUAGE_NOT_SPECIFIED][0]['value']) !== FALSE, 'Make sure the comment does not appears in the output when the comments option disabled.'); + } + } + } + +}