I've noticed that the persistent state module seems to change the way that Pathauto generates aliases. Here are the two settings I've tried for my content path:

[node:menu-link:parents:join-path]/[node:title]
[node:menu-link:parent:url:path]/[node:title]

With the persistent state module, Pathauto is generating the alias from the parent menu title instead of the parent menu path.

If I have a website with a main section titled "About Us". If I allow Pathauto to generate the URL, it will create "domain.com/about-us". If I want to simplify that URL to something like "domain.com/about", I can uncheck the automatic alias box and enter my own path. All pages under the "About Us" page in the menu should have that same base URL. So if I have a "Staff" page under the "About Us" section, it's URL should be "domain.com/about/staff".

This would work before using the persistent state module, but the automatic alias box for all pages under the "About Us" section would become unchecked. I would then have to go through and re-check the box for each page.

Doing the same thing using the persistent state module, all the sub-pages keep their automatic alias box checked, but the URL stays the same. This seems to be because the alias is being generated from the parent title instead of the parent alias. So URL for my "Staff" page under the "About Us" section remains "domain.com/about-us/staff" while the parent page is "domain.com/about".

Comments

interX’s picture

This is not an issue with Pathauto persistent state, but pathauto itself.
The only thing that the token [join-path] will do is use a cleaned version of the titles as path (regardless of parents' aliases)

        case 'join-path':
          module_load_include('inc', 'pathauto');
          $values = array();
          foreach (element_children($array) as $key) {
            $value = is_array($array[$key]) ? render($array[$key]) : (string) $array[$key];
            $value = pathauto_cleanstring($value);
            $values[] = $value;
          }
          $replacements[$original] = implode('/', $values);
          break;

This will not give the expected results if any of the parents has a fixed path alias or is not using [node:title] as URL alias.

There should be an additional token f.e. 'join-path-alias' to do this.

maxocub’s picture

Here is one way to do it:


/**
 * Implements hook_token_info().
 */
function MYMODULE_token_info() {
  $info['tokens']['array']['join-path-alias'] = array(
    'name' => t('Joined path alias'),
    'description' => t('Menu parents\' aliases joined.'),
  );
  return $info;
}

/**
 * Implements hook_tokens().
 */
function MYMODULE_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();

  if ($type == 'array' && !empty($data['array'])) {
    $array = $data['array'];

    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'join-path-alias':
          module_load_include('inc', 'pathauto');
          $values = array();

          foreach (element_children($array) as $key) {
            // Get the clean string generated by pathauto
            $value = is_array($array[$key]) ? render($array[$key]) : (string) $array[$key];
            $value = pathauto_cleanstring($value);

            // Get the path alias
            $link = menu_link_load($key);
            $path = $link['link_path'];
            $alias = drupal_get_path_alias($path);

            // If there is no path alias, use pathauto clean string
            // If there is a path alias, take only the last part
            $alias = strstr($alias, 'node/') ? $value : preg_replace('/.*\//', '', $alias);

            // If the pathauto clean string is different from the alias,
            // we have a custom alias and we should use it, else, use the clean string
            $values[] = ($alias != $value) ? $alias : $value;
          }
          $replacements[$original] = implode('/', $values);
          break;
        }
     }
  }
  return $replacements;
}

Dave Reid’s picture

Project: Pathauto Persistent State » Token
Version: 7.x-1.3 » 7.x-1.x-dev
Category: Feature request » Support request

I believe you want the [node:menu-link:parent:url:path] you mentioned in the above you used it, but that it only used the menu title. If that's not the case when using that token, then it's a bug in Token module's implementation.

maxocub’s picture

Thank you Dave, you're right, it does exactly what I want!

Dave Reid’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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