function ctools_plugin_example_context_create_simplecontext
Create a context, either from manual configuration or from an argument on the URL.
Parameters
$empty: If true, just return an empty context.
$data: If from settings form, an array as from a form. If from argument, a string.
$conf: TRUE if the $data is coming from admin configuration, FALSE if it's from a URL arg.
Return value
a Context object/
1 string reference to 'ctools_plugin_example_context_create_simplecontext'
- simplecontext.inc in ctools_plugin_example/
plugins/ contexts/ simplecontext.inc - Sample ctools context type plugin that shows how to create a context from an arg.
File
-
ctools_plugin_example/
plugins/ contexts/ simplecontext.inc, line 45
Code
function ctools_plugin_example_context_create_simplecontext($empty, $data = NULL, $conf = FALSE) {
$context = new ctools_context('simplecontext');
$context->plugin = 'simplecontext';
if ($empty) {
return $context;
}
if ($conf) {
if (!empty($data)) {
$context->data = new stdClass();
// For this simple item we'll just create our data by stripping non-alpha and
// adding '_from_configuration_item_1' to it.
$context->data->item1 = t("Item1");
$context->data->item2 = t("Item2");
$context->data->description = preg_replace('/[^a-z]/i', '', $data['sample_simplecontext_setting']);
$context->data->description .= '_from_configuration_sample_simplecontext_setting';
$context->title = t("Simplecontext context from config");
return $context;
}
}
else {
// $data is coming from an arg - it's just a string.
// This is used for keyword.
$context->title = $data;
$context->argument = $data;
// Make up a bogus context.
$context->data = new stdClass();
$context->data->item1 = t("Item1");
$context->data->item2 = t("Item2");
// For this simple item we'll just create our data by stripping non-alpha and
// adding '_from_simplecontext_argument' to it.
$context->data->description = preg_replace('/[^a-z]/i', '', $data);
$context->data->description .= '_from_simplecontext_argument';
$context->arg_length = strlen($context->argument);
return $context;
}
}