diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessBaseTableTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessBaseTableTest.php index f227792..a8e3b7a 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAccessBaseTableTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessBaseTableTest.php @@ -17,7 +17,7 @@ class NodeAccessBaseTableTest extends NodeTestBase { * * @var array */ - public static $modules = array('node_access_test'); + public static $modules = array('node_access_test', 'views'); /** * The installation profile to use with this test. diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 6b77d21..1f96d7d 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -1201,7 +1201,6 @@ function node_view_multiple($nodes, $view_mode = 'teaser', $langcode = NULL) { * default setting for number of posts to show on node listing pages. * * @see node_page_default() - * @see taxonomy_term_page() * @see node_form_system_site_information_settings_form_submit() */ function node_form_system_site_information_settings_form_alter(&$form, &$form_state, $form_id) { diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyAttributesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyAttributesTest.php index 1172fbc..d63101b 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyAttributesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyAttributesTest.php @@ -19,7 +19,7 @@ class TaxonomyAttributesTest extends TaxonomyTestBase { * * @var array */ - public static $modules = array('rdf'); + public static $modules = array('rdf', 'views'); public static function getInfo() { return array( diff --git a/core/modules/taxonomy/config/install/entity.view_mode.taxonomy_term.full.yml b/core/modules/taxonomy/config/install/entity.view_mode.taxonomy_term.full.yml index 50b1854..bb8c47e 100644 --- a/core/modules/taxonomy/config/install/entity.view_mode.taxonomy_term.full.yml +++ b/core/modules/taxonomy/config/install/entity.view_mode.taxonomy_term.full.yml @@ -1,6 +1,6 @@ id: taxonomy_term.full label: 'Taxonomy term page' -status: false +status: true cache: true targetEntityType: taxonomy_term dependencies: 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 6477894..a3210ef 100644 --- a/core/modules/taxonomy/config/install/views.view.taxonomy_term.yml +++ b/core/modules/taxonomy/config/install/views.view.taxonomy_term.yml @@ -2,7 +2,7 @@ base_field: nid base_table: node core: '8' description: 'Content belonging to a certain taxonomy term.' -status: false +status: true display: default: id: default @@ -175,7 +175,21 @@ display: links: true comments: false provider: views - header: { } + header: + entity_taxonomy_term: + id: entity_taxonomy_term + table: views + field: entity_taxonomy_term + relationship: none + group_type: group + admin_label: '' + empty: true + tokenize: 1 + entity_id: '!1' + view_mode: full + bypass_access: 0 + plugin_id: entity + provider: views footer: { } empty: { } relationships: { } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TaxonomyController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TaxonomyController.php index 0312a9d..b8f5b0e 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TaxonomyController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TaxonomyController.php @@ -19,6 +19,19 @@ class TaxonomyController extends ControllerBase { /** + * Title callback for term pages. + * + * @param \Drupal\taxonomy\TermInterface $term + * A taxonomy term entity. + * + * @return + * The term name to be used as the page title. + */ + public function getTitle(TermInterface $term) { + return $term->label(); + } + + /** * Returns a rendered edit form to create a new term associated to the given vocabulary. * * @param \Drupal\taxonomy\VocabularyInterface $taxonomy_vocabulary @@ -36,15 +49,6 @@ public function addForm(VocabularyInterface $taxonomy_vocabulary) { } /** - * @todo Remove taxonomy_term_page(). - */ - public function termPage(TermInterface $taxonomy_term) { - module_load_include('pages.inc', 'taxonomy'); - return taxonomy_term_page($taxonomy_term); - - } - - /** * Route title callback. * * @param \Drupal\taxonomy\VocabularyInterface $taxonomy_vocabulary @@ -71,11 +75,23 @@ public function termTitle(TermInterface $taxonomy_term) { } /** - * @todo Remove taxonomy_term_feed(). + * Generate the content feed for a taxonomy term. + * + * @param \Drupal\taxonomy\TermInterface $term + * The taxonomy term entity. + * + * @return \Symfony\Component\HttpFoundation\Response + * A response object. */ public function termFeed(TermInterface $taxonomy_term) { - module_load_include('pages.inc', 'taxonomy'); - return taxonomy_term_feed($taxonomy_term); + $channel['link'] = $this->url('taxonomy.term_page', array('taxonomy_term' => $taxonomy_term->id()), array('absolute' => TRUE)); + $channel['title'] = \Drupal::config('system.site')->get('name') . ' - ' . $taxonomy_term->label(); + // Only display the description if we have a single term, to avoid clutter and confusion. + // HTML will be removed from feed description. + $channel['description'] = check_markup($taxonomy_term->description->value, $taxonomy_term->description->format, '', TRUE); + $nids = taxonomy_select_nodes($taxonomy_term->id(), FALSE, \Drupal::config('system.rss')->get('items.limit')); + + return node_feed($nids, $channel); } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php index e79d159..f99cc6a 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php @@ -207,6 +207,7 @@ function testTaxonomyIndex() { * Tests that there is a link to the parent term on the child term page. */ function testTaxonomyTermHierarchyBreadcrumbs() { + \Drupal::moduleHandler()->install(array('views')); // Create two taxonomy terms and set term2 as the parent of term1. $term1 = $this->createTerm($this->vocabulary); $term2 = $this->createTerm($this->vocabulary); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php index 966d45a..23dc07d 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php @@ -300,6 +300,7 @@ function testTermAutocompletion() { * Save, edit and delete a term using the user interface. */ function testTermInterface() { + \Drupal::moduleHandler()->install(array('views')); $edit = array( 'name[0][value]' => $this->randomName(12), 'description[0][value]' => $this->randomName(100), diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index f1db93f..132cab9 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -16,6 +16,7 @@ use Drupal\taxonomy\Entity\Vocabulary; use Drupal\taxonomy\VocabularyInterface; use Drupal\Component\Utility\String; +use Symfony\Cmf\Component\Routing\RouteObjectInterface; /** * Denotes that no term in the vocabulary has a parent. @@ -134,6 +135,36 @@ function taxonomy_term_uri($term) { } /** + * Implements hook_page_build(). + */ +function taxonomy_page_build(&$page) { + if (\Drupal::request()->attributes->get(RouteObjectInterface::ROUTE_NAME) == 'taxonomy.term_page') { + $term = \Drupal::request()->attributes->get('taxonomy_term'); + foreach ($term->uriRelationships() as $rel) { + // Set the term path as the canonical URL to prevent duplicate content. + $page['#attached']['drupal_add_html_head_link'][] = array( + array( + 'rel' => $rel, + 'href' => $term->url($rel), + ), + TRUE, + ); + + if ($rel == 'canonical') { + // Set the non-aliased canonical path as a default shortlink. + $page['#attached']['drupal_add_html_head_link'][] = array( + array( + 'rel' => 'shortlink', + 'href' => $term->url($rel, array('alias' => TRUE)), + ), + TRUE, + ); + } + } + } +} + +/** * Return nodes attached to a term across all field instances. * * This function requires taxonomy module to be maintaining its own tables, diff --git a/core/modules/taxonomy/taxonomy.pages.inc b/core/modules/taxonomy/taxonomy.pages.inc deleted file mode 100644 index 294dabb..0000000 --- a/core/modules/taxonomy/taxonomy.pages.inc +++ /dev/null @@ -1,81 +0,0 @@ -id() . '/feed', 'RSS - ' . $term->getName()); - - foreach ($term->uriRelationships() as $rel) { - // Set the term path as the canonical URL to prevent duplicate content. - $build['#attached']['drupal_add_html_head_link'][] = array( - array( - 'rel' => $rel, - 'href' => $term->url($rel), - ), - TRUE, - ); - - if ($rel == 'canonical') { - // Set the non-aliased canonical path as a default shortlink. - $build['#attached']['drupal_add_html_head_link'][] = array( - array( - 'rel' => 'shortlink', - 'href' => $term->url($rel, array('alias' => TRUE)), - ), - TRUE, - ); - } - } - - $build['taxonomy_terms'] = taxonomy_term_view_multiple(array($term->id() => $term)); - if ($nids = taxonomy_select_nodes($term->id(), TRUE, \Drupal::config('node.settings')->get('items_per_page'))) { - $nodes = node_load_multiple($nids); - $build['nodes'] = node_view_multiple($nodes); - $build['pager'] = array( - '#theme' => 'pager', - '#weight' => 5, - ); - } - else { - $build['no_content'] = array( - '#prefix' => '

', - '#markup' => t('There is currently no content classified with this term.'), - '#suffix' => '

', - ); - } - return $build; -} - -/** - * Generate the content feed for a taxonomy term. - * - * @param \Drupal\taxonomy\Entity\Term $term - * The taxonomy term entity. - * - * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. - * Use \Drupal\taxonomy\Controller\TaxonomyController::termFeed(). - */ -function taxonomy_term_feed(Term $term) { - $channel['link'] = url('taxonomy/term/' . $term->id(), array('absolute' => TRUE)); - $channel['title'] = \Drupal::config('system.site')->get('name') . ' - ' . $term->getName(); - // Only display the description if we have a single term, to avoid clutter and confusion. - // HTML will be removed from feed description. - $channel['description'] = $term->description->processed; - $nids = taxonomy_select_nodes($term->id(), FALSE, \Drupal::config('system.rss')->get('items.limit')); - - return node_feed($nids, $channel); -} diff --git a/core/modules/taxonomy/taxonomy.routing.yml b/core/modules/taxonomy/taxonomy.routing.yml index 014f957..d533544 100644 --- a/core/modules/taxonomy/taxonomy.routing.yml +++ b/core/modules/taxonomy/taxonomy.routing.yml @@ -90,7 +90,7 @@ taxonomy.overview_terms: taxonomy.term_page: path: '/taxonomy/term/{taxonomy_term}' defaults: - _content: '\Drupal\taxonomy\Controller\TaxonomyController::termPage' + _entity_view: 'taxonomy_term.full' _title: 'Taxonomy term' _title_callback: '\Drupal\taxonomy\Controller\TaxonomyController::termTitle' requirements: diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php index bf4e008..b815be2 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php @@ -249,7 +249,7 @@ public function alterRoutes(RouteCollection $collection) { // We assume that the numeric ids of the parameters match the one from // the view argument handlers. foreach ($parameters as $position => $parameter_name) { - $path = str_replace('arg_' . $position, $parameter_name, $path); + $path = str_replace('{arg_' . $position . '}', '{' . $parameter_name . '}', $path); $argument_map['arg_' . $position] = $parameter_name; } // Set the corrected path and the mapping to the route object. diff --git a/core/modules/views/tests/Drupal/views/Tests/Plugin/display/PathPluginBaseTest.php b/core/modules/views/tests/Drupal/views/Tests/Plugin/display/PathPluginBaseTest.php index 95f140e..27d520d 100644 --- a/core/modules/views/tests/Drupal/views/Tests/Plugin/display/PathPluginBaseTest.php +++ b/core/modules/views/tests/Drupal/views/Tests/Plugin/display/PathPluginBaseTest.php @@ -250,6 +250,40 @@ public function testAlterRoutesWithParameters() { } /** + * Tests alter routes with optional parameter in the overriding route. + */ + public function testAlterRoutesWithOptionalParameters() { + $collection = new RouteCollection(); + $collection->add('test_route', new Route('test_route/{parameter}', array('_controller' => 'Drupal\Tests\Core\Controller\TestController::content'))); + + list($view) = $this->setupViewExecutableAccessPlugin(); + + $display = array(); + $display['display_plugin'] = 'page'; + $display['id'] = 'page_1'; + $display['display_options'] = array( + 'path' => 'test_route/%', + ); + $display['display_options']['arguments'] = array( + 'test_id' => array(), + 'test_id2' => array(), + ); + $this->pathPlugin->initDisplay($view, $display); + + $view_route_names = $this->pathPlugin->alterRoutes($collection); + $this->assertEquals(array('test_id.page_1' => 'test_route'), $view_route_names); + + // Ensure that the test_route is overridden. + $route = $collection->get('test_route'); + $this->assertInstanceOf('\Symfony\Component\Routing\Route', $route); + $this->assertEquals('test_id', $route->getDefault('view_id')); + $this->assertEquals('page_1', $route->getDefault('display_id')); + // Ensure that the path did not changed and placeholders are respected. + $this->assertEquals('/test_route/{parameter}/{arg_1}', $route->getPath()); + $this->assertEquals(array('arg_0' => 'parameter'), $route->getOption('_view_argument_map')); + } + + /** * Returns some mocked view entity, view executable, and access plugin. */ protected function setupViewExecutableAccessPlugin() {