I got a neat idea yesterday to have the Token module provide arguments for the Panel Contexts. So, instead of having to depend on the officially provided argument contexts, you could have the Token module generate a huge list of arguments that you could use. The attached is a proof of concept screenshot.

This is what is in token.inc so far:

// $Id: nid.inc,v 1.1.2.5 2007/10/25 02:23:19 merlinofchaos Exp $
/**
 * @file arguments/nid.inc
 *
 * Plugin to provide a argument handlers using the Token module
 */

if (module_exists('token')) {
  function panels_token_panels_arguments() {
    $tokenlist = token_get_list();
    $args = array();
    foreach ($tokenlist as $category => $tokens) {
      foreach ($tokens as $token => $description) {
        $args['token_'. $category .'_'. $token] = array(
          'title' => substr(ucwords($category) .': '. $description, 0, 20),
          'keyword' => 'token_'. $category .'_'. $token,
          'description' => substr($description),
          'context' => 'panels_token_context'
        );
      }
    }
    return $args;
  }
  
  /**
   * Discover if this argument gives us the data we want.
   */
  function panels_token_context($arg = NULL, $conf = NULL, $empty = FALSE) {
  }
}

That is what I used to generate the token list in the arguments page. What we need now are the generated contexts. Any help truly appreciated.

Comments

wim leers’s picture

Excellent idea!

I'm not sure yet how this would work, but I'm sure it's possible. It'd allow you to filter by MIME type, for example.

merlinofchaos’s picture

This is a totally awesome idea. I'm not sure if this should be in panels, in token, or in a glue module between them. I'm sure that I don't have the bandwidth to do the work on it, but I fully support more work on this, because there is a LOT that can be done here.

druvision’s picture

Great idea - but token support is also needed for the panel title field and other fields as well.

Amnon
-
Professional: Drupal Israel | Drupal Development & Consulting | Eco-Healing | Effective Hosting Strategies | בניית אתרים
Personal: Hitech Dolphin: Regain Simple Joy :)

wim leers’s picture

If it's in the context, it can be used in the title, I think. You can use that %keywords thing in your title, which retrieves keywords from the context.

druvision’s picture

StatusFileSize
new24.32 KB

I've tested this code and made a few fixes:
1. Fixed a syntax error on line 18 in the original code (not enough arguments for substr($description) - by removing the substr alltogether
2. Made it easy for the argument length to fit into the selection list by using the argument ID (the argument description is hard to fit into the width of the selection list).

/**
* @file arguments/token.inc
*
* Plugin to provide a argument handlers using the Token module
*/

if (module_exists('token')) {
  function panels_token_panels_arguments() {
    $tokenlist = token_get_list();
    $args = array();
    foreach ($tokenlist as $category => $tokens) {
      foreach ($tokens as $token => $description) {
        $args['token_'. $category .'_'. $token] = array(
          'title' => substr(ucwords($category) .': '. $token, 0, 40),
          'keyword' => 'token_'. $category .'_'. $token,
          'description' => $description,
          'context' => 'panels_token_context'
        );
      }
    }
    return $args;
  }

  /**
   * Discover if this argument gives us the data we want.
   */
  function panels_token_context($arg = NULL, $conf = NULL, $empty = FALSE) {
  }
}

Enjoy

Amnon
-
Professional: Drupal Israel | Drupal Development & Consulting | Eco-Healing | Effective Hosting Strategies | בניית אתרים
Personal: Hitech Dolphin: Regain Simple Joy :)

nath’s picture

Sounds like something really useful.

jshuell’s picture

I am extremely interested in this, if only for a way to grab the node context from the title and title-raw tokens. As it stands now, Panels only allows context to be gotten from the node ID and any site that has implemented tokens and PathAuto to create user friendly (most the time) URLs cannot have panels taking over node pages. And the Panel-node content type is not an option for sites that already have their content in specific content types. I am new to coding for Drupal and do not yet completely understand the depth of the hook system, but I am reading up on the token and pathauto modules to find a way to grab the tokenized title from the URL and use it as an argument. My problem is finding a way to get the Node ID from that string. The URL Alias table is the likely suspect in the database to garner it from, can I simply

db_result(db_query("SELECT src FROM {url_alias} WHERE dst LIKE '%/%s'", $arg)); 

The problem I see with the select statement is that it assumes there is a path before the title, and although that works in my case (at least for the time being) it wont always be true. So, how to go about this in a more generic way that is reusable by everyone that has this issue? Im also not so sure about that LIKE condition.

jshuell’s picture

Ok, I think I got this. I know the OP was after token support but this at least gets me URL Alias support. I created a new plugin based heavily on merlinofchaos' nid.inc file but which when it detects that the argument is not a number will then check the URL Alias table for a match and if it finds it will retrieve the ID from there and load the node as usual.

EDIT: Moved to a new issue - http://drupal.org/node/227157

merlinofchaos’s picture

jshuell: This is very interesting. Can you create a new issue for this (It's related but not the same as actual token support) -- I'd like to explore this further. I don't know enough, this second, to say if this is the path Panels 2 really should go or not, but I am intrigued and we should check this out.

sdboyer’s picture

This remains a pretty interesting idea, but work seems to have fallen off! Anybody still keen on it?

There are two questions that this brings to mind for me. Since merlin didn't raise either when he originally responded, I don't know that they'd be horribly significant concerns, but I'd be interested to hear what folks' thoughts are on them. First, I'd be a bit concerned over the potential namespace clashes that could come out of something like this, especially with some of the more common namespace paths. This may not be an issue at all - my recollection of the way that panel pages handle namespace conflicts with aliased URLs is that they tend to get out of the way. However, it does strike me that the plethora of options token-arguments would provide is something of a headache waiting to happen, especially if you're running a site where users with no knowledge of the site's infrastructure. But I may well be being overly paranoid.

The other issue is the potentially more serious one - performance. Again, I have some digging to do as the new Panels co-maintainer in terms of learning the Panels hook_menu() voodoo, but it seems to me that token arguments could cause exponential growth in the number of checks Panels has to run on every single page request.

Other than that, though, this strikes me as quite spiffy. Nothing better than finding ways to get two existing structures to extend one another...

summit’s picture

Subscribing, token-support for panels would be awesome!
greetings, Martijn

toma’s picture

Subscribing

sdboyer’s picture

Again, the panels devs ain't got time to work on this. If y'all want to see it, file a patch!

summit’s picture

Status: Needs work » Postponed (maintainer needs more info)

Hi,

Above token.inc gives me the possibility to choose tokens as arguments, but with adding the token, say [title], I got The input was invalid.
Please advise how to proceed.

Greetings,
Martijn

summit’s picture

Anyone update for this please?
Thanks a lot in advance!

greetings,
Martijn

ausvalue’s picture

subscribe

wim leers’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

Cleaning up the issue queue.