ctools_custom_content_ui.class.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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['title_heading'] = array(
  22. '#title' => t('Title heading'),
  23. '#type' => 'select',
  24. '#default_value' => isset($form_state['item']->settings['title_heading']) ? $form_state['item']->settings['title_heading'] : 'h2',
  25. '#options' => array(
  26. 'h1' => t('h1'),
  27. 'h2' => t('h2'),
  28. 'h3' => t('h3'),
  29. 'h4' => t('h4'),
  30. 'h5' => t('h5'),
  31. 'h6' => t('h6'),
  32. 'div' => t('div'),
  33. 'span' => t('span'),
  34. ),
  35. );
  36. $form['body'] = array(
  37. '#type' => 'text_format',
  38. '#title' => t('Body'),
  39. '#default_value' => $form_state['item']->settings['body'],
  40. '#format' => $form_state['item']->settings['format'],
  41. );
  42. $form['substitute'] = array(
  43. '#type' => 'checkbox',
  44. '#title' => t('Use context keywords'),
  45. '#description' => t('If checked, context keywords will be substituted in this content.'),
  46. '#default_value' => !empty($form_state['item']->settings['substitute']),
  47. );
  48. }
  49. function edit_form_submit(&$form, &$form_state) {
  50. parent::edit_form_submit($form, $form_state);
  51. // Since items in our settings are not in the schema, we have to do these manually:
  52. $form_state['item']->settings['title'] = $form_state['values']['title'];
  53. $form_state['item']->settings['title_heading'] = $form_state['values']['title_heading'];
  54. $form_state['item']->settings['body'] = $form_state['values']['body']['value'];
  55. $form_state['item']->settings['format'] = $form_state['values']['body']['format'];
  56. $form_state['item']->settings['substitute'] = $form_state['values']['substitute'];
  57. }
  58. function list_form(&$form, &$form_state) {
  59. parent::list_form($form, $form_state);
  60. $options = array('all' => t('- All -'));
  61. foreach ($this->items as $item) {
  62. $options[$item->category] = $item->category;
  63. }
  64. $form['top row']['category'] = array(
  65. '#type' => 'select',
  66. '#title' => t('Category'),
  67. '#options' => $options,
  68. '#default_value' => 'all',
  69. '#weight' => -10,
  70. );
  71. }
  72. function list_filter($form_state, $item) {
  73. if ($form_state['values']['category'] != 'all' && $form_state['values']['category'] != $item->category) {
  74. return TRUE;
  75. }
  76. return parent::list_filter($form_state, $item);
  77. }
  78. function list_sort_options() {
  79. return array(
  80. 'disabled' => t('Enabled, title'),
  81. 'title' => t('Title'),
  82. 'name' => t('Name'),
  83. 'category' => t('Category'),
  84. 'storage' => t('Storage'),
  85. );
  86. }
  87. function list_build_row($item, &$form_state, $operations) {
  88. // Set up sorting
  89. switch ($form_state['values']['order']) {
  90. case 'disabled':
  91. $this->sorts[$item->name] = empty($item->disabled) . $item->admin_title;
  92. break;
  93. case 'title':
  94. $this->sorts[$item->name] = $item->admin_title;
  95. break;
  96. case 'name':
  97. $this->sorts[$item->name] = $item->name;
  98. break;
  99. case 'category':
  100. $this->sorts[$item->name] = $item->category;
  101. break;
  102. case 'storage':
  103. $this->sorts[$item->name] = $item->type . $item->admin_title;
  104. break;
  105. }
  106. $ops = theme('links__ctools_dropbutton', array('links' => $operations, 'attributes' => array('class' => array('links', 'inline'))));
  107. $this->rows[$item->name] = array(
  108. 'data' => array(
  109. array('data' => check_plain($item->name), 'class' => array('ctools-export-ui-name')),
  110. array('data' => check_plain($item->admin_title), 'class' => array('ctools-export-ui-title')),
  111. array('data' => check_plain($item->category), 'class' => array('ctools-export-ui-category')),
  112. array('data' => $ops, 'class' => array('ctools-export-ui-operations')),
  113. ),
  114. 'title' => check_plain($item->admin_description),
  115. 'class' => array(!empty($item->disabled) ? 'ctools-export-ui-disabled' : 'ctools-export-ui-enabled'),
  116. );
  117. }
  118. function list_table_header() {
  119. return array(
  120. array('data' => t('Name'), 'class' => array('ctools-export-ui-name')),
  121. array('data' => t('Title'), 'class' => array('ctools-export-ui-title')),
  122. array('data' => t('Category'), 'class' => array('ctools-export-ui-category')),
  123. array('data' => t('Operations'), 'class' => array('ctools-export-ui-operations')),
  124. );
  125. }
  126. }