workflow_bundle.inc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * @file
  4. * Describes a CTools Access plugin.
  5. *
  6. * Used to select whether or not a panel (variant) is displayed based
  7. * upon the current workflow and/or workflow state of the current node.
  8. * @see https://drupal.org/node/2187731
  9. */
  10. /**
  11. * Defines the Plugin.
  12. *
  13. * Plugins are described by creating a $plugin array which will
  14. * be used by the system that includes the file.
  15. */
  16. $plugin = array(
  17. 'title' => t('Workflow: bundle'),
  18. 'description' => t('Controls access by workflow bundle'),
  19. 'callback' => 'workflow_bundle_ctools_access_check',
  20. 'default' => array('workflow_bundle' => 0),
  21. 'settings form' => 'workflow_bundle_ctools_settings',
  22. 'summary' => 'workflow_bundle_ctools_summary',
  23. 'required context' => new ctools_context_required(t('Node'), 'node'),
  24. );
  25. /**
  26. * Custom callback defined by 'callback' in the $plugin array.
  27. *
  28. * Check for access.
  29. */
  30. function workflow_bundle_ctools_access_check($conf, $context) {
  31. // For some unknown reason $context may not be set. We just want to be sure.
  32. if (empty($context) || empty($context->data) || empty($context->data->type)) {
  33. return FALSE;
  34. }
  35. // If the node's content type is not part of the selected workflow access to
  36. // the pane is denied.
  37. $type = $context->data->type;
  38. $workflow = workflow_get_workflow_type_map_by_type($type);
  39. if (isset($workflow->wid) && $conf['workflow_bundle'] == $workflow->wid) {
  40. return TRUE;
  41. }
  42. return FALSE;
  43. }
  44. /**
  45. * Settings form for the 'workflow bundle' access plugin.
  46. */
  47. function workflow_bundle_ctools_settings($form, &$form_state, $conf) {
  48. $options = array();
  49. $workflows = workflow_get_workflows();
  50. foreach ($workflows as $value) {
  51. $options[$value->wid] = $value->name;
  52. }
  53. $form['settings']['workflow_bundle'] = array(
  54. '#title' => t('Select workflow'),
  55. '#type' => 'select',
  56. '#options' => $options,
  57. '#description' => t('The pane will only be visible for nodes of content types that belong to this workflow'),
  58. '#default_value' => $conf['workflow_bundle'],
  59. );
  60. return $form;
  61. }
  62. /**
  63. * Provide a summary description based upon the workflow bundle.
  64. */
  65. function workflow_bundle_ctools_summary($conf, $context) {
  66. $workflow = workflow_get_workflows_by_wid($conf['workflow_bundle']);
  67. return t('Nodes that have workflow "@workflow"', array('@workflow' => $workflow->name));
  68. }