ctools_custom_content_ui.class.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. class ctools_custom_content_ui extends ctools_export_ui {
  3. function edit_form(&$form, &$form_state) {
  4. // Correct for an error that came in because filter format changed.
  5. if (is_array($form_state['item']->settings['body'])) {
  6. $form_state['item']->settings['format'] = $form_state['item']->settings['body']['format'];
  7. $form_state['item']->settings['body'] = $form_state['item']->settings['body']['value'];
  8. }
  9. parent::edit_form($form, $form_state);
  10. $form['category'] = array(
  11. '#type' => 'textfield',
  12. '#title' => t('Category'),
  13. '#description' => t('What category this content should appear in. If left blank the category will be "Miscellaneous".'),
  14. '#default_value' => $form_state['item']->category,
  15. );
  16. $form['title'] = array(
  17. '#type' => 'textfield',
  18. '#default_value' => $form_state['item']->settings['title'],
  19. '#title' => t('Title'),
  20. );
  21. $form['body'] = array(
  22. '#type' => 'text_format',
  23. '#title' => t('Body'),
  24. '#default_value' => $form_state['item']->settings['body'],
  25. '#format' => $form_state['item']->settings['format'],
  26. );
  27. $form['substitute'] = array(
  28. '#type' => 'checkbox',
  29. '#title' => t('Use context keywords'),
  30. '#description' => t('If checked, context keywords will be substituted in this content.'),
  31. '#default_value' => !empty($form_state['item']->settings['substitute']),
  32. );
  33. }
  34. function edit_form_submit(&$form, &$form_state) {
  35. parent::edit_form_submit($form, $form_state);
  36. // Since items in our settings are not in the schema, we have to do these manually:
  37. $form_state['item']->settings['title'] = $form_state['values']['title'];
  38. $form_state['item']->settings['body'] = $form_state['values']['body']['value'];
  39. $form_state['item']->settings['format'] = $form_state['values']['body']['format'];
  40. $form_state['item']->settings['substitute'] = $form_state['values']['substitute'];
  41. }
  42. function list_form(&$form, &$form_state) {
  43. parent::list_form($form, $form_state);
  44. $options = array('all' => t('- All -'));
  45. foreach ($this->items as $item) {
  46. $options[$item->category] = $item->category;
  47. }
  48. $form['top row']['category'] = array(
  49. '#type' => 'select',
  50. '#title' => t('Category'),
  51. '#options' => $options,
  52. '#default_value' => 'all',
  53. '#weight' => -10,
  54. );
  55. }
  56. function list_filter($form_state, $item) {
  57. if ($form_state['values']['category'] != 'all' && $form_state['values']['category'] != $item->category) {
  58. return TRUE;
  59. }
  60. return parent::list_filter($form_state, $item);
  61. }
  62. function list_sort_options() {
  63. return array(
  64. 'disabled' => t('Enabled, title'),
  65. 'title' => t('Title'),
  66. 'name' => t('Name'),
  67. 'category' => t('Category'),
  68. 'storage' => t('Storage'),
  69. );
  70. }
  71. function list_build_row($item, &$form_state, $operations) {
  72. // Set up sorting
  73. switch ($form_state['values']['order']) {
  74. case 'disabled':
  75. $this->sorts[$item->name] = empty($item->disabled) . $item->admin_title;
  76. break;
  77. case 'title':
  78. $this->sorts[$item->name] = $item->admin_title;
  79. break;
  80. case 'name':
  81. $this->sorts[$item->name] = $item->name;
  82. break;
  83. case 'category':
  84. $this->sorts[$item->name] = $item->category;
  85. break;
  86. case 'storage':
  87. $this->sorts[$item->name] = $item->type . $item->admin_title;
  88. break;
  89. }
  90. $ops = theme('links__ctools_dropbutton', array('links' => $operations, 'attributes' => array('class' => array('links', 'inline'))));
  91. $this->rows[$item->name] = array(
  92. 'data' => array(
  93. array('data' => check_plain($item->name), 'class' => array('ctools-export-ui-name')),
  94. array('data' => check_plain($item->admin_title), 'class' => array('ctools-export-ui-title')),
  95. array('data' => check_plain($item->category), 'class' => array('ctools-export-ui-category')),
  96. array('data' => $ops, 'class' => array('ctools-export-ui-operations')),
  97. ),
  98. 'title' => check_plain($item->admin_description),
  99. 'class' => array(!empty($item->disabled) ? 'ctools-export-ui-disabled' : 'ctools-export-ui-enabled'),
  100. );
  101. }
  102. function list_table_header() {
  103. return array(
  104. array('data' => t('Name'), 'class' => array('ctools-export-ui-name')),
  105. array('data' => t('Title'), 'class' => array('ctools-export-ui-title')),
  106. array('data' => t('Category'), 'class' => array('ctools-export-ui-category')),
  107. array('data' => t('Operations'), 'class' => array('ctools-export-ui-operations')),
  108. );
  109. }
  110. }