Skip to content
Snippets Groups Projects
Commit 9398d6a6 authored by Earl Miles's avatar Earl Miles
Browse files

Move context from Panels to CTools. This includes a bunch of stuff:

- a tool for AJAX, which is the next generation tool based on what Views uses.
- a tool for modals -- completely ripping the modal out of Panels.
- moving plugins for 'arguments', 'relationships' and 'contexts' into CTools.
parent 4b9a680b
No related branches found
No related tags found
No related merge requests found
Showing
with 2194 additions and 44 deletions
/* $Id$ */
.panels-context-holder .panels-context-title {
float: left;
width: 49%;
font-style: italic;
}
.panels-context-holder .panels-context-content {
float: right;
width: 49%;
}
/* $Id$ */
div.ctools-modal-content {
background: #fff;
color: #000;
padding: 0;
margin: 2px;
border: 1px solid #000;
width: 600px;
text-align: left;
}
div.ctools-modal-content .modal-title {
font-size: 120%;
font-weight: bold;
color: white;
overflow: hidden;
white-space: nowrap;
}
div.ctools-modal-content .modal-header {
background-color: #2385c2;
padding: 0 .25em 0 1em;
}
div.ctools-modal-content .modal-header a {
color: white;
float: right;
}
div.ctools-modal-content .modal-content {
padding: 0 1em;
overflow: auto;
width: 575px;
height: 400px;
}
div.ctools-modal-content .modal-form {
}
div.ctools-modal-content .form-checkboxes .form-item {
float: left;
width: 24%;
}
div.ctools-modal-content a.close {
color: white;
}
div.ctools-modal-content a.close:hover {
text-decoration: none;
}
div.ctools-modal-content a.close img {
position: relative;
top: 1px;
}
div.ctools-modal-content .modal-content .modal-throbber-wrapper {
width: 575px;
height: 400px;
text-align: center;
}
div.ctools-modal-content .modal-content .modal-throbber-wrapper img {
margin-top: 160px;
}
/** modal forms CSS **/
div.ctools-modal-content .form-item label {
width: 8em;
float: left;
}
div.ctools-modal-content .form-item label.option {
width: auto;
float: none;
}
div.ctools-modal-content .form-item .description {
clear: left;
}
div.ctools-modal-content .form-item .description .tips {
margin-left: 2em;
}
div.ctools-modal-content .no-float .form-item * {
float: none;
}
div.ctools-modal-content .modal-form .no-float label {
width: auto;
}
div.ctools-modal-content .modal-form fieldset,
div.ctools-modal-content .modal-form .form-checkboxes {
clear: left;
}
<?php
// $Id$
/**
* @file
* CTools primary module file.
*
* Most of the CTools tools are in their own .inc files. This contains
* nothing more than a few convenience functions and some hooks that
* must be implemented in the module file.
*/
/**
* Include ctools .inc files as necessary.
*/
......@@ -14,54 +22,71 @@ function ctools_include($file) {
}
/**
* Implementation of hook_theme().
* Provide the proper path to a CTools image
*/
function ctools_theme() {
return array(
'ctools_collapsible' => array(
'arguments' => array('handle' => NULL, 'content' => NULL, 'collapsed' => FALSE),
'file' => 'includes/collapsible-div.inc',
),
);
function ctools_image_path($image) {
return drupal_get_path('module', 'ctools') . '/images/' . $image;
}
/**
* Fetch a group of plugins by name.
*
* @param $module
* The name of the module that utilizes this plugin system. It will be
* used to call hook_ctools_plugin_$plugin() to get more data about the plugin.
* @param $type
* The type identifier of the plugin.
* @param $id
* If specified, return only information about plugin with this identifier.
* The system will do its utmost to load only plugins with this id.
*
* @return
* An array of information arrays about the plugins received. The contents
* of the array are specific to the plugin.
* Include views .css files.
*/
function ctools_get_plugins($module, $type, $id = NULL) {
ctools_include('plugins');
return _ctools_get_plugins($module, $type, $id);
function ctools_add_css($file) {
drupal_add_css(drupal_get_path('module', 'ctools') . "/css/$file.css");
}
/**
* Provide a form for displaying an export.
* Include views .js files.
*/
function ctools_add_js($file) {
drupal_add_js(drupal_get_path('module', 'ctools') . "/js/$file.js");
}
/**
* Provide a hook passthrough to included files.
*
* This is a simple form that should be invoked like this:
* @code
* $output = drupal_get_form('ctools_export_form', $code, $object_title);
* @endcode
* To organize things neatly, each CTools tool gets its own toolname.$type.inc
* file. If it exists, it's loaded and ctools_$tool_$type() is executed.
* To save time we pass the $items array in so we don't need to do array
* addition. It modifies the array by reference and doesn't need to return it.
*/
function _ctools_passthrough(&$items, $type = 'theme') {
$files = drupal_system_listing('.' . $type . '.inc$', drupal_get_path('module', 'ctools') . '/includes', 'name', 0);
foreach ($files as $file) {
require_once './' . $file->filename;
list($tool) = explode('.', $file->name, 2);
$function = 'ctools_' . $tool . '_' . $type;
if (function_exists($function)) {
$function($items);
}
}
}
/**
* Implementation of hook_theme().
*/
function ctools_theme() {
$items = array();
_ctools_passthrough($items, 'theme');
return $items;
}
/**
* Implementation of hook_menu().
*/
function ctools_export_form(&$form_state, $code, $title = '') {
$lines = substr_count($code, "\n");
$form['code'] = array(
'#type' => 'textarea',
'#title' => $title,
'#default_value' => $code,
'#rows' => $lines,
);
function ctools_menu() {
$items = array();
_ctools_passthrough($items, 'menu');
return $items;
}
return $form;
}
\ No newline at end of file
/**
* Implementation of hook_ctools_plugin_dierctory() to let the system know
* we implement task and task_handler plugins.
*/
function ctools_ctools_plugin_directory($module, $plugin) {
if ($module == 'ctools') {
return 'plugins/' . $plugin;
}
}
......@@ -874,6 +874,7 @@ function delegator_administer_task_handler_export($task_name, $name) {
$title = delegator_get_handler_title($plugin, $handler, $task, $subtask_id);
drupal_set_title(t('Export task handler "@title"', array('@title' => $title)));
ctools_include('export');
return drupal_get_form('ctools_export_form', delegator_export_task_handler($handler), $title);
}
......
......@@ -333,6 +333,7 @@ function delegator_update_task_handler_weight($handler, $weight) {
* Shortcut function to get task plugins.
*/
function delegator_get_tasks() {
ctools_include('plugins');
return ctools_get_plugins('delegator', 'tasks');
}
......@@ -340,6 +341,7 @@ function delegator_get_tasks() {
* Shortcut function to get a task plugin.
*/
function delegator_get_task($id) {
ctools_include('plugins');
return ctools_get_plugins('delegator', 'tasks', $id);
}
......@@ -347,6 +349,7 @@ function delegator_get_task($id) {
* Shortcut function to get task handler plugins.
*/
function delegator_get_task_handlers() {
ctools_include('plugins');
return ctools_get_plugins('delegator', 'task_handlers');
}
......@@ -354,6 +357,7 @@ function delegator_get_task_handlers() {
* Shortcut function to get a task handler plugin.
*/
function delegator_get_task_handler($id) {
ctools_include('plugins');
return ctools_get_plugins('delegator', 'task_handlers', $id);
}
......@@ -407,8 +411,8 @@ function delegator_get_handler_summary($plugin, $handler, $task, $subtask_id) {
* Implementation of hook_ctools_plugin_dierctory() to let the system know
* we implement task and task_handler plugins.
*/
function delegator_ctools_plugin_directory($plugin) {
if ($plugin == 'tasks' || $plugin == 'task_handlers') {
function delegator_ctools_plugin_directory($module, $plugin) {
if ($module == 'delegator') {
return 'plugins/' . $plugin;
}
}
......
<!-- $Id$ -->
Arguments create a context from external input, which is assumed to be a
string as though it came from a URL element.
'title' => title
'description' => Description
'keyword' => Default keyword for the context
'context' => Callback to create the context. Params: $arg = NULL, $conf = NULL, $empty = FALSE
'settings form' => params: $conf
'settings form validate' => params: $form, $form_state
'settings form submit' => params: $form, $form_state
<!-- $Id$ -->
Context plugin data:
'title' => Visible title
'description' => Description of context
'context' => Callback to create a context. Params: $empty, $data = NULL, $conf = FALSE
'settings form' => Callback to show a context setting form. Params: ($conf, $external = FALSE)
'settings form validate' => params: ($form, &$form_values, &$form_state)
'settings form submit' => params: 'ctools_context_node_settings_form_submit',
'keyword' => The default keyword to use.
'context name' => The unique identifier for this context for use by required context checks.
'no ui' => if TRUE this context cannot be selected.
<!-- $Id$ -->
'title' => The title to display.
'description' => Description to display.
'keyword' => Default keyword for the context created by this relationship.
'required context' => One or more ctools_context_required/optional objects
describing the context input.
new panels_required_context(t('Node'), 'node'),
'context' => The callback to create the context. Params: ($context = NULL, $conf)
'settings form' => Settings form. Params: $conf
'settings form validate' => Validate.
<!-- $Id$ -->
<!-- $Id$ -->
......@@ -27,6 +27,14 @@ Automatically filled in data:
path
file
Use of hook_ctools_plugin_TYPE to define info about your plugin.
$info += array(
'module' => $module,
'type' => $type,
'cache' => FALSE,
'defaults' => array(),
'hook' => $module . '_' . $type,
);
General feature for callbacks:
either 'function_name' or
......@@ -36,4 +44,4 @@ General feature for callbacks:
'function' => 'function_name'
),
Using ctools_plugin_get_function() of ctools_plugin_load_function() will take advantage.
\ No newline at end of file
Using ctools_plugin_get_function() or ctools_plugin_load_function() will take advantage.
\ No newline at end of file
<!-- $Id$ -->
Implementing hook_ctools_plugin_directory()
Implementing hook_ctools_plugin_directory($module, $plugin)
Creating a pluginname.inc file
Naming the function properly within this file:
returning 1 or more plugins per file:
Best practices
......
images/icon-close-window.png

877 B

images/icon-configure.png

765 B

images/icon-delete.png

877 B

images/throbber.gif

3.13 KiB

<?php
// $Id$
/**
* @file
* Utilize the CTools AJAX responder.
*
* The AJAX responder is a javascript tool to make it very easy to do complicated
* operations as a response to AJAX requests. When links are attached to the ajax
* responder, the server sends back a packet of JSON data; this packet is an
* array of commands to carry out.
*
* The command names correlate to functions in the responder space, making it
* relatively easy for applications to provide their own commands to do whatever
* spiffy functionality is necessary.
*
* Each command is an object. $object->command is the type of command and
* will be used to find the function (it will correllate directly to
* a function in the Drupal.CTools.AJAX.Command space). The object can
* contain any other data that the command needs to process.
*
* Built in commands:
* - replace
* - selector: The CSS selector. This can be any selector jquery uses in $().
* - data: The data to use with the jquery replace() function.
*
* - append
* - selector: The CSS selector. This can be any selector jquery uses in $().
* - data: The data to use with the jquery append() function.
*
* - addClass
* - selector: The CSS selector. This can be any selector jquery uses in $().
* - data: The class to add.
*
* - alert
* - title: The title of the alert.
* - data: The data in the alert.
*/
/**
* Render an image as a button link. This will automatically apply an AJAX class
* to the link and add the appropriate javascript to make this happen.
*
* @param $image
* The path to an image to use that will be sent to theme('image') for rendering.
* @param $dest
* The destination of the link.
* @param $alt
* The alt text of the link.
* @param $class
* Any class to apply to the link. @todo this should be a options array.
*/
function ctools_ajax_image_button($image, $dest, $alt, $class = '') {
return ctools_ajax_text_button(theme('image', $image), $dest, $alt, $class);
}
/**
* Render text as a link. This will automatically apply an AJAX class
* to the link and add the appropriate javascript to make this happen.
*
* Note: 'html' => true so be sure any text is vetted! Chances are these kinds of buttons will
* not use user input so this is a very minor concern.
*
* @param $image
* The path to an image to use that will be sent to theme('image') for rendering.
* @param $dest
* The destination of the link.
* @param $alt
* The alt text of the link.
* @param $class
* Any class to apply to the link. @todo this should be a options array.
* @param $type
* A type to use, in case a different behavior should be attached. Defaults
* to ctools-use-ajax.
*/
function ctools_ajax_text_button($text, $dest, $alt, $class = '', $type = 'ctools-use-ajax') {
return l($text, $dest, array('html' => TRUE, 'attributes' => array('class' => "$type $class", 'title' => $alt, 'alt' => $alt)));
}
/**
* Create a command array for the error case.
*/
function ctools_ajax_command_error($error = '') {
return array(
'command' => 'alert',
'title' => t('Error'),
'text' => $error ? $error : t('Server reports invalid input error.'),
);
}
/**
* Create a replace command for the AJAX responder.
*
* The replace command will replace a portion of the current document
* with the specified HTML.
*
* @param $selector
* The CSS selector. This can be any selector jquery uses in $().
* @param $html
* The data to use with the jquery replace() function.
*/
function ctools_ajax_command_replace($selector, $html) {
return array(
'command' => 'replace',
'selector' => $selector,
'data' => $html,
);
}
/**
* Create an append command for the AJAX responder.
*
* This will append the HTML to the specified selector.
*
* @param $selector
* The CSS selector. This can be any selector jquery uses in $().
* @param $html
* The data to use with the jquery append() function.
*/
function ctools_ajax_command_append($selector, $html) {
return array(
'command' => 'append',
'selector' => $selector,
'data' => $html,
);
}
/**
* Create a changed command for the AJAX responder.
*
* This will mark an item as 'changed'.
*
* @param $selector
* The CSS selector. This can be any selector jquery uses in $().
* @param $star
* An optional CSS selector which must be inside $selector. If specified,
* a star will be appended.
*/
function ctools_ajax_command_changed($selector, $star = '') {
return array(
'command' => 'changed',
'selector' => $selector,
'star' => $star,
);
}
/**
* Force a table to be restriped.
*
* This is usually used after a table has been modifed by a replace or append
* command.
*
* @param $selector
* The CSS selector. This can be any selector jquery uses in $().
*/
function ctools_ajax_command_restripe($selector) {
return array(
'command' => 'restripe',
'selector' => $selector,
);
}
/**
* Render a commands array into JSON and immediately hand this back
* to the AJAX requester.
*/
function ctools_ajax_render($commands = array()) {
drupal_json($commands);
exit;
}
/**
* Send an error response back via AJAX and immediately exit.
*/
function ctools_ajax_render_error($error = '') {
$commands = array();
$commands[] = ctools_ajax_command_error($error);
ctools_ajax_render($commands);
}
<?php
// $Id$
/**
* @file
* Theme registry for collapsible-div tool.
*/
function ctools_collapsible_theme($items) {
$items['ctools_collapsible'] = array(
'arguments' => array('handle' => NULL, 'content' => NULL, 'collapsed' => FALSE),
'file' => 'includes/collapsible-div.inc',
);
}
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment