Split from #2091399: [META] Remove menu_get_object()

Only one instance which is in taxonomy_term_is_page().

Files: 
CommentFileSizeAuthor
#3 menu_get_object.2095971-03.patch722 bytesekes
PASSED: [[SimpleTest]]: [MySQL] 58,902 pass(es).
[ View ]
#2 menu_get_object.2095971-02.patch682 bytesekes
PASSED: [[SimpleTest]]: [MySQL] 58,913 pass(es).
[ View ]

Comments

From the original issue, this one instance:

menu_get_object() is breaking (fatal error) taxonomy_term_is_page() if the core taxonomy/term/% page view is enabled (views.view.taxonomy_term.yml).

To reproduce, add content in terms. Enable view. Clear cache. Then $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT)->getPath(); returns NULL. Hence taxonomy_term_is_page() tries to access id on non-object $page_term.

Status:Active» Needs review
StatusFileSize
new682 bytes
PASSED: [[SimpleTest]]: [MySQL] 58,913 pass(es).
[ View ]

Something as simple as attached?

function taxonomy_term_is_page(Term $term) {
-  $page_term = menu_get_object('taxonomy_term', 2);
-  return (!empty($page_term) ? $page_term->id() == $term->id() : FALSE);
+  $page_term = \Drupal::request()->attributes->get('taxonomy_term');
+  return (is_object($page_term) && $page_term instanceof Term ? $page_term->id() == $term->id() : FALSE);

StatusFileSize
new722 bytes
PASSED: [[SimpleTest]]: [MySQL] 58,902 pass(es).
[ View ]

Following suggestion in irc from timplunkett.

function taxonomy_term_is_page(Term $term) {
-  $page_term = menu_get_object('taxonomy_term', 2);
-  return (!empty($page_term) ? $page_term->id() == $term->id() : FALSE);
+  $request = \Drupal::request();
+  if ($request->attributes->has('taxonomy_term')) {
+    $page_term = $request->attributes->get('taxonomy_term');
+    return $page_term->id() == $term->id();
+  }
+  return FALSE;
}

Status:Needs review» Needs work

The last submitted patch, menu_get_object.2095971-03.patch, failed testing.

Status:Needs work» Needs review

#3: menu_get_object.2095971-03.patch queued for re-testing.

Status:Needs review» Reviewed & tested by the community

Looks good to me, and was the only instance of this.

Status:Reviewed & tested by the community» Fixed

Committed and pushed to 8.x. Thanks!

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.