CommentFileSizeAuthor
#1 drupal-remove_arg-2294093-1.patch2.48 KBParisLiakos

Comments

ParisLiakos’s picture

Status: Active » Needs review
StatusFileSize
new2.48 KB
dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Nice.

chx’s picture

Truly the end of an era. arg() was added in the first days of 2003, debuted in Drupal 4.1.0. Few things as ancient as those. Only getting rid of node_invoke (from 2001) last summer compares.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 0a54fea and pushed to 8.x. Thanks!

  • alexpott committed 0a54fea on 8.x
    Issue #2294093 by ParisLiakos: Remove arg().
    
hass’s picture

This killed by code. Can you share an example for the upgrade, please? This is inside hook_page_alter():

    if (\Drupal::moduleHandler()->moduleExists('search') && $config->get('track.site_search') && arg(0) == 'search' && $keys = google_analytics_search_get_keys()) {
      // hook_preprocess_search_results() is not executed if search result is
      // empty. Make sure the counter is set to 0 if there are no results.
      $url_custom = '(window.google_analytics_search_results) ? ' . Json::encode(url('search/' . arg(1), array('query' => array('search' => $keys)))) . ' : ' . Json::encode(url('search/' . arg(1), array('query' => array('search' => 'no-results:' . $keys, 'cat' => 'no-results'))));
    }

This looks like serving a specific need.

Please note that:

  • arg(0) == 'search' matches all paths/routes starting with search. e.g. search/node or search/foo or search/bar
  • arg(1) gave me node or any other keyword depending on the path search/node or search/foo or search/bar

I cannot see how I can implement this with RouteMatch.

hass’s picture

Status: Fixed » Needs work
dawehner’s picture

Status: Needs work » Fixed

@hass
Please have a look at https://www.drupal.org/node/2274705 and have a look at available routes defined by the search module:
search.view, search.view_$entity_id. This should be enough for you to solve the question for yourself. Please fix the duplicated support question.

hass’s picture

Status: Fixed » Needs work

I have read https://www.drupal.org/node/2274705, but i do not understand how this could help. This change notice does not help me solving the migration. I have no fixed route. This is all dynamic. It's also not possible to grab the path elements. There is no duplicate support question open.

If not possible we may need to rollback the patch here.

ParisLiakos’s picture

Status: Needs work » Fixed
if (strpos(\Drupal::routeMatch()->getRouteName(), 'search.view') === 0) {
  // This will match any /search* path. See Drupal\search\Routing\SearchPageRoutes
}

Plz, if you have more questions, open a support request instead of reopening this issue

hass’s picture

And what about arg(1) value? This is all missing in the changelog message and needs documentation.

ParisLiakos’s picture

// This returns 'node' in /search/node
// @see \Drupal\search\SearchPageInterface
\Drupal::routeMatch()->getParameter('entity')->getPath();
alexpott’s picture

We need to update change records... eg. https://www.drupal.org/node/2088511

alexpott’s picture

ParisLiakos’s picture

that was the only one i could found
i just removed the references to arg from the example code

hass’s picture

Why are you not documenting how it could be upgrade from arg? For me this is not really easy to guess.

hass’s picture

@ParisLiakos: \Drupal::routeMatch()->getParameter('entity')->getPath(); does not return anything.

Status: Fixed » Closed (fixed)

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