Drupal: hook_url_inbound_alter in url_rewrite: rewrite the request part of the paging URL

I am trying to use url_rewrite to work with unfriendly parameters in the module url paging. I want to rotate type urls page-title.html?page=0,1in page-title/page1.html.

Here are my hooks:

function mymod_url_outbound_alter(&$path, &$options, $original_path) {
    $localPath = $path . '?' . $options['query'];
    dpm("_url_outbound_alter($localPath)");
    if (preg_match('|(.+)\.html\?page=0%2C(\d+)|', $localPath, $matches)) {
        $path = "${matches[1]}/page${matches[2]}.html";
        unset($options['query']);
        dpm("altering path to $path");
    }
}

function mymod_url_inbound_alter(&$result, $path, $path_language) {
    if (preg_match('|(.+)/page(\d+)\.html|', $path, $matches)) {
        //$result = "${matches[1]}.html?page=0,${matches[2]}";
        $result = "${matches[1]}.html";
        //$_GET['q'] = "page=0,${matches[2]}";
        $_GET['page'] = "0,${matches[2]}";
        dpm("altering in-path to $result");
    }
}

function mymod_boot() {}

Can't add part of request to hook_url_inbound_alter?

  • If I comment on mymod_url_outbound_alter, it works, bot comma us URL-encoded - OK, it showed a friendly URL.
  • If I turn both on, the page goes into an infinite 301 loop redirect.
  • The above options also don't seem to work.

Yes, I know it’s better to fix pagingit to use a URL without a request. But the module is too complex to do it reliably. paginationThe module has no functions for me.

URL? , ?

+3
1

$options['query'] - , , -

$localPath = $path . '?' . $options['query']['page']

, $path Path. :

function pageing_url_outbound_alter(&$path, &$options, $original_path)
{
    if ($path == 'admin/content' && isset($options['query']['page']))
    {
        $path = 'admin/content/page' . $options['query']['page'];
        unset($options['query']['page']);
    }
}

function pageing_url_inbound_alter(&$path, $original_path, $path_language)
{
    if (preg_match('|admin/content/page(\d+)|', $path, $matches))
    {
        $path = 'admin/content';
        $_GET['page'] = $matches[1];
    }
}

Drupal 7 RC3

+2

Source: https://habr.com/ru/post/1780385/


All Articles