Drupal: hook_url_inbound_alter en url_rewrite: parte de consulta reescritura de URL para paginación

StackOverflow https://stackoverflow.com/questions/4448609

  •  10-10-2019
  •  | 
  •  

Pregunta

Estoy tratando de utilizar url_rewrite a trabajar en torno a parámetros nonfriendly en el URL de módulo paging. Deseo convertir las URL como page-title.html?page=0,1 a page-title/page1.html.

Aquí están mis ganchos:

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() {}

Es imposible añadir consulta participar en hook_url_inbound_alter?

  • Si comento hacia fuera mymod_url_outbound_alter, funciona, bot coma nosotros con codificación URL -. OK, se mostró la URL amigable
  • Si habilito tanto, la entra en la página de redirección 301 infinita lazo.
  • La comentado variantes también no parecen funcionar.

Sí, ya sé que es mejor paging solución a utilizar URL no consulta. Sin embargo, el módulo es un poco demasiado complejo para hacerlo de forma fiable. pagination módulo carece de características para mí.

es el problema en que altera la URL? ¿Qué puedo hacer para que funcione?

¿Fue útil?

Solución

$options['query'] is an array that contains the query parameters and their values, so you would have to do something like

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

Also note that $path has not been rewritten by the Path module yet. Here is what works for me:

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];
    }
}

This is for Drupal 7 RC3

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top