first import
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide access control/visibility based on length of
|
||||
* simplecontext argument (in URL).
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Arg length"),
|
||||
'description' => t('Control access by length of simplecontext argument.'),
|
||||
'callback' => 'ctools_plugin_example_arg_length_ctools_access_check',
|
||||
'settings form' => 'ctools_plugin_example_arg_length_ctools_access_settings',
|
||||
'summary' => 'ctools_plugin_example_arg_length_ctools_access_summary',
|
||||
'required context' => new ctools_context_required(t('Simplecontext'), 'simplecontext'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Settings form for the 'by role' access plugin.
|
||||
*/
|
||||
function ctools_plugin_example_arg_length_ctools_access_settings(&$form, &$form_state, $conf) {
|
||||
$form['settings']['greater_than'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Grant access if simplecontext argument length is'),
|
||||
'#options' => array(1 => t('Greater than'), 0 => t('Less than or equal to')),
|
||||
'#default_value' => $conf['greater_than'],
|
||||
);
|
||||
$form['settings']['arg_length'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Length of simplecontext argument'),
|
||||
'#size' => 3,
|
||||
'#default_value' => $conf['arg_length'],
|
||||
'#description' => t('Access/visibility will be granted based on arg length.'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for access.
|
||||
*/
|
||||
function ctools_plugin_example_arg_length_ctools_access_check($conf, $context) {
|
||||
// As far as I know there should always be a context at this point, but this
|
||||
// is safe.
|
||||
if (empty($context) || empty($context->data)) {
|
||||
return FALSE;
|
||||
}
|
||||
$compare = ($context->arg_length > $conf['arg_length']);
|
||||
if (($compare && $conf['greater_than']) || (!$compare && !$conf['greater_than'])) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a summary description based upon the checked roles.
|
||||
*/
|
||||
function ctools_plugin_example_arg_length_ctools_access_summary($conf, $context) {
|
||||
return t('Simpletext argument must be !comp @length characters',
|
||||
array('!comp' => $conf['greater_than'] ? 'greater than' : 'less than or equal to',
|
||||
'@length' => $conf['arg_length']));
|
||||
}
|
||||
|
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide access control based upon role membership.
|
||||
* This is directly from the ctools module, but serves as a good
|
||||
* example of an access plugin
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("CTools example: role"),
|
||||
'description' => t('Control access by role.'),
|
||||
'callback' => 'ctools_plugin_example_example_role_ctools_access_check',
|
||||
'default' => array('rids' => array()),
|
||||
'settings form' => 'ctools_plugin_example_example_role_ctools_access_settings',
|
||||
'summary' => 'ctools_plugin_example_example_role_ctools_access_summary',
|
||||
'required context' => new ctools_context_required(t('User'), 'user'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Settings form for the 'by role' access plugin.
|
||||
*/
|
||||
function ctools_plugin_example_example_role_ctools_access_settings(&$form, &$form_state, $conf) {
|
||||
$form['settings']['rids'] = array(
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => t('Role'),
|
||||
'#default_value' => $conf['rids'],
|
||||
'#options' => ctools_get_roles(),
|
||||
'#description' => t('Only the checked roles will be granted access.'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compress the roles allowed to the minimum.
|
||||
*/
|
||||
function ctools_plugin_example_example_role_ctools_access_settings_submit(&$form, &$form_state) {
|
||||
$form_state['values']['settings']['rids'] = array_keys(array_filter($form_state['values']['settings']['rids']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for access.
|
||||
*/
|
||||
function ctools_plugin_example_example_role_ctools_access_check($conf, $context) {
|
||||
// As far as I know there should always be a context at this point, but this
|
||||
// is safe.
|
||||
if (empty($context) || empty($context->data) || !isset($context->data->roles)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$roles = array_keys($context->data->roles);
|
||||
$roles[] = $context->data->uid ? DRUPAL_AUTHENTICATED_RID : DRUPAL_ANONYMOUS_RID;
|
||||
return (bool) array_intersect($conf['rids'], $roles);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a summary description based upon the checked roles.
|
||||
*/
|
||||
function ctools_plugin_example_example_role_ctools_access_summary($conf, $context) {
|
||||
if (!isset($conf['rids'])) {
|
||||
$conf['rids'] = array();
|
||||
}
|
||||
$roles = ctools_get_roles();
|
||||
$names = array();
|
||||
foreach (array_filter($conf['rids']) as $rid) {
|
||||
$names[] = check_plain($roles[$rid]);
|
||||
}
|
||||
if (empty($names)) {
|
||||
return t('@identifier can have any role', array('@identifier' => $context->identifier));
|
||||
}
|
||||
return format_plural(count($names), '@identifier must have role "@roles"', '@identifier can be one of "@roles"', array('@roles' => implode(', ', $names), '@identifier' => $context->identifier));
|
||||
}
|
||||
|
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Sample plugin to provide an argument handler for a simplecontext.
|
||||
*
|
||||
* Given any argument to the page, simplecontext will get it
|
||||
* and turn it into a piece of data (a "context") just by adding some text to it.
|
||||
* Normally, the argument would be a key into some database (like the node
|
||||
* database, for example, and the result of using the argument would be to load
|
||||
* a specific "context" or data item that we can use elsewhere.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Simplecontext arg"),
|
||||
// keyword to use for %substitution
|
||||
'keyword' => 'simplecontext',
|
||||
'description' => t('Creates a "simplecontext" from the arg.'),
|
||||
'context' => 'simplecontext_arg_context',
|
||||
// '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 simplecontext arg'),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* 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 simplecontext_arg_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
||||
// If $empty == TRUE it wants a generic, unfilled context.
|
||||
if ($empty) {
|
||||
return ctools_context_create_empty('simplecontext');
|
||||
}
|
||||
// Do whatever error checking is required, returning FALSE if it fails the test
|
||||
// Normally you'd check
|
||||
// for a missing object, one you couldn't create, etc.
|
||||
if (empty($arg)) {
|
||||
return FALSE;
|
||||
}
|
||||
return ctools_context_create('simplecontext', $arg);
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 566 B |
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* "No context" sample content type. It operates with no context at all. It would
|
||||
* be basically the same as a 'custom content' block, but it's not even that
|
||||
* sophisticated.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t('CTools example no context content type'),
|
||||
'description' => t('No context content type - requires and uses no context.'),
|
||||
|
||||
// 'single' => TRUE means has no subtypes.
|
||||
'single' => TRUE,
|
||||
// Constructor.
|
||||
'content_types' => array('no_context_content_type'),
|
||||
// Name of a function which will render the block.
|
||||
'render callback' => 'no_context_content_type_render',
|
||||
// The default context.
|
||||
'defaults' => array(),
|
||||
|
||||
// This explicitly declares the config form. Without this line, the func would be
|
||||
// ctools_plugin_example_no_context_content_type_edit_form.
|
||||
'edit form' => 'no_context_content_type_edit_form',
|
||||
|
||||
// Icon goes in the directory with the content type.
|
||||
'icon' => 'icon_example.png',
|
||||
'category' => array(t('CTools Examples'), -9),
|
||||
|
||||
// this example does not provide 'admin info', which would populate the
|
||||
// panels builder page preview.
|
||||
);
|
||||
|
||||
/**
|
||||
* Run-time rendering of the body of the block.
|
||||
*
|
||||
* @param $subtype
|
||||
* @param $conf
|
||||
* Configuration as done at admin time.
|
||||
* @param $args
|
||||
* @param $context
|
||||
* Context - in this case we don't have any.
|
||||
*
|
||||
* @return
|
||||
* An object with at least title and content members.
|
||||
*/
|
||||
function no_context_content_type_render($subtype, $conf, $args, $context) {
|
||||
$block = new stdClass();
|
||||
|
||||
$ctools_help = theme('advanced_help_topic', array('module' => 'ctools', 'topic' => 'plugins', 'type' => 'title'));
|
||||
$ctools_plugin_example_help = theme('advanced_help_topic', array('module' => 'ctools_plugin_example', 'topic' => 'Chaos-Tools--CTools--Plugin-Examples', 'type' => 'title'));
|
||||
|
||||
// The title actually used in rendering
|
||||
$block->title = check_plain("No-context content type");
|
||||
$block->content = t("
|
||||
<div>Welcome to the CTools Plugin Example demonstration content type.
|
||||
|
||||
This block is a content type which requires no context at all. It's like a custom block,
|
||||
but not even that sophisticated.
|
||||
|
||||
For more information on the example plugins, please see the advanced help for
|
||||
|
||||
{$ctools_help} and {$ctools_plugin_example_help}
|
||||
</div>
|
||||
");
|
||||
if (!empty($conf)) {
|
||||
$block->content .= '<div>The only information that can be displayed in this block comes from the code and its settings form: </div>';
|
||||
$block->content .= '<div style="border: 1px solid red;">' . var_export($conf, TRUE) . '</div>';
|
||||
}
|
||||
|
||||
return $block;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 'Edit form' callback for the content type.
|
||||
* This example just returns a form; validation and submission are standard drupal
|
||||
* Note that if we had not provided an entry for this in hook_content_types,
|
||||
* this could have had the default name
|
||||
* ctools_plugin_example_no_context_content_type_edit_form.
|
||||
*
|
||||
*/
|
||||
function no_context_content_type_edit_form($form, &$form_state) {
|
||||
$conf = $form_state['conf'];
|
||||
$form['item1'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Item1'),
|
||||
'#size' => 50,
|
||||
'#description' => t('The setting for item 1.'),
|
||||
'#default_value' => !empty($conf['item1']) ? $conf['item1'] : '',
|
||||
'#prefix' => '<div class="clear-block no-float">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
$form['item2'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Item2'),
|
||||
'#size' => 50,
|
||||
'#description' => t('The setting for item 2'),
|
||||
'#default_value' => !empty($conf['item2']) ? $conf['item2'] : '',
|
||||
'#prefix' => '<div class="clear-block no-float">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
function no_context_content_type_edit_form_submit($form, &$form_state) {
|
||||
foreach (array('item1', 'item2') as $key) {
|
||||
$form_state['conf'][$key] = $form_state['values'][$key];
|
||||
}
|
||||
}
|
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Content type that displays the relcontext context type.
|
||||
*
|
||||
* This example is for use with the relcontext relationship to show
|
||||
* how we can get a relationship-context into a data type.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
// Used in add content dialogs.
|
||||
'title' => t('CTools example relcontext content type'),
|
||||
'admin info' => 'ctools_plugin_example_relcontext_content_type_admin_info',
|
||||
'content_types' => 'relcontext_content_type',
|
||||
'single' => TRUE,
|
||||
'render callback' => 'relcontext_content_type_render',
|
||||
// Icon goes in the directory with the content type. Here, in plugins/content_types.
|
||||
'icon' => 'icon_example.png',
|
||||
'description' => t('Relcontext content type - works with relcontext context.'),
|
||||
'required context' => new ctools_context_required(t('Relcontext'), 'relcontext'),
|
||||
'category' => array(t('CTools Examples'), -9),
|
||||
'edit form' => 'relcontext_edit_form',
|
||||
|
||||
// this example does not provide 'admin info', which would populate the
|
||||
// panels builder page preview.
|
||||
|
||||
);
|
||||
|
||||
/**
|
||||
* Run-time rendering of the body of the block.
|
||||
*
|
||||
* @param $subtype
|
||||
* @param $conf
|
||||
* Configuration as done at admin time
|
||||
* @param $args
|
||||
* @param $context
|
||||
* Context - in this case we don't have any
|
||||
*
|
||||
* @return
|
||||
* An object with at least title and content members
|
||||
*/
|
||||
function relcontext_content_type_render($subtype, $conf, $args, $context) {
|
||||
$data = $context->data;
|
||||
$block = new stdClass();
|
||||
|
||||
// Don't forget to check this data if it's untrusted.
|
||||
// The title actually used in rendering.
|
||||
$block->title = "Relcontext content type";
|
||||
$block->content = t("
|
||||
This is a block of data created by the Relcontent content type.
|
||||
Data in the block may be assembled from static text (like this) or from the
|
||||
content type settings form (\$conf) for the content type, or from the context
|
||||
that is passed in. <br />
|
||||
In our case, the configuration form (\$conf) has just one field, 'config_item_1;
|
||||
and it's configured with:
|
||||
");
|
||||
if (!empty($conf)) {
|
||||
$block->content .= '<div style="border: 1px solid red;">' . var_export($conf['config_item_1'], TRUE) . '</div>';
|
||||
}
|
||||
if (!empty($context)) {
|
||||
$block->content .= '<br />The args ($args) were <div style="border: 1px solid yellow;" >' .
|
||||
var_export($args, TRUE) . '</div>';
|
||||
}
|
||||
$block->content .= '<br />And the relcontext context ($context->data->description)
|
||||
(which was created from a
|
||||
simplecontext context) was <div style="border: 1px solid green;" >' .
|
||||
print_r($context->data->description, TRUE) . '</div>';
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* 'Edit' callback for the content type.
|
||||
* This example just returns a form.
|
||||
*
|
||||
*/
|
||||
function relcontext_edit_form($form, &$form_state) {
|
||||
$conf = $form_state['conf'];
|
||||
|
||||
$form['config_item_1'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Config Item 1 (relcontext)'),
|
||||
'#size' => 50,
|
||||
'#description' => t('Setting for relcontext.'),
|
||||
'#default_value' => !empty($conf['config_item_1']) ? $conf['config_item_1'] : '',
|
||||
'#prefix' => '<div class="clear-block no-float">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
function relcontext_edit_form_submit($form, &$form_state) {
|
||||
foreach (element_children($form) as $key) {
|
||||
if (!empty($form_state['values'][$key])) {
|
||||
$form_state['conf'][$key] = $form_state['values'][$key];
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Sample ctools content type that takes advantage of context.
|
||||
*
|
||||
* This example uses the context it gets (simplecontext) to demo how a
|
||||
* ctools content type can access and use context. Note that the simplecontext
|
||||
* can be either configured manually into a panel or it can be retrieved via
|
||||
* an argument.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t('Simplecontext content type'),
|
||||
'content_types' => 'simplecontext_content_type',
|
||||
// 'single' means not to be subtyped.
|
||||
'single' => TRUE,
|
||||
// Name of a function which will render the block.
|
||||
'render callback' => 'simplecontext_content_type_render',
|
||||
|
||||
// Icon goes in the directory with the content type.
|
||||
'icon' => 'icon_example.png',
|
||||
'description' => t('Simplecontext content type - works with a simplecontext context.'),
|
||||
'required context' => new ctools_context_required(t('Simplecontext'), 'simplecontext'),
|
||||
'edit form' => 'simplecontext_content_type_edit_form',
|
||||
'admin title' => 'ctools_plugin_example_simplecontext_content_type_admin_title',
|
||||
|
||||
// presents a block which is used in the preview of the data.
|
||||
// Pn Panels this is the preview pane shown on the panels building page.
|
||||
'admin info' => 'ctools_plugin_example_simplecontext_content_type_admin_info',
|
||||
'category' => array(t('CTools Examples'), -9),
|
||||
);
|
||||
|
||||
function ctools_plugin_example_simplecontext_content_type_admin_title($subtype, $conf, $context = NULL) {
|
||||
$output = t('Simplecontext');
|
||||
if ($conf['override_title'] && !empty($conf['override_title_text'])) {
|
||||
$output = filter_xss_admin($conf['override_title_text']);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to provide administrative info (the preview in panels when building
|
||||
* a panel).
|
||||
*
|
||||
* In this case we'll render the content with a dummy argument and
|
||||
* a dummy context.
|
||||
*/
|
||||
function ctools_plugin_example_simplecontext_content_type_admin_info($subtype, $conf, $context = NULL) {
|
||||
$context = new stdClass();
|
||||
$context->data = new stdClass();
|
||||
$context->data->description = t("no real context");
|
||||
$block = simplecontext_content_type_render($subtype, $conf, array("Example"), $context);
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run-time rendering of the body of the block (content type)
|
||||
*
|
||||
* @param $subtype
|
||||
* @param $conf
|
||||
* Configuration as done at admin time
|
||||
* @param $args
|
||||
* @param $context
|
||||
* Context - in this case we don't have any
|
||||
*
|
||||
* @return
|
||||
* An object with at least title and content members
|
||||
*/
|
||||
function simplecontext_content_type_render($subtype, $conf, $args, $context) {
|
||||
$data = $context->data;
|
||||
$block = new stdClass();
|
||||
|
||||
// Don't forget to check this data if it's untrusted.
|
||||
// The title actually used in rendering.
|
||||
$block->title = "Simplecontext content type";
|
||||
$block->content = t("
|
||||
This is a block of data created by the Simplecontext content type.
|
||||
Data in the block may be assembled from static text (like this) or from the
|
||||
content type settings form (\$conf) for the content type, or from the context
|
||||
that is passed in. <br />
|
||||
In our case, the configuration form (\$conf) has just one field, 'config_item_1;
|
||||
and it's configured with:
|
||||
");
|
||||
if (!empty($conf)) {
|
||||
$block->content .= '<div style="border: 1px solid red;">' . print_r(filter_xss_admin($conf['config_item_1']), TRUE) . '</div>';
|
||||
}
|
||||
if (!empty($context)) {
|
||||
$block->content .= '<br />The args ($args) were <div style="border: 1px solid yellow;" >' .
|
||||
var_export($args, TRUE) . '</div>';
|
||||
}
|
||||
$block->content .= '<br />And the simplecontext context ($context->data->description) was <div style="border: 1px solid green;" >' .
|
||||
print_r($context->data->description, TRUE) . '</div>';
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* 'Edit' callback for the content type.
|
||||
* This example just returns a form.
|
||||
*
|
||||
*/
|
||||
function simplecontext_content_type_edit_form($form, &$form_state) {
|
||||
$conf = $form_state['conf'];
|
||||
$form['config_item_1'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Config Item 1 for simplecontext content type'),
|
||||
'#size' => 50,
|
||||
'#description' => t('The stuff for item 1.'),
|
||||
'#default_value' => !empty($conf['config_item_1']) ? $conf['config_item_1'] : '',
|
||||
'#prefix' => '<div class="clear-block no-float">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
function simplecontext_content_type_edit_form_submit($form, &$form_state) {
|
||||
foreach (element_children($form) as $key) {
|
||||
if (!empty($form_state['values'][$key])) {
|
||||
$form_state['conf'][$key] = $form_state['values'][$key];
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Sample ctools context type plugin that
|
||||
* is used in this demo to create a relcontext from an existing simplecontext.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Relcontext"),
|
||||
'description' => t('A relcontext object.'),
|
||||
// Function to create the relcontext.
|
||||
'context' => 'ctools_plugin_example_context_create_relcontext',
|
||||
// Function that does the settings.
|
||||
'settings form' => 'relcontext_settings_form',
|
||||
'keyword' => 'relcontext',
|
||||
'context name' => 'relcontext',
|
||||
);
|
||||
|
||||
/**
|
||||
* Create a context, either from manual configuration (form) or from an argument on the URL.
|
||||
*
|
||||
* @param $empty
|
||||
* If true, just return an empty context.
|
||||
* @param $data
|
||||
* If from settings form, an array as from a form. If from argument, a string.
|
||||
* @param $conf
|
||||
* TRUE if the $data is coming from admin configuration, FALSE if it's from a URL arg.
|
||||
*
|
||||
* @return
|
||||
* a Context object.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
function relcontext_settings_form($conf, $external = FALSE) {
|
||||
$form = array();
|
||||
|
||||
$form['sample_relcontext_setting'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Relcontext setting'),
|
||||
'#size' => 50,
|
||||
'#description' => t('Just an example setting.'),
|
||||
'#default_value' => !empty($conf['sample_relcontext_setting']) ? $conf['sample_relcontext_setting'] : '',
|
||||
'#prefix' => '<div class="clear-block no-float">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Sample ctools context type plugin that shows how to create a context from an arg.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Simplecontext"),
|
||||
'description' => t('A single "simplecontext" context, or data element.'),
|
||||
'context' => 'ctools_plugin_example_context_create_simplecontext', // func to create context
|
||||
'context name' => 'simplecontext',
|
||||
'settings form' => 'simplecontext_settings_form',
|
||||
'keyword' => 'simplecontext',
|
||||
|
||||
// Provides a list of items which are exposed as keywords.
|
||||
'convert list' => 'simplecontext_convert_list',
|
||||
// Convert keywords into data.
|
||||
'convert' => 'simplecontext_convert',
|
||||
|
||||
'placeholder form' => array(
|
||||
'#type' => 'textfield',
|
||||
'#description' => t('Enter some data to represent this "simplecontext".'),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Create a context, either from manual configuration or from an argument on the URL.
|
||||
*
|
||||
* @param $empty
|
||||
* If true, just return an empty context.
|
||||
* @param $data
|
||||
* If from settings form, an array as from a form. If from argument, a string.
|
||||
* @param $conf
|
||||
* TRUE if the $data is coming from admin configuration, FALSE if it's from a URL arg.
|
||||
*
|
||||
* @return
|
||||
* a Context object/
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
function simplecontext_settings_form($conf, $external = FALSE) {
|
||||
if (empty($conf)) {
|
||||
$conf = array(
|
||||
'sample_simplecontext_setting' => 'default simplecontext setting',
|
||||
);
|
||||
}
|
||||
$form = array();
|
||||
$form['sample_simplecontext_setting'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Setting for simplecontext'),
|
||||
'#size' => 50,
|
||||
'#description' => t('An example setting that could be used to configure a context'),
|
||||
'#default_value' => $conf['sample_simplecontext_setting'],
|
||||
'#prefix' => '<div class="clear-block no-float">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Provide a list of sub-keywords.
|
||||
*
|
||||
* This is used to provide keywords from the context for use in a content type,
|
||||
* pane, etc.
|
||||
*/
|
||||
function simplecontext_convert_list() {
|
||||
return array(
|
||||
'item1' => t('Item1'),
|
||||
'item2' => t('Item2'),
|
||||
'description' => t('Description'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a context into a string to be used as a keyword by content types, etc.
|
||||
*/
|
||||
function simplecontext_convert($context, $type) {
|
||||
switch ($type) {
|
||||
case 'item1':
|
||||
return $context->data->item1;
|
||||
case 'item2':
|
||||
return $context->data->item2;
|
||||
case 'description':
|
||||
return $context->data->description;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,214 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Holds the panels pages export.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_default_panel_pages()
|
||||
*/
|
||||
function ctools_plugin_example_default_panel_pages() {
|
||||
$page = new stdClass();
|
||||
$page->pid = 'new';
|
||||
$page->did = 'new';
|
||||
$page->name = 'ctools_plugin_example_demo_panel';
|
||||
$page->title = 'Panels Plugin Example Demo Panel';
|
||||
$page->access = array();
|
||||
$page->path = 'demo_panel';
|
||||
$page->load_flags = 1;
|
||||
$page->css_id = '';
|
||||
$page->arguments = array(
|
||||
0 =>
|
||||
array(
|
||||
'name' => 'simplecontext_arg',
|
||||
'id' => 1,
|
||||
'default' => '404',
|
||||
'title' => '',
|
||||
'identifier' => 'Simplecontext arg',
|
||||
'keyword' => 'simplecontext',
|
||||
),
|
||||
);
|
||||
$page->relationships = array(
|
||||
0 =>
|
||||
array(
|
||||
'context' => 'argument_simplecontext_arg_1',
|
||||
'name' => 'relcontext_from_simplecontext',
|
||||
'id' => 1,
|
||||
'identifier' => 'Relcontext from Simplecontext',
|
||||
'keyword' => 'relcontext',
|
||||
),
|
||||
);
|
||||
$page->no_blocks = '0';
|
||||
$page->switcher_options = array();
|
||||
$page->menu = '0';
|
||||
$page->contexts = array();
|
||||
$display = new ctools_display();
|
||||
$display->did = 'new';
|
||||
$display->layout = 'threecol_33_34_33_stacked';
|
||||
$display->layout_settings = array();
|
||||
$display->panel_settings = array();
|
||||
$display->content = array();
|
||||
$display->panels = array();
|
||||
$pane = new stdClass();
|
||||
$pane->pid = 'new-1';
|
||||
$pane->panel = 'left';
|
||||
$pane->type = 'custom';
|
||||
$pane->shown = '1';
|
||||
$pane->subtype = 'custom';
|
||||
$pane->access = array();
|
||||
$pane->configuration = array(
|
||||
'style' => 'default',
|
||||
'override_title' => 0,
|
||||
'override_title_text' => '',
|
||||
'css_id' => '',
|
||||
'css_class' => '',
|
||||
'title' => '"No Context Item"',
|
||||
'body' => 'The "no context item" content type is here to demonstrate that you can create a content_type that does not require a context. This is probably the same as just creating a custom php block on the fly, and might serve the same purpose.',
|
||||
'format' => '1',
|
||||
);
|
||||
$pane->cache = array();
|
||||
$display->content['new-1'] = $pane;
|
||||
$display->panels['left'][0] = 'new-1';
|
||||
$pane = new stdClass();
|
||||
$pane->pid = 'new-2';
|
||||
$pane->panel = 'left';
|
||||
$pane->type = 'no_context_item';
|
||||
$pane->shown = '1';
|
||||
$pane->subtype = 'description';
|
||||
$pane->access = array();
|
||||
$pane->configuration = array(
|
||||
'style' => 'default',
|
||||
'override_title' => 0,
|
||||
'override_title_text' => '',
|
||||
'css_id' => '',
|
||||
'css_class' => '',
|
||||
'item1' => 'one',
|
||||
'item2' => 'two',
|
||||
'item3' => 'three',
|
||||
);
|
||||
$pane->cache = array();
|
||||
$display->content['new-2'] = $pane;
|
||||
$display->panels['left'][1] = 'new-2';
|
||||
$pane = new stdClass();
|
||||
$pane->pid = 'new-3';
|
||||
$pane->panel = 'middle';
|
||||
$pane->type = 'custom';
|
||||
$pane->shown = '1';
|
||||
$pane->subtype = 'custom';
|
||||
$pane->access = array();
|
||||
$pane->configuration = array(
|
||||
'style' => 'default',
|
||||
'override_title' => 0,
|
||||
'override_title_text' => '',
|
||||
'css_id' => '',
|
||||
'css_class' => '',
|
||||
'title' => 'Simplecontext',
|
||||
'body' => 'The "Simplecontext" content and content type demonstrate a very basic context and how to display it.
|
||||
|
||||
Simplecontext includes configuration, so it can get info from the config. It can also get its information to run from a simplecontext context, generated either from an arg to the panels page or via explicitly adding a context to the page.',
|
||||
'format' => '1',
|
||||
);
|
||||
$pane->cache = array();
|
||||
$display->content['new-3'] = $pane;
|
||||
$display->panels['middle'][0] = 'new-3';
|
||||
$pane = new stdClass();
|
||||
$pane->pid = 'new-4';
|
||||
$pane->panel = 'middle';
|
||||
$pane->type = 'simplecontext_item';
|
||||
$pane->shown = '1';
|
||||
$pane->subtype = 'description';
|
||||
$pane->access = array(
|
||||
0 => '2',
|
||||
1 => '4',
|
||||
);
|
||||
$pane->configuration = array(
|
||||
'context' => 'argument_simplecontext_arg_1',
|
||||
'style' => 'default',
|
||||
'override_title' => 0,
|
||||
'override_title_text' => '',
|
||||
'css_id' => '',
|
||||
'css_class' => '',
|
||||
'config_item_1' => 'simplecontext called from arg',
|
||||
);
|
||||
$pane->cache = array();
|
||||
$display->content['new-4'] = $pane;
|
||||
$display->panels['middle'][1] = 'new-4';
|
||||
$pane = new stdClass();
|
||||
$pane->pid = 'new-5';
|
||||
$pane->panel = 'right';
|
||||
$pane->type = 'custom';
|
||||
$pane->shown = '1';
|
||||
$pane->subtype = 'custom';
|
||||
$pane->access = array();
|
||||
$pane->configuration = array(
|
||||
'style' => 'default',
|
||||
'override_title' => 0,
|
||||
'override_title_text' => '',
|
||||
'css_id' => '',
|
||||
'css_class' => '',
|
||||
'title' => 'Relcontext',
|
||||
'body' => 'The relcontext content_type gets its data from a relcontext, which is an example of a relationship. This panel should be run with an argument like "/xxx", which allows the simplecontext to get its context, and then the relcontext is configured in this panel to get (create) its data from the simplecontext.',
|
||||
'format' => '1',
|
||||
);
|
||||
$pane->cache = array();
|
||||
$display->content['new-5'] = $pane;
|
||||
$display->panels['right'][0] = 'new-5';
|
||||
$pane = new stdClass();
|
||||
$pane->pid = 'new-6';
|
||||
$pane->panel = 'right';
|
||||
$pane->type = 'relcontext_item';
|
||||
$pane->shown = '1';
|
||||
$pane->subtype = 'description';
|
||||
$pane->access = array();
|
||||
$pane->configuration = array(
|
||||
'context' => 'relationship_relcontext_from_simplecontext_1',
|
||||
'style' => 'default',
|
||||
'override_title' => 0,
|
||||
'override_title_text' => '',
|
||||
'css_id' => '',
|
||||
'css_class' => '',
|
||||
'config_item_1' => 'default1',
|
||||
);
|
||||
$pane->cache = array();
|
||||
$display->content['new-6'] = $pane;
|
||||
$display->panels['right'][1] = 'new-6';
|
||||
$pane = new stdClass();
|
||||
$pane->pid = 'new-7';
|
||||
$pane->panel = 'top';
|
||||
$pane->type = 'custom_php';
|
||||
$pane->shown = '1';
|
||||
$pane->subtype = 'custom_php';
|
||||
$pane->access = array();
|
||||
$pane->configuration = array(
|
||||
'style' => 'default',
|
||||
'override_title' => 0,
|
||||
'override_title_text' => '',
|
||||
'css_id' => '',
|
||||
'css_class' => '',
|
||||
'title' => '',
|
||||
'body' => '$arg = arg(1);
|
||||
$arg0 = arg(0);
|
||||
if (!$arg) {
|
||||
$block->content = <<<END
|
||||
<em>This page is intended to run with an arg and you don\'t have one.</em>
|
||||
<br />
|
||||
Without an arg, the page doesn\'t have any context.
|
||||
<br />Please try something like "/$arg0/xxx"
|
||||
END;
|
||||
|
||||
$block->title = "This is intended to run with an argument";
|
||||
} else {
|
||||
$block->content = "The arg for this page is \'$arg\'";
|
||||
}',
|
||||
);
|
||||
$pane->cache = array();
|
||||
$display->content['new-7'] = $pane;
|
||||
$display->panels['top'][0] = 'new-7';
|
||||
$page->display = $display;
|
||||
$page->displays = array();
|
||||
$pages['ctools_plugin_example'] = $page;
|
||||
|
||||
|
||||
return $pages;
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Sample relationship plugin.
|
||||
*
|
||||
* We take a simplecontext, look in it for what we need to make a relcontext, and make it.
|
||||
* In the real world, this might be getting a taxonomy id from a node, for example.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Relcontext from simplecontext"),
|
||||
'keyword' => 'relcontext',
|
||||
'description' => t('Adds a relcontext from existing simplecontext.'),
|
||||
'required context' => new ctools_context_required(t('Simplecontext'), 'simplecontext'),
|
||||
'context' => 'ctools_relcontext_from_simplecontext_context',
|
||||
'settings form' => 'ctools_relcontext_from_simplecontext_settings_form',
|
||||
);
|
||||
|
||||
/**
|
||||
* Return a new context based on an existing context.
|
||||
*/
|
||||
function ctools_relcontext_from_simplecontext_context($context = NULL, $conf) {
|
||||
// If unset it wants a generic, unfilled context, which is just NULL.
|
||||
if (empty($context->data)) {
|
||||
return ctools_context_create_empty('relcontext', NULL);
|
||||
}
|
||||
|
||||
// You should do error-checking here.
|
||||
|
||||
// Create the new context from some element of the parent context.
|
||||
// In this case, we'll pass in the whole context so it can be used to
|
||||
// create the relcontext.
|
||||
return ctools_context_create('relcontext', $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings form for the relationship.
|
||||
*/
|
||||
function ctools_relcontext_from_simplecontext_settings_form($conf) {
|
||||
// We won't configure it in this case.
|
||||
return array();
|
||||
}
|
||||
|
Reference in New Issue
Block a user