Using the Extend Pathes feature of Taxonomy Theme I have run into the following problem: I have two themes, A and B, and want the following mapping:

A: node/[any number]
B: node/[any number]/add

If I code this in module Taxonomy Theme,

A: node/*
B: node/*/add

the behaviour is dependent on the order in which the themes are checked: For instance, if I am visiting page 'node/3/add' and the rule for theme A is checked first then the rule for theme B is the last matching one (and therfore B will be taken). However, if the rule for theme A is checked last, it applies (as * matches '3/add') and therefore A will be taken — not what I wanted in the first place! This leads to undeterministic behaviour.

I propose to add the wildcard # which shall match any string not containing a forward slash. With this, the above problem can be solved via

A: node/#
B: node/#/add

The attached patch changes mainly two lines of the existing code. Here it is:

Index: taxonomy_theme_admin.inc
===================================================================
--- taxonomy_theme_admin.inc	(revision 1)
+++ taxonomy_theme_admin.inc	(working copy)
@@ -340,7 +340,7 @@
     '#collapsed' => FALSE,
   );
   if (variable_get('taxonomy_theme_extended_enable', 0)) {
-    $form['taxonomy_theme_extended']['help'] = array('#value' => t('<p>To assign a theme for a particular path enter the path into according textarea.<br />Enter one path per line as Drupal paths (or path aliases). Character \'*\' is a wildcard.<br /><i>Adding \'node/6\' to the \'bluemarine\' field will assign bluemarine theme to node 6.</i></p>'));
+    $form['taxonomy_theme_extended']['help'] = array('#value' => t('<p>To assign a theme for a particular path enter the path into according textarea.<br />Enter one path per line as Drupal paths (or path aliases). Character \'*\' is a wildcard for any string and character \'#\' is a wildcard for any string not containing a forward slash (\'/\').<br /><i>Adding \'node/6\' to the \'bluemarine\' field will assign bluemarine theme to node 6.</i></p>'));
     $form['taxonomy_theme_extended']['theme_pathes'] = array('#tree' => TRUE);
     $options_admin_themes = _taxonomy_theme_options(TRUE, FALSE);
     foreach($options_admin_themes as $themex) {
Index: taxonomy_theme_pathes.inc
===================================================================
--- taxonomy_theme_pathes.inc	(revision 1)
+++ taxonomy_theme_pathes.inc	(working copy)
@@ -16,6 +16,7 @@
   foreach ($themes as $themex) {
     $pathes_regexp = _taxonomy_theme_expcache($themex->name);
     if (preg_grep($pathes_regexp, array($uri, $alias_uri))) {
+      error_log('new theme "'.$themex->name.'"', 0);
       $custom_theme = $themex->name;
     }
   }
@@ -37,7 +38,7 @@
     if (db_num_rows($result)) {
       while ($path = db_fetch_object($result)) {
         $pathes .= empty($pathes) ? '' : '|';
-        $pathes .= str_replace(array('*', '/'), array('.*', '\/'), drupal_get_normal_path($path->path));
+        $pathes .= str_replace(array('*', '/', '#'), array('.*', '\/', '[^\/]*'), drupal_get_normal_path($path->path));
       }
     }
     $cache[$theme_name] = '/^('.$pathes.')$/';
CommentFileSizeAuthor
#1 patch_100.txt2.11 KBhbfkf
patch_99.txt2.16 KBhbfkf

Comments

hbfkf’s picture

Title: New wildcard symbol for more fine-control » New wildcard symbol for more fine-control (revised)
StatusFileSize
new2.11 KB

Going a little further: This attached patch (also shown below) introduces (besides the already existing wildcard *) two new wildcards:

  • # for a nonempty string of digits (like '129', '021', but not '12k1'),
  • % for a nonempty string not containing a forward slash (like '1ja3', but not '1231/asd')

Here is the patch:

Index: taxonomy_theme_admin.inc
===================================================================
--- taxonomy_theme_admin.inc	(revision 12)
+++ taxonomy_theme_admin.inc	(working copy)
@@ -340,7 +340,7 @@
     '#collapsed' => FALSE,
   );
   if (variable_get('taxonomy_theme_extended_enable', 0)) {
-    $form['taxonomy_theme_extended']['help'] = array('#value' => t('<p>To assign a theme for a particular path enter the path into according textarea.<br />Enter one path per line as Drupal paths (or path aliases). Character \'*\' is a wildcard for any string and character \'#\' is a wildcard for any string not containing a forward slash (\'/\').<br /><i>Adding \'node/6\' to the \'bluemarine\' field will assign bluemarine theme to node 6.</i></p>'));
+    $form['taxonomy_theme_extended']['help'] = array('#value' => t('<p>To assign a theme for a particular path enter the path into according textarea.<br />Enter one path per line as Drupal paths (or path aliases). Character \'*\' is a wildcard for any string, character \'%\' is a wildcard for any nonempty string not containing a forward slash (\'/\'), and character \'#\' is a wildcard for any nonempty string consisting of digits only.<br /><i>Adding \'node/6\' to the \'bluemarine\' field will assign bluemarine theme to node 6.</i></p>'));
     $form['taxonomy_theme_extended']['theme_pathes'] = array('#tree' => TRUE);
     $options_admin_themes = _taxonomy_theme_options(TRUE, FALSE);
     foreach($options_admin_themes as $themex) {
Index: taxonomy_theme_pathes.inc
===================================================================
--- taxonomy_theme_pathes.inc	(revision 12)
+++ taxonomy_theme_pathes.inc	(working copy)
@@ -38,7 +38,7 @@
     if (db_num_rows($result)) {
       while ($path = db_fetch_object($result)) {
         $pathes .= empty($pathes) ? '' : '|';
-        $pathes .= str_replace(array('*', '/', '#'), array('.*', '\/', '[^\/]*'), drupal_get_normal_path($path->path));
+        $pathes .= str_replace(array('*', '/', '%', '#'), array('.*', '\/', '[^\/]+', '[0-9]+'), drupal_get_normal_path($path->path));
       }
     }
     $cache[$theme_name] = '/^('.$pathes.')$/';
profix898’s picture

Component: - Extended (Pathes) » - Extended (Paths)

Hi, thanks a lot for thinking about this. I agree that in some cases more fine-control is needed. And it can be implemented easily and cleanly the way you suggest. Nice so far. However I think before your modification can be added, we should also take a look at the new menu system in Drupal-6. AFAIK it introduces new placeholders to wildcard-match menu paths. The patch for taxonomy_theme should be compatible or semantically even to Drupal-6. Otherwise we would need to change the wildcard symbols in a few month and thats a bad idea IMO. I will take a look at this as time permits ...

druru’s picture

I'd like to know more about where Drupal 6 menu system is headed.

How / where can i see the features targeted for inclusion in the next release?

I'm not sure what you mean by placeholders but i've been trying to write some of my own code that matches url aliases of node displays to decide whether a menu should remain expanded or not. This sounds a lot like what you're talking about and a very needed feature. But i'd like to see where the menu system is heading..

Any links would be greatly appreciated..

thanks

profix898’s picture

Documentation of the new menu system is located at http://drupal.org/node/109131. You can now have paths like node/%/edit without the need for arg(x) == y && is_numeric(arg(z)) etc., but directly supported through the menu system. This should make taxonomy_theme code much nicer, lighter and more robust (after a rewrite :() in Drupal 6.
There is also a discussion on adding 'context' to the $node object in http://drupal.org/node/113382, that would allow to map themes to nodes based on the context 'properties'. This might also solve the issue mentioned here

I'm inclined to say: Lets commit hbfkf's patch to Drupal-5 branch and put the heavy changes into the Drupal 6 rewrite (providing an automated upgrade patch, of course).

profix898’s picture

Status: Needs review » Fixed

Patch in #1 committed to the Drupal-5 branch. Thanks a lot.
Porting taxonomy_theme to Drupal 6 will require a rework of major parts, I fear. We will see how to handle wildcard paths in this context later.

Anonymous’s picture

Status: Fixed » Closed (fixed)