arg_length.inc

  1. cis7 sites/all/modules/ulmus/ctools/ctools_plugin_example/plugins/access/arg_length.inc
  2. cle7 sites/all/modules/ulmus/ctools/ctools_plugin_example/plugins/access/arg_length.inc
  3. ecd7 sites/all/modules/ulmus/ctools/ctools_plugin_example/plugins/access/arg_length.inc
  4. elmsmedia7 sites/all/modules/ulmus/ctools/ctools_plugin_example/plugins/access/arg_length.inc
  5. harmony7 sites/all/modules/ulmus/ctools/ctools_plugin_example/plugins/access/arg_length.inc
  6. icor7 sites/all/modules/ulmus/ctools/ctools_plugin_example/plugins/access/arg_length.inc
  7. meedjum_blog7 sites/all/modules/ulmus/ctools/ctools_plugin_example/plugins/access/arg_length.inc
  8. mooc7 sites/all/modules/ulmus/ctools/ctools_plugin_example/plugins/access/arg_length.inc

Plugin to provide access control/visibility based on length of simplecontext argument (in URL).

Functions

Namesort descending Description
ctools_plugin_example_arg_length_ctools_access_check Check for access.
ctools_plugin_example_arg_length_ctools_access_settings Settings form for the 'by role' access plugin.
ctools_plugin_example_arg_length_ctools_access_summary Provide a summary description based upon the checked roles.

File

sites/all/modules/ulmus/ctools/ctools_plugin_example/plugins/access/arg_length.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Plugin to provide access control/visibility based on length of
  5. * simplecontext argument (in URL).
  6. */
  7. /**
  8. * Plugins are described by creating a $plugin array which will be used
  9. * by the system that includes this file.
  10. */
  11. $plugin = array(
  12. 'title' => t("Arg length"),
  13. 'description' => t('Control access by length of simplecontext argument.'),
  14. 'callback' => 'ctools_plugin_example_arg_length_ctools_access_check',
  15. 'settings form' => 'ctools_plugin_example_arg_length_ctools_access_settings',
  16. 'summary' => 'ctools_plugin_example_arg_length_ctools_access_summary',
  17. 'required context' => new ctools_context_required(t('Simplecontext'), 'simplecontext'),
  18. );
  19. /**
  20. * Settings form for the 'by role' access plugin.
  21. */
  22. function ctools_plugin_example_arg_length_ctools_access_settings(&$form, &$form_state, $conf) {
  23. $form['settings']['greater_than'] = array(
  24. '#type' => 'radios',
  25. '#title' => t('Grant access if simplecontext argument length is'),
  26. '#options' => array(1 => t('Greater than'), 0 => t('Less than or equal to')),
  27. '#default_value' => $conf['greater_than'],
  28. );
  29. $form['settings']['arg_length'] = array(
  30. '#type' => 'textfield',
  31. '#title' => t('Length of simplecontext argument'),
  32. '#size' => 3,
  33. '#default_value' => $conf['arg_length'],
  34. '#description' => t('Access/visibility will be granted based on arg length.'),
  35. );
  36. }
  37. /**
  38. * Check for access.
  39. */
  40. function ctools_plugin_example_arg_length_ctools_access_check($conf, $context) {
  41. // As far as I know there should always be a context at this point, but this
  42. // is safe.
  43. if (empty($context) || empty($context->data)) {
  44. return FALSE;
  45. }
  46. $compare = ($context->arg_length > $conf['arg_length']);
  47. if (($compare && $conf['greater_than']) || (!$compare && !$conf['greater_than'])) {
  48. return TRUE;
  49. }
  50. return FALSE;
  51. }
  52. /**
  53. * Provide a summary description based upon the checked roles.
  54. */
  55. function ctools_plugin_example_arg_length_ctools_access_summary($conf, $context) {
  56. return t('Simpletext argument must be !comp @length characters',
  57. array('!comp' => $conf['greater_than'] ? 'greater than' : 'less than or equal to',
  58. '@length' => $conf['arg_length']));
  59. }