first import
This commit is contained in:
14
sites/all/modules/ctools/ctools_plugin_example/README.txt
Normal file
14
sites/all/modules/ctools/ctools_plugin_example/README.txt
Normal file
@ -0,0 +1,14 @@
|
||||
|
||||
The CTools Plugin Example is an example for developers of how to CTools
|
||||
access, argument, content type, context, and relationship plugins.
|
||||
|
||||
There are a number of ways to profit from this:
|
||||
|
||||
1. The code itself intends to be as simple and self-explanatory as possible.
|
||||
Nothing fancy is attempted: It's just trying to use the plugin API to show
|
||||
how it can be used.
|
||||
|
||||
2. There is a sample panel. You can access it at /ctools_plugin_example/xxxx
|
||||
to see how it works.
|
||||
|
||||
3. There is Advanced Help at admin/advanced_help/ctools_plugin_example.
|
@ -0,0 +1,15 @@
|
||||
name = Chaos Tools (CTools) Plugin Example
|
||||
description = Shows how an external module can provide ctools plugins (for Panels, etc.).
|
||||
package = Chaos tool suite
|
||||
dependencies[] = ctools
|
||||
dependencies[] = panels
|
||||
dependencies[] = page_manager
|
||||
dependencies[] = advanced_help
|
||||
core = 7.x
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-02-02
|
||||
version = "7.x-1.2+31-dev"
|
||||
core = "7.x"
|
||||
project = "ctools"
|
||||
datestamp = "1359766341"
|
||||
|
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @file
|
||||
*
|
||||
* Working sample module to demonstrate CTools 3 plugins
|
||||
*
|
||||
* This sample module is only intended to demonstrate how external modules can
|
||||
* provide ctools plugins. There is no useful functionality, and it's only
|
||||
* intended for developers or for educational use.
|
||||
*
|
||||
* As far as possible, everything is kept very simple, not exercising all of
|
||||
* the capabilities of CTools or Panels.
|
||||
*
|
||||
* Although the ctools documentation suggests that strict naming conventions
|
||||
* be followed, this code attempts to follow only the conventions which are
|
||||
* required (the hooks), in order to demonstrate the difference. You can
|
||||
* certainly use the conventions, but it's important to know the difference
|
||||
* between a convention and a requirement.
|
||||
*
|
||||
* The advanced_help module is required, because both CTools and this module
|
||||
* provide help that way.
|
||||
*
|
||||
* There is a demonstration panel provided at /ctools_plugin_example/123
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_menu
|
||||
*/
|
||||
function ctools_plugin_example_menu() {
|
||||
$items = array();
|
||||
|
||||
$items["admin/settings/ctools_plugin_example"] = array(
|
||||
'title' => 'CTools plugin example',
|
||||
'description' => t("Demonstration code, advanced help, and a demo panel to show how to build ctools plugins."),
|
||||
'page callback' => 'ctools_plugin_example_explanation_page',
|
||||
'access arguments' => array('administer site configuration'),
|
||||
'type' => MENU_NORMAL_ITEM,
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_ctools_plugin_directory().
|
||||
*
|
||||
* It simply tells panels where to find the .inc files that define various
|
||||
* args, contexts, content_types. In this case the subdirectories of
|
||||
* ctools_plugin_example/panels are used.
|
||||
*/
|
||||
function ctools_plugin_example_ctools_plugin_directory($module, $plugin) {
|
||||
if ($module == 'ctools' && !empty($plugin)) {
|
||||
return "plugins/$plugin";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement hook_ctools_plugin_api().
|
||||
*
|
||||
* If you do this, CTools will pick up default panels pages in
|
||||
* <modulename>.pages_default.inc
|
||||
*/
|
||||
function ctools_plugin_example_ctools_plugin_api($module, $api) {
|
||||
// @todo -- this example should explain how to put it in a different file.
|
||||
if ($module == 'panels_mini' && $api == 'panels_default') {
|
||||
return array('version' => 1);
|
||||
}
|
||||
if ($module == 'page_manager' && $api == 'pages_default') {
|
||||
return array('version' => 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Just provide an explanation page for the admin section
|
||||
* @return unknown_type
|
||||
*/
|
||||
function ctools_plugin_example_explanation_page() {
|
||||
$content = '<p>' . t("The CTools Plugin Example is simply a developer's demo of how to create plugins for CTools. It provides no useful functionality for an ordinary user.") . '</p>';
|
||||
|
||||
$content .= '<p>' . t(
|
||||
'There is a demo panel demonstrating much of the functionality provided at
|
||||
<a href="@demo_url">CTools demo panel</a>, and you can find documentation on the examples at
|
||||
!ctools_plugin_example_help.
|
||||
CTools itself provides documentation at !ctools_help. Mostly, though, the code itself is intended to be the teacher.
|
||||
You can find it in %path.',
|
||||
array(
|
||||
'@demo_url' => url('ctools_plugin_example/xxxxx'),
|
||||
'!ctools_plugin_example_help' => theme('advanced_help_topic', array('module' => 'ctools_plugin_example', 'topic' => 'Chaos-Tools--CTools--Plugin-Examples', 'type' => 'title')),
|
||||
'!ctools_help' => theme('advanced_help_topic', array('module' => 'ctools', 'topic' => 'plugins', 'type' => 'title'),
|
||||
'%path' => drupal_get_path('module', 'ctools_plugin_example'),
|
||||
)) . '</p>';
|
||||
|
||||
return $content;
|
||||
}
|
@ -0,0 +1,451 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This module provides default panels to demonstrate the behavior of the plugins.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Default panels pages for CTools Plugin Example
|
||||
*
|
||||
* To pick up this file, your module needs to implement
|
||||
* hook_ctools_plugin_api() - See ctools_plugin_example_ctools_plugin_api() in
|
||||
* ctools_plugin_example.module.
|
||||
*
|
||||
*
|
||||
* Note the naming of the file: <modulename>.pages_default.inc
|
||||
* With this naming, no additional code needs to be provided. CTools will just find the file.
|
||||
* The name of the hook is <modulename>_default_page_manager_pages()
|
||||
*
|
||||
* This example provides two pages, but the returned array could
|
||||
* have several pages.
|
||||
*
|
||||
* @return
|
||||
* Array of pages, normally exported from Panels.
|
||||
*/
|
||||
|
||||
function ctools_plugin_example_default_page_manager_pages() {
|
||||
|
||||
// begin exported panel.
|
||||
|
||||
$page = new stdClass;
|
||||
$page->disabled = FALSE; /* Edit this to true to make a default page disabled initially */
|
||||
$page->api_version = 1;
|
||||
$page->name = 'ctools_plugin_example';
|
||||
$page->task = 'page';
|
||||
$page->admin_title = 'CTools plugin example';
|
||||
$page->admin_description = 'This panel provides no functionality to a working Drupal system. It\'s intended to display the various sample plugins provided by the CTools Plugin Example module. ';
|
||||
$page->path = 'ctools_plugin_example/%sc';
|
||||
$page->access = array(
|
||||
'logic' => 'and',
|
||||
);
|
||||
$page->menu = array(
|
||||
'type' => 'normal',
|
||||
'title' => 'CTools plugin example',
|
||||
'name' => 'navigation',
|
||||
'weight' => '0',
|
||||
'parent' => array(
|
||||
'type' => 'none',
|
||||
'title' => '',
|
||||
'name' => 'navigation',
|
||||
'weight' => '0',
|
||||
),
|
||||
);
|
||||
$page->arguments = array(
|
||||
'sc' => array(
|
||||
'id' => 2,
|
||||
'identifier' => 'simplecontext-arg',
|
||||
'name' => 'simplecontext_arg',
|
||||
'settings' => array(),
|
||||
),
|
||||
);
|
||||
$page->conf = array();
|
||||
$page->default_handlers = array();
|
||||
$handler = new stdClass;
|
||||
$handler->disabled = FALSE; /* Edit this to true to make a default handler disabled initially */
|
||||
$handler->api_version = 1;
|
||||
$handler->name = 'page_ctools_panel_context';
|
||||
$handler->task = 'page';
|
||||
$handler->subtask = 'ctools_plugin_example';
|
||||
$handler->handler = 'panel_context';
|
||||
$handler->weight = 0;
|
||||
$handler->conf = array(
|
||||
'title' => 'Panel',
|
||||
'no_blocks' => FALSE,
|
||||
'css_id' => '',
|
||||
'css' => '',
|
||||
'contexts' => array(
|
||||
'0' => array(
|
||||
'name' => 'simplecontext',
|
||||
'id' => 1,
|
||||
'identifier' => 'Configured simplecontext (not from argument)',
|
||||
'keyword' => 'configured_simplecontext',
|
||||
'context_settings' => array(
|
||||
'sample_simplecontext_setting' => 'default simplecontext setting',
|
||||
),
|
||||
),
|
||||
),
|
||||
'relationships' => array(
|
||||
'0' => array(
|
||||
'context' => 'argument_simplecontext_arg_2',
|
||||
'name' => 'relcontext_from_simplecontext',
|
||||
'id' => 1,
|
||||
'identifier' => 'Relcontext from simplecontext (from relationship)',
|
||||
'keyword' => 'relcontext',
|
||||
),
|
||||
),
|
||||
'access' => array(
|
||||
'logic' => 'and',
|
||||
),
|
||||
);
|
||||
$display = new panels_display;
|
||||
$display->layout = 'threecol_33_34_33_stacked';
|
||||
$display->layout_settings = array();
|
||||
$display->panel_settings = array(
|
||||
'style' => 'rounded_corners',
|
||||
'style_settings' => array(
|
||||
'default' => array(
|
||||
'corner_location' => 'pane',
|
||||
),
|
||||
),
|
||||
);
|
||||
$display->cache = array();
|
||||
$display->title = 'CTools plugin example panel';
|
||||
$display->hide_title = FALSE;
|
||||
$display->title_pane = 1;
|
||||
$display->content = array();
|
||||
$display->panels = array();
|
||||
$pane = new stdClass;
|
||||
$pane->pid = 'new-1';
|
||||
$pane->panel = 'left';
|
||||
$pane->type = 'no_context_content_type';
|
||||
$pane->subtype = 'no_context_content_type';
|
||||
$pane->shown = TRUE;
|
||||
$pane->access = array();
|
||||
$pane->configuration = array(
|
||||
'item1' => 'contents of config item 1',
|
||||
'item2' => 'contents of config item 2',
|
||||
'override_title' => 0,
|
||||
'override_title_text' => '',
|
||||
);
|
||||
$pane->cache = array();
|
||||
$pane->style = array();
|
||||
$pane->css = array();
|
||||
$pane->extras = array();
|
||||
$pane->position = 0;
|
||||
$display->content['new-1'] = $pane;
|
||||
$display->panels['left'][0] = 'new-1';
|
||||
$pane = new stdClass;
|
||||
$pane->pid = 'new-2';
|
||||
$pane->panel = 'left';
|
||||
$pane->type = 'custom';
|
||||
$pane->subtype = 'custom';
|
||||
$pane->shown = TRUE;
|
||||
$pane->access = array(
|
||||
'plugins' => array(
|
||||
'0' => array(
|
||||
'name' => 'arg_length',
|
||||
'settings' => array(
|
||||
'greater_than' => '1',
|
||||
'arg_length' => '4',
|
||||
),
|
||||
'context' => 'argument_simplecontext_arg_2',
|
||||
),
|
||||
),
|
||||
);
|
||||
$pane->configuration = array(
|
||||
'title' => 'Long Arg Visibility Block',
|
||||
'body' => 'This block will be here when the argument is longer than configured arg length. It uses the \'arg_length\' access plugin to test against the length of the argument used for Simplecontext.',
|
||||
'format' => '1',
|
||||
'substitute' => 1,
|
||||
);
|
||||
$pane->cache = array();
|
||||
$pane->style = array();
|
||||
$pane->css = array();
|
||||
$pane->extras = array();
|
||||
$pane->position = 1;
|
||||
$display->content['new-2'] = $pane;
|
||||
$display->panels['left'][1] = 'new-2';
|
||||
$pane = new stdClass;
|
||||
$pane->pid = 'new-3';
|
||||
$pane->panel = 'left';
|
||||
$pane->type = 'custom';
|
||||
$pane->subtype = 'custom';
|
||||
$pane->shown = TRUE;
|
||||
$pane->access = array(
|
||||
'plugins' => array(
|
||||
'0' => array(
|
||||
'name' => 'arg_length',
|
||||
'settings' => array(
|
||||
'greater_than' => '0',
|
||||
'arg_length' => '4',
|
||||
),
|
||||
'context' => 'argument_simplecontext_arg_2',
|
||||
),
|
||||
),
|
||||
);
|
||||
$pane->configuration = array(
|
||||
'title' => 'Short Arg Visibility',
|
||||
'body' => 'This block appears when the simplecontext argument is <i>less than</i> the configured length.',
|
||||
'format' => '1',
|
||||
'substitute' => 1,
|
||||
);
|
||||
$pane->cache = array();
|
||||
$pane->style = array();
|
||||
$pane->css = array();
|
||||
$pane->extras = array();
|
||||
$pane->position = 2;
|
||||
$display->content['new-3'] = $pane;
|
||||
$display->panels['left'][2] = 'new-3';
|
||||
$pane = new stdClass;
|
||||
$pane->pid = 'new-4';
|
||||
$pane->panel = 'middle';
|
||||
$pane->type = 'simplecontext_content_type';
|
||||
$pane->subtype = 'simplecontext_content_type';
|
||||
$pane->shown = TRUE;
|
||||
$pane->access = array();
|
||||
$pane->configuration = array(
|
||||
'buttons' => NULL,
|
||||
'#validate' => NULL,
|
||||
'#submit' => NULL,
|
||||
'#action' => NULL,
|
||||
'context' => 'argument_simplecontext_arg_2',
|
||||
'aligner_start' => NULL,
|
||||
'override_title' => 1,
|
||||
'override_title_text' => 'Simplecontext (with an arg)',
|
||||
'aligner_stop' => NULL,
|
||||
'override_title_markup' => NULL,
|
||||
'config_item_1' => 'Config item 1 contents',
|
||||
'#build_id' => NULL,
|
||||
'#type' => NULL,
|
||||
'#programmed' => NULL,
|
||||
'form_build_id' => 'form-19c4ae6cb54fad8f096da46e95694e5a',
|
||||
'#token' => NULL,
|
||||
'form_token' => '17141d3531eaa7b609da78afa6f3b560',
|
||||
'form_id' => 'simplecontext_content_type_edit_form',
|
||||
'#id' => NULL,
|
||||
'#description' => NULL,
|
||||
'#attributes' => NULL,
|
||||
'#required' => NULL,
|
||||
'#tree' => NULL,
|
||||
'#parents' => NULL,
|
||||
'#method' => NULL,
|
||||
'#post' => NULL,
|
||||
'#processed' => NULL,
|
||||
'#defaults_loaded' => NULL,
|
||||
);
|
||||
$pane->cache = array();
|
||||
$pane->style = array();
|
||||
$pane->css = array();
|
||||
$pane->extras = array();
|
||||
$pane->position = 0;
|
||||
$display->content['new-4'] = $pane;
|
||||
$display->panels['middle'][0] = 'new-4';
|
||||
$pane = new stdClass;
|
||||
$pane->pid = 'new-5';
|
||||
$pane->panel = 'middle';
|
||||
$pane->type = 'simplecontext_content_type';
|
||||
$pane->subtype = 'simplecontext_content_type';
|
||||
$pane->shown = TRUE;
|
||||
$pane->access = array();
|
||||
$pane->configuration = array(
|
||||
'buttons' => NULL,
|
||||
'#validate' => NULL,
|
||||
'#submit' => NULL,
|
||||
'#action' => NULL,
|
||||
'context' => 'context_simplecontext_1',
|
||||
'aligner_start' => NULL,
|
||||
'override_title' => 1,
|
||||
'override_title_text' => 'Configured simplecontext content type (not from arg)',
|
||||
'aligner_stop' => NULL,
|
||||
'override_title_markup' => NULL,
|
||||
'config_item_1' => '(configuration for simplecontext)',
|
||||
'#build_id' => NULL,
|
||||
'#type' => NULL,
|
||||
'#programmed' => NULL,
|
||||
'form_build_id' => 'form-d016200490abd015dc5b8a7e366d76ea',
|
||||
'#token' => NULL,
|
||||
'form_token' => '17141d3531eaa7b609da78afa6f3b560',
|
||||
'form_id' => 'simplecontext_content_type_edit_form',
|
||||
'#id' => NULL,
|
||||
'#description' => NULL,
|
||||
'#attributes' => NULL,
|
||||
'#required' => NULL,
|
||||
'#tree' => NULL,
|
||||
'#parents' => NULL,
|
||||
'#method' => NULL,
|
||||
'#post' => NULL,
|
||||
'#processed' => NULL,
|
||||
'#defaults_loaded' => NULL,
|
||||
);
|
||||
$pane->cache = array();
|
||||
$pane->style = array();
|
||||
$pane->css = array();
|
||||
$pane->extras = array();
|
||||
$pane->position = 1;
|
||||
$display->content['new-5'] = $pane;
|
||||
$display->panels['middle'][1] = 'new-5';
|
||||
$pane = new stdClass;
|
||||
$pane->pid = 'new-6';
|
||||
$pane->panel = 'middle';
|
||||
$pane->type = 'custom';
|
||||
$pane->subtype = 'custom';
|
||||
$pane->shown = TRUE;
|
||||
$pane->access = array();
|
||||
$pane->configuration = array(
|
||||
'admin_title' => 'Simplecontext keyword usage',
|
||||
'title' => 'Simplecontext keyword usage',
|
||||
'body' => 'Demonstrating context keyword usage:
|
||||
item1 is %sc:item1
|
||||
item2 is %sc:item2
|
||||
description is %sc:description',
|
||||
'format' => '1',
|
||||
'substitute' => 1,
|
||||
);
|
||||
$pane->cache = array();
|
||||
$pane->style = array();
|
||||
$pane->css = array();
|
||||
$pane->extras = array();
|
||||
$pane->position = 2;
|
||||
$display->content['new-6'] = $pane;
|
||||
$display->panels['middle'][2] = 'new-6';
|
||||
$pane = new stdClass;
|
||||
$pane->pid = 'new-7';
|
||||
$pane->panel = 'right';
|
||||
$pane->type = 'relcontext_content_type';
|
||||
$pane->subtype = 'relcontext_content_type';
|
||||
$pane->shown = TRUE;
|
||||
$pane->access = array();
|
||||
$pane->configuration = array(
|
||||
'buttons' => NULL,
|
||||
'#validate' => NULL,
|
||||
'#submit' => NULL,
|
||||
'#action' => NULL,
|
||||
'context' => 'relationship_relcontext_from_simplecontext_1',
|
||||
'aligner_start' => NULL,
|
||||
'override_title' => 0,
|
||||
'override_title_text' => '',
|
||||
'aligner_stop' => NULL,
|
||||
'override_title_markup' => NULL,
|
||||
'config_item_1' => 'some stuff in this one',
|
||||
'#build_id' => NULL,
|
||||
'#type' => NULL,
|
||||
'#programmed' => NULL,
|
||||
'form_build_id' => 'form-8485f84511bd06e51b4a48e998448054',
|
||||
'#token' => NULL,
|
||||
'form_token' => '1c3356396374d51d7d2531a10fd25310',
|
||||
'form_id' => 'relcontext_edit_form',
|
||||
'#id' => NULL,
|
||||
'#description' => NULL,
|
||||
'#attributes' => NULL,
|
||||
'#required' => NULL,
|
||||
'#tree' => NULL,
|
||||
'#parents' => NULL,
|
||||
'#method' => NULL,
|
||||
'#post' => NULL,
|
||||
'#processed' => NULL,
|
||||
'#defaults_loaded' => NULL,
|
||||
);
|
||||
$pane->cache = array();
|
||||
$pane->style = array();
|
||||
$pane->css = array();
|
||||
$pane->extras = array();
|
||||
$pane->position = 0;
|
||||
$display->content['new-7'] = $pane;
|
||||
$display->panels['right'][0] = 'new-7';
|
||||
$pane = new stdClass;
|
||||
$pane->pid = 'new-8';
|
||||
$pane->panel = 'top';
|
||||
$pane->type = 'custom';
|
||||
$pane->subtype = 'custom';
|
||||
$pane->shown = TRUE;
|
||||
$pane->access = array();
|
||||
$pane->configuration = array(
|
||||
'title' => 'Demonstrating ctools plugins',
|
||||
'body' => 'The CTools Plugin Example module (and this panel page) are just here to demonstrate how to build CTools plugins.
|
||||
|
||||
',
|
||||
'format' => '2',
|
||||
'substitute' => 1,
|
||||
);
|
||||
$pane->cache = array();
|
||||
$pane->style = array();
|
||||
$pane->css = array();
|
||||
$pane->extras = array();
|
||||
$pane->position = 0;
|
||||
$display->content['new-8'] = $pane;
|
||||
$display->panels['top'][0] = 'new-8';
|
||||
$handler->conf['display'] = $display;
|
||||
$page->default_handlers[$handler->name] = $handler;
|
||||
|
||||
// end of exported panel.
|
||||
$pages['ctools_plugin_example_demo_page'] = $page;
|
||||
|
||||
// begin exported panel
|
||||
|
||||
$page = new stdClass;
|
||||
$page->disabled = FALSE; /* Edit this to true to make a default page disabled initially */
|
||||
$page->api_version = 1;
|
||||
$page->name = 'ctools_plugin_example_base';
|
||||
$page->task = 'page';
|
||||
$page->admin_title = 'CTools Plugin Example base page';
|
||||
$page->admin_description = 'This panel is for when people hit /ctools_plugin_example without an argument. We can use it to tell people to move on.';
|
||||
$page->path = 'ctools_plugin_example';
|
||||
$page->access = array();
|
||||
$page->menu = array();
|
||||
$page->arguments = array();
|
||||
$page->conf = array();
|
||||
$page->default_handlers = array();
|
||||
$handler = new stdClass;
|
||||
$handler->disabled = FALSE; /* Edit this to true to make a default handler disabled initially */
|
||||
$handler->api_version = 1;
|
||||
$handler->name = 'page_ctools_plugin_example_base_panel_context';
|
||||
$handler->task = 'page';
|
||||
$handler->subtask = 'ctools_plugin_example_base';
|
||||
$handler->handler = 'panel_context';
|
||||
$handler->weight = 0;
|
||||
$handler->conf = array(
|
||||
'title' => 'Panel',
|
||||
'no_blocks' => FALSE,
|
||||
'css_id' => '',
|
||||
'css' => '',
|
||||
'contexts' => array(),
|
||||
'relationships' => array(),
|
||||
);
|
||||
$display = new panels_display;
|
||||
$display->layout = 'onecol';
|
||||
$display->layout_settings = array();
|
||||
$display->panel_settings = array();
|
||||
$display->cache = array();
|
||||
$display->title = '';
|
||||
$display->hide_title = FALSE;
|
||||
$display->content = array();
|
||||
$display->panels = array();
|
||||
$pane = new stdClass;
|
||||
$pane->pid = 'new-1';
|
||||
$pane->panel = 'middle';
|
||||
$pane->type = 'custom';
|
||||
$pane->subtype = 'custom';
|
||||
$pane->shown = TRUE;
|
||||
$pane->access = array();
|
||||
$pane->configuration = array(
|
||||
'title' => 'Use this page with an argument',
|
||||
'body' => 'This demo page works if you use an argument, like <a href="ctools_plugin_example/xxxxx">ctools_plugin_example/xxxxx</a>.',
|
||||
'format' => '1',
|
||||
'substitute' => NULL,
|
||||
);
|
||||
$pane->cache = array();
|
||||
$pane->style = array();
|
||||
$pane->css = array();
|
||||
$pane->extras = array();
|
||||
$pane->position = 0;
|
||||
$display->content['new-1'] = $pane;
|
||||
$display->panels['middle'][0] = 'new-1';
|
||||
$handler->conf['display'] = $display;
|
||||
$page->default_handlers[$handler->name] = $handler;
|
||||
// end exported panel.
|
||||
|
||||
$pages['base_page'] = $page;
|
||||
|
||||
return $pages;
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
<div id="node-16" class="node">
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="content clear-block">
|
||||
<p>We can use access plugins to determine access to a page or visibility of the panes in a page. Basically, we just determine access based on configuration settings and the various contexts that are available to us.</p>
|
||||
<p>The arbitrary example in plugins/access/arg_length.inc determines access based on the length of the simplecontext argument. You can configure whether access should be granted if the simplecontext argument is greater or less than some number.</p>
|
||||
</div>
|
||||
|
||||
<div class="clear-block">
|
||||
<div class="meta">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
@ -0,0 +1,20 @@
|
||||
<div id="node-12" class="node">
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="content clear-block">
|
||||
<p>Contexts are fundamental to CTools, and they almost always start with an argument to a panels page, so we'll start there too.</p>
|
||||
<p>We first need to process an argument.</p>
|
||||
<p>We're going to work with a "Simplecontext" context type and argument, and then with a content type that displays it. So we'll start by with the Simplecontext argument plugin in plugins/arguments/simplecontext_arg.inc.</p>
|
||||
<p>Note that the name of the file (simplecontext_arg.inc) is built from the machine name of our plugin (simplecontext_arg). And note also that the primary function that we use to provide our argument (ctools_plugin_example_simplecontext_arg_ctools_arguments()) is also built from the machine name. This magic is most of the naming magic that you have to know.</p>
|
||||
<p>You can browse plugins/arguments/simplecontext_arg.inc and see the little that it does.</p>
|
||||
</div>
|
||||
|
||||
<div class="clear-block">
|
||||
<div class="meta">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
@ -0,0 +1,19 @@
|
||||
<div id="node-10" class="node">
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="content clear-block">
|
||||
<p>This demonstration module is intended for developers to look at and play with. CTools plugins are not terribly difficult to do, but it can be hard to sort through the various arguments and required functions. The idea here is that you should have a starting point for most anything you want to do. Just work through the example, and then start experimenting with changing it.</p>
|
||||
<p>There are two parts to this demo: </p>
|
||||
<p>First, there is a sample panel provided that uses all the various plugins. It's at <a href="/ctools_plugin_example/12345">ctools_example/12345</a>. You can edit the panel and configure all the panes on it.</p>
|
||||
<p>Second, the code is there for you to experiment with and change as you see fit. Sometimes starting with simple code and working with it can take you places that it's hard to go when you're looking at more complex examples.</p>
|
||||
</div>
|
||||
|
||||
<div class="clear-block">
|
||||
<div class="meta">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
@ -0,0 +1,17 @@
|
||||
<div id="node-14" class="node">
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="content clear-block">
|
||||
<p>Now we get to the heart of the matter: Building a content type plugin. A content type plugin uses the contexts available to it to display something. plugins/content_types/simplecontext_content_type.inc does this work for us.</p>
|
||||
<p>Note that our content type also has an edit form which can be used to configure its behavior. This settings form is accessed through the panels interface, and it's up to you what the settings mean to the code and the generation of content in the display rendering.</p>
|
||||
</div>
|
||||
|
||||
<div class="clear-block">
|
||||
<div class="meta">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
@ -0,0 +1,21 @@
|
||||
<div id="node-13" class="node">
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="content clear-block">
|
||||
<p>Now that we have a plugin for a simplecontext argument, we can create a plugin for a simplecontext context. </p>
|
||||
<p>Normally, a context would take an argument which is a key like a node ID (nid) and retrieve a more complex object from a database or whatever. In our example, we'll artificially transform the argument into an arbitrary "context" data object. </p>
|
||||
<p>plugins/contexts/simplecontext.inc implements our context.</p>
|
||||
<p>Note that there are actually two ways to create a context. The normal one, which we've been referring to, is to create a context from an argument. However, it is also possible to configure a context in a panel using the panels interface. This is quite inflexible, but might be useful for configuring single page. However, it means that we have a settings form for exactly that purpose. Our context would have to know how to create itself from a settings form as well as from an argument. Simplecontext can do that.</p>
|
||||
<p>A context plugin can also provide keywords that expose parts of its context using keywords like masterkeyword:dataitem. The node plugin for ctools has node:nid and node:title, for example. The simplecontext plugin here provides the simplest of keywords.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="clear-block">
|
||||
<div class="meta">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
@ -0,0 +1,20 @@
|
||||
<div id="node-11" class="node">
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="content clear-block">
|
||||
<p>Your module must provide a few things so that your plugins can be found.</p>
|
||||
<p>First, you need to implement hook_ctools_plugin_directory(). Here we're telling CTools that our plugins will be found in the module's directory in the plugins/<plugintype> directory. Context plugins will be in ctools_plugin_example/plugins/contexts, Content-type plugins will be in ctools_plugin_example/plugins/content_types.</p>
|
||||
<p><div class="codeblock"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">ctools_plugin_example_ctools_plugin_directory</span><span style="color: #007700">(</span><span style="color: #0000BB">$module</span><span style="color: #007700">, </span><span style="color: #0000BB">$plugin</span><span style="color: #007700">) {<br /> if (</span><span style="color: #0000BB">$module </span><span style="color: #007700">== </span><span style="color: #DD0000">'ctools' </span><span style="color: #007700">&& !empty(</span><span style="color: #0000BB">$plugin</span><span style="color: #007700">)) {<br /> return </span><span style="color: #DD0000">"plugins/$plugin"</span><span style="color: #007700">;<br /> }<br />}<br /></span><span style="color: #0000BB">?></span></span></code></div></p>
|
||||
<p>Second, if you module wants to provide default panels pages, you can implement hook_ctools_plugin_api(). CTools will then pick up your panels pages in the file named <modulename>.pages_default.inc.</p>
|
||||
<p><div class="codeblock"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">ctools_plugin_example_ctools_plugin_api</span><span style="color: #007700">(</span><span style="color: #0000BB">$module</span><span style="color: #007700">, </span><span style="color: #0000BB">$api</span><span style="color: #007700">) {<br /> if (</span><span style="color: #0000BB">$module </span><span style="color: #007700">== </span><span style="color: #DD0000">'panels_mini' </span><span style="color: #007700">&& </span><span style="color: #0000BB">$api </span><span style="color: #007700">== </span><span style="color: #DD0000">'panels_default'</span><span style="color: #007700">) {<br /> return array(</span><span style="color: #DD0000">'version' </span><span style="color: #007700">=> </span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /> }<br /> if (</span><span style="color: #0000BB">$module </span><span style="color: #007700">== </span><span style="color: #DD0000">'page_manager' </span><span style="color: #007700">&& </span><span style="color: #0000BB">$api </span><span style="color: #007700">== </span><span style="color: #DD0000">'pages_default'</span><span style="color: #007700">) {<br /> return array(</span><span style="color: #DD0000">'version' </span><span style="color: #007700">=> </span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /> }<br />}<br /></span><span style="color: #0000BB">?></span></span></code></div></p>
|
||||
</div>
|
||||
|
||||
<div class="clear-block">
|
||||
<div class="meta">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
@ -0,0 +1,18 @@
|
||||
<div id="node-15" class="node">
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="content clear-block">
|
||||
<p>Often a single data type can lead us to other data types. For example, a node has a user (the author) and the user has data associated with it.</p>
|
||||
<p>A relationship plugin allows this kind of data to be accessed. </p>
|
||||
<p>An example relationship plugin is provided in plugins/relationships/relcontext_from_simplecontext.inc. It looks at a simplecontext (which we got from an argument) and builds an (artificial) "relcontext" from that.</p>
|
||||
</div>
|
||||
|
||||
<div class="clear-block">
|
||||
<div class="meta">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
@ -0,0 +1,42 @@
|
||||
[Chaos-Tools--CTools--Plugin-Examples]
|
||||
title = CTools Plugin Examples
|
||||
file = Chaos-Tools--CTools--Plugin-Examples
|
||||
weight = 0
|
||||
parent =
|
||||
|
||||
[Module-setup-and-hooks]
|
||||
title = Module setup and hooks
|
||||
file = Module-setup-and-hooks
|
||||
weight = -15
|
||||
parent = Chaos-Tools--CTools--Plugin-Examples
|
||||
|
||||
[Argument-Plugins--Starting-at-the-beginning]
|
||||
title = Argument Plugins: Starting at the beginning
|
||||
file = Argument-Plugins--Starting-at-the-beginning
|
||||
weight = -14
|
||||
parent = Chaos-Tools--CTools--Plugin-Examples
|
||||
|
||||
[Context-plugins--Creating-a--context--from-an-argument]
|
||||
title = Context plugins: Creating a context from an argument
|
||||
file = Context-plugins--Creating-a--context--from-an-argument
|
||||
weight = -13
|
||||
parent = Chaos-Tools--CTools--Plugin-Examples
|
||||
|
||||
[Content-Type-Plugins--Displaying-content-using-a-context]
|
||||
title = Content Type Plugins: Displaying content using a context
|
||||
file = Content-Type-Plugins--Displaying-content-using-a-context
|
||||
weight = -12
|
||||
parent = Chaos-Tools--CTools--Plugin-Examples
|
||||
|
||||
[Access-Plugins--Determining-access-and-visibility]
|
||||
title = Access Plugins: Determining access and visibility
|
||||
file = Access-Plugins--Determining-access-and-visibility
|
||||
weight = -11
|
||||
parent = Chaos-Tools--CTools--Plugin-Examples
|
||||
|
||||
[Relationships--Letting-one-context-take-us-to-another]
|
||||
title = Relationships: Letting one context take us to another
|
||||
file = Relationships--Letting-one-context-take-us-to-another
|
||||
weight = -10
|
||||
parent = Chaos-Tools--CTools--Plugin-Examples
|
||||
|
@ -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