function ctools_plugin_example_context_create_relcontext
Create a context, either from manual configuration (form) 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_relcontext'
- relcontext.inc in ctools_plugin_example/
plugins/ contexts/ relcontext.inc - Sample ctools context type plugin that is used in this demo to create a relcontext from an existing simplecontext.
File
-
ctools_plugin_example/
plugins/ contexts/ relcontext.inc, line 37
Code
function ctools_plugin_example_context_create_relcontext($empty, $data = NULL, $conf = FALSE) {
$context = new ctools_context('relcontext');
$context->plugin = 'relcontext';
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 'sample_relcontext_setting' to it.
$context->data->description = 'relcontext_from__' . preg_replace('/[^a-z]/i', '', $data['sample_relcontext_setting']);
$context->data->description .= '_from_configuration_sample_simplecontext_setting';
$context->title = t("Relcontext context from simplecontext");
return $context;
}
}
else {
// $data is coming from an arg - it's just a string.
// This is used for keyword.
$context->title = "relcontext_" . $data->data->description;
$context->argument = $data->argument;
// Make up a bogus context.
$context->data = new stdClass();
// For this simple item we'll just create our data by stripping non-alpha and
// prepend 'relcontext_' and adding '_created_from_from_simplecontext' to it.
$context->data->description = 'relcontext_' . preg_replace('/[^a-z]/i', '', $data->data->description);
$context->data->description .= '_created_from_simplecontext';
return $context;
}
}