5 * Plugin to provide access control/visibility based on length of
6 * simplecontext argument (in URL).
10 * Plugins are described by creating a $plugin array which will be used
11 * by the system that includes this file.
14 'title' => t("Arg length"),
15 'description' => t('Control access by length of simplecontext argument.'),
16 'callback' => 'ctools_plugin_example_arg_length_ctools_access_check',
17 'settings form' => 'ctools_plugin_example_arg_length_ctools_access_settings',
18 'summary' => 'ctools_plugin_example_arg_length_ctools_access_summary',
19 'required context' => new ctools_context_required(t('Simplecontext'), 'simplecontext'),
23 * Settings form for the 'by role' access plugin.
25 function ctools_plugin_example_arg_length_ctools_access_settings(&$form, &$form_state, $conf) {
26 $form['settings']['greater_than'] = array(
28 '#title' => t('Grant access if simplecontext argument length is'),
29 '#options' => array(1 => t('Greater than'), 0 => t('Less than or equal to')),
30 '#default_value' => $conf['greater_than'],
32 $form['settings']['arg_length'] = array(
33 '#type' => 'textfield',
34 '#title' => t('Length of simplecontext argument'),
36 '#default_value' => $conf['arg_length'],
37 '#description' => t('Access/visibility will be granted based on arg length.'),
44 function ctools_plugin_example_arg_length_ctools_access_check($conf, $context) {
45 // As far as I know there should always be a context at this point, but this
47 if (empty($context) || empty($context->data)) {
50 $compare = ($context->arg_length > $conf['arg_length']);
51 if (($compare && $conf['greater_than']) || (!$compare && !$conf['greater_than'])) {
58 * Provide a summary description based upon the checked roles.
60 function ctools_plugin_example_arg_length_ctools_access_summary($conf, $context) {
61 return t('Simpletext argument must be !comp @length characters',
62 array('!comp' => $conf['greater_than'] ? 'greater than' : 'less than or equal to',
63 '@length' => $conf['arg_length']));