| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: simplecontext.inc,v 1.1.2.1 2010/01/29 19:54:02 merlinofchaos Exp $ 3 4 5 /** 6 * @file 7 * Sample ctools context type plugin that shows how to create a context from an arg. 8 * 9 */ 10 11 /** 12 * Plugins are described by creating a $plugin array which will be used 13 * by the system that includes this file. 14 */ 15 $plugin = array( 16 'title' => t("Simplecontext"), 17 'description' => t('A single "simplecontext" context, or data element.'), 18 'context' => 'ctools_plugin_example_context_create_simplecontext', // func to create context 19 'context name' => 'simplecontext', 20 'settings form' => 'simplecontext_settings_form', 21 'keyword' => 'simplecontext', 22 23 // Provides a list of items which are exposed as keywords. 24 'convert list' => 'simplecontext_convert_list', 25 // Convert keywords into data. 26 'convert' => 'simplecontext_convert', 27 28 'placeholder form' => array( 29 '#type' => 'textfield', 30 '#description' => t('Enter some data to represent this "simplecontext".'), 31 ), 32 ); 33 34 /** 35 * Create a context, either from manual configuration or from an argument on the URL. 36 * 37 * @param $empty 38 * If true, just return an empty context. 39 * @param $data 40 * If from settings form, an array as from a form. If from argument, a string. 41 * @param $conf 42 * TRUE if the $data is coming from admin configuration, FALSE if it's from a URL arg. 43 * 44 * @return 45 * a Context object/ 46 */ 47 function ctools_plugin_example_context_create_simplecontext($empty, $data = NULL, $conf = FALSE) { 48 $context = new ctools_context('simplecontext'); 49 $context->plugin = 'simplecontext'; 50 51 if ($empty) { 52 return $context; 53 } 54 55 if ($conf) { 56 if (!empty($data)) { 57 $context->data = new stdClass(); 58 // For this simple item we'll just create our data by stripping non-alpha and 59 // adding '_from_configuration_item_1' to it. 60 $context->data->item1 = t("Item1"); 61 $context->data->item2 = t("Item2"); 62 $context->data->description = preg_replace('/[^a-z]/i', '', $data['sample_simplecontext_setting']); 63 $context->data->description .= '_from_configuration_sample_simplecontext_setting'; 64 $context->title = t("Simplecontext context from config"); 65 return $context; 66 } 67 } 68 else { 69 // $data is coming from an arg - it's just a string. 70 // This is used for keyword. 71 $context->title = $data; 72 $context->argument = $data; 73 // Make up a bogus context 74 $context->data = new stdClass(); 75 $context->data->item1 = t("Item1"); 76 $context->data->item2 = t("Item2"); 77 78 // For this simple item we'll just create our data by stripping non-alpha and 79 // adding '_from_simplecontext_argument' to it. 80 $context->data->description = preg_replace('/[^a-z]/i', '', $data); 81 $context->data->description .= '_from_simplecontext_argument'; 82 $context->arg_length = strlen($context->argument); 83 return $context; 84 } 85 } 86 87 function simplecontext_settings_form($conf, $external = FALSE) { 88 if (empty($conf)) { 89 $conf = array( 90 'sample_simplecontext_setting' => 'default simplecontext setting', 91 ); 92 } 93 $form = array(); 94 $form['sample_simplecontext_setting'] = array( 95 '#type' => 'textfield', 96 '#title' => t('Setting for simplecontext'), 97 '#size' => 50, 98 '#description' => t('An example setting that could be used to configure a context'), 99 '#default_value' => $conf['sample_simplecontext_setting'], 100 '#prefix' => '<div class="clear-block no-float">', 101 '#suffix' => '</div>', 102 ); 103 return $form; 104 } 105 106 107 108 /** 109 * Provide a list of sub-keywords. 110 * 111 * This is used to provide keywords from the context for use in a content type, 112 * pane, etc. 113 */ 114 function simplecontext_convert_list() { 115 return array( 116 'item1' => t('Item1'), 117 'item2' => t('Item2'), 118 'description' => t('Description'), 119 ); 120 } 121 122 /** 123 * Convert a context into a string to be used as a keyword by content types, etc. 124 */ 125 function simplecontext_convert($context, $type) { 126 switch ($type) { 127 case 'item1': 128 return $context->data->item1; 129 case 'item2': 130 return $context->data->item2; 131 case 'description': 132 return $context->data->description; 133 } 134 } 135
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |