I'm developing a module, something similar to Talk module, which allows to have reviews or comments on a separate page, not on the bottom of a node page. As you may know, even if your node has an alias like: http://example.com/great-film, its talk page url will look like: http://example.com/node/1/talk ... but I want to make it accessible via http://example.com/great-film/talk ...

I tried to create hook_menu like this:

$items['%/talk'] = array(
'page callback' => 'talk_page',
'page arguments' => array(0),
'access callback' => 'user_access',
'access arguments' => array('access content'),
);

But it doesn't work. Pathauto won't help also, because '/talk' isn't a node, this is a custom url ... so my idea is to make Drupal somehow recognize '%/talk' slug (instead of % it should have node's alias) ... is it possible to do this somehow? Any ideas?

Comments

Kuldip Gohil’s picture

first create menu item like $items['node/%node_id/talk']

then you can refer following code it will insert alias for your menu item when new node inserted.. please add check for your content type.

function custom_nodeapi(&$node, $op, $a3, $a4)
{
  switch ($op)
  {
    case 'insert':
    {  
      /* 
  We create aliases here: 
      */

      $placeholders = pathauto_get_placeholders('node', $node);
      $nid          = $node->nid;
      $url          = "node/$nid/talk";

      pathauto_create_alias('custom', 'insert',  $placeholders, $url,
                            $nid, $type, $node->language);
      break;
    }
    case 'delete':
    {
      path_set_alias("node/$nid/talk");
      break;
    }
    
  }
}

function custom_pathauto($op = '')
{
  $pathauto = null;

  switch ($op)
  {
    case 'settings':
    {
      $header     = t("Custom Path For Node talk Pages");
      $pattern    = t('Default path pattern for talk.');
      $bulk       = t(  'Bulk generate aliases for talk');
      $bulkDesc   = t(  'Generate aliases for all existing node ');
      $patterns   = token_get_list('node');
      $languages  = array ( );

      foreach ($patterns as $type => $pattern_set)
      {
        if ($type != 'global')
        {
          foreach ($pattern_set as $pattern => $description)
          {
            $placeholders["[$pattern]"] = $description;
          }
        }
      }
      if (module_exists('locale'))
      {
        $languages  = array  ( '' => t('Language neutral') )
                    + locale_language_list('name');
      }
      foreach (node_get_types('names') as $node_type => $node_name)
      {
        if (('cw_printer' == $node_type) or ('cw_laptop' == $node_type))
        {
          if ((variable_get('language_content_type_'. $node_type, 0)) &&
              (count($languages)))
          {
            $patternitems[$node_type] =
                  t(  'Default path pattern for @node_type (applies to all '
                    . '@node_type node types with blank patterns below)',
                    array ( '@node_type'=>$node_name ));

            foreach ($languages as $lang_code => $lang_name)
            {
              if (!empty($lang_code))
              {
                $patternitems[$node_type . '_' . $lang_code] =
                          t('Pattern for all @node_type paths in @language',
                            array ( '@node_type'=>$node_name
                                ,   '@language' =>$lang_name ));
              }
              else
              {
                $patternitems[$node_type . '_' . $lang_code] =
                      t('Pattern for all language neutral @node_type paths',
                        array ( '@node_type'=>$node_name ));
              }
            }
          }
          else
          {
            $patternitems[$node_type] =
                                      t('Pattern for all @node_type paths',
                                        array ( '@node_type'=>$node_name ));
          }
        }
      }
      $settings = array ( 'module'        =>'custom'
                      ,   'token_type'    =>'node'
                      ,   'groupheader'   =>$header
                      ,   'patterndescr'  =>$patern
                      ,   'patterndefault'=>t('[title-raw]/talk')
                      ,   'bulkname'      =>$bulk
                      ,   'bulkdescr'     =>$bulkDesc
                      ,   'placeholders'  =>$placeholders
                      ,   'patternitems'  =>$patternitems
                      , );
      $pathauto = (object) $settings;
      break;
    }
    default:
    {
      break;
    }
  }
  return $pathauto;
}

timonweb’s picture

Wow, Kuldip Gohil, thanks alot! I'll check this and will let you know how this goes!

ralf.strobel’s picture

You can just use this module: Extended path aliases