Use Optional Arguments in a Panels Path I am porting an existing custom form that takes optional arguments from the URL to preload some fields. I can not use the ?q= method because I must maintain backwards compatibility. For example, both of these URLs are valid:

shop/barn
shop/barn/small/white/red/double/tin


The problem I am running into is how to setup this with Page Manager to accept an optional argument. If I set up my url to be:

shop/barn/%settings


and map %settings to a string, I can get it load the optional arguments! But ... shop/barn does not work. The only way I've figured out to resolve this so far is to create two pages with the exact same panel setup. I would really like to condense this down to one.

I have a feeling the answer lies in something to do with making a custom ctools arguments plugin as the author posted for Panel Pages and Taxonomy Term Arguments. I have tried modifying line 48 in the simplecontext_arg.inc in the ctools_plugin_example module with the following to accomplish this:

if (empty($arg)) {
  $arg[0] = '123';
  return ctools_context_create('simplecontext', $arg);
}


Unfortunately, this displays a blank panel when I visit ctools_plugin_example unlike visiting ctools_plugin_example\123.

This is being implemented on a Drupal Commerce site, so in a perfect world I would also like my panel pages to override the node/%node path with the optional argument so that I can more easily and consistently change the path of my product displays in the future instead of having to manually maintain a bunch of URLs.

I am also open to suggesting something other than Panel Pages, such as overriding the node--barn.tpl.php files.
My final solution was to create a Page Panel with the following path:

shop/%product/!optionalArgs


% indicates a required argument, ! indicates an optional argument

In order to grab all of the "arguments" or URL path after the product (ex: barn), go to Settings » Arguments, select Settings for optionalArgs, and make sure Get all arguments after this one is checked. Click Finish.

In order to use this with a Clean URL, the panel path needs to be some derivative of the Clean URL because panels does not have access to it. For more details, see merlinofchaos's explanation in the following Panels Issue: Panels, Pathauto and Arguments


  Let's say I have a url. It can be any URL, but for this example it's "node/12".
  
  Let's say I have an alias and it's generated by pathauto, and it's
  something like video/type/12/this-is-the-title-of-the-video and it's
  aliased to "node/12"
  
  If I visit
  http://example.com/video/type/12/this-is-the-title-of-the-video then
  what Drupal thinks the URL was was, in fact, 'node/12'. Panels never
  has a chance to do anything with video/type/12/foo because that URL
  doesn't really exist.
  
  The reason, then, that adding some other piece to the URL makes it
  work is that aliases don't accept arguments. They must be exact. So
  the problem, in that case, is the alias itself is actually taking the
  page away from where you want it to go.