3

I added a link to a content body from ck editor as /node/7. When viewing this page I want to show www.sitename.com/example/alias.

This is working fine in drupal 7 (earlier version of my site), but not sure which module does this work.

I have installed pathauto, redirect, pathologic modules. I also configured the text format at admin/config/content/formats and set pathologic filter as first priority. But no luck.

After installed redirect module, if I hit node/7 in browser it automatically redirect to expected alias. But I want is the content page should show only url alias even If entered /node/7 in ckeditor.

Am I missing any configurations in any of the above module? or am I missing any module?

2

I found a hook in Pathologic module as hook_pathologic_alter and I used it to convert node path to URL alias.

I used this hook as follows

/**
 * Implements hook_pathologic_alter().
 */
function mymodule_pathologic_alter(&$url_params, &$parts, &$cached_settings){
    if ($parts['path'] != '<front>') {

        //get the alias for the path and assign it in path
        $alias = \Drupal::service('path.alias_manager')->getAliasByPath('/'.$url_params['path']);

        //Url::fromUri which Pathologic uses need a path without slash at first, so trim it
        $url_params['path'] = ltrim($alias, '/');
    }
}

This converts a node path to alias and pass it, so Pathologic will form a URL with alias.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.