If you want URL argument data passed into your contexts, you need to create a specific plugin for that argument and then link it to your context. Our new folder layout looks like this.
We don't need to change our MYMODULE_ctools_plugin_directory($module, $plugin) – because we are getting the value of $plugin as 'arguments' , which if you see above points to this directory.
We now create the necessary code for datecontext_arg.inc
<?php
/**
* Plugins are described by creating a $plugin array which will be used
* by the system that includes this file.
*/
$plugin = array(
'title' => t("Datecontext arg"),
// keyword to use for %substitution
'keyword' => 'datecontext',
'description' => t('Creates a date context from the argument'),
'context' => 'olamalu_rota_context_create_datecontext_arg',
// 'settings form' => 'simplecontext_arg_settings_form',
// placeholder_form is used in panels preview, for example, so we can
// preview without getting the arg from a URL
'placeholder form' => array(
'#type' => 'textfield',
'#description' => t('Enter the datecontext argument'),
),
);
/**
* Get the simplecontext context using the arg. In this case we're just going
* to manufacture the context from the data in the arg, but normally it would
* be an API call, db lookup, etc.
*/
function olamalu_rota_context_create_datecontext_arg($arg = NULL, $conf = NULL, $empty = FALSE) {
// If $empty == TRUE it wants a generic, unfilled context.
if ($empty) {
return ctools_context_create_empty('datecontext');
}
// Do whatever error checking is required, returning FALSE if it fails the test
if (empty($arg)) {
return FALSE;
}
try {
date_create($arg);
} catch (Exception $e) {
return FALSE;
}
return ctools_context_create('datecontext', $arg);
}
(You'll see we copied this from the ctools plugin examples).
Basically stepping through this code – the first array defines the plugin ($plugin). The 'context' key points to the function olamalu_rota_context_create_datecontext_arg, which is where the context data is created.
There's not much to do, as we already have a context (datecontext created above), so we simply use ctools functions to create our context using that. Note that we need a date to be created from the argument so we don't validate (i.e. we return FALSE) if we can't create a date.
Flush the cache and you should be able to assign arguments to this context.