ctools_custom_content.module 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * @file
  4. * The ctools_custom_content module.
  5. *
  6. * This module allows styles to be created and managed on behalf of modules
  7. * that implement styles.
  8. *
  9. * The ctools_custom_content tool allows recolorable styles to be created via a miniature
  10. * scripting language. Panels utilizes this to allow administrators to add
  11. * styles directly to any panel display.
  12. */
  13. /**
  14. * Implementation of hook_permission()
  15. */
  16. function ctools_custom_content_permission() {
  17. return array(
  18. 'administer custom content' => array(
  19. 'title' => t('Administer custom content'),
  20. 'description' => t('Add, edit and delete CTools custom stored custom content'),
  21. ),
  22. );
  23. }
  24. /**
  25. * Implementation of hook_ctools_plugin_directory() to let the system know
  26. * we implement task and task_handler plugins.
  27. */
  28. function ctools_custom_content_ctools_plugin_directory($module, $plugin) {
  29. // Most of this module is implemented as an export ui plugin, and the
  30. // rest is in ctools/includes/ctools_custom_content.inc.
  31. if ($module == 'ctools' && $plugin == 'export_ui') {
  32. return 'plugins/' . $plugin;
  33. }
  34. }
  35. /**
  36. * Implements hook_get_pane_links_alter().
  37. */
  38. function ctools_custom_content_get_pane_links_alter(&$links, $pane, $content_type) {
  39. if ($pane->type == 'custom') {
  40. if (!isset($pane->configuration['name'])) {
  41. $name_of_pane = $pane->subtype;
  42. }
  43. else {
  44. $name_of_pane = $pane->configuration['name'];
  45. }
  46. $links['top']['edit_custom_content'] = array(
  47. 'title' => t('Edit custom content pane'),
  48. 'href' => url('admin/structure/ctools-content/list/' . $name_of_pane . '/edit', array('absolute' => TRUE)),
  49. 'attributes' => array('target' => array('_blank')),
  50. );
  51. }
  52. }
  53. /**
  54. * Create callback for creating a new CTools custom content type.
  55. *
  56. * This ensures we get proper defaults from the plugin for its settings.
  57. */
  58. function ctools_content_type_new($set_defaults) {
  59. $item = ctools_export_new_object('ctools_custom_content', $set_defaults);
  60. ctools_include('content');
  61. $plugin = ctools_get_content_type('custom');
  62. $item->settings = ctools_content_get_defaults($plugin, array());
  63. return $item;
  64. }
  65. /**
  66. * Implementation of hook_panels_dashboard_blocks().
  67. *
  68. * Adds page information to the Panels dashboard.
  69. */
  70. function ctools_custom_content_panels_dashboard_blocks(&$vars) {
  71. $vars['links']['ctools_custom_content'] = array(
  72. 'title' => l(t('Custom content'), 'admin/structure/ctools-content/add'),
  73. 'description' => t('Custom content panes are basic HTML you enter that can be reused in all of your panels.'),
  74. );
  75. // Load all mini panels and their displays.
  76. ctools_include('export');
  77. $items = ctools_export_crud_load_all('ctools_custom_content');
  78. $count = 0;
  79. $rows = array();
  80. foreach ($items as $item) {
  81. $rows[] = array(
  82. check_plain($item->admin_title),
  83. array(
  84. 'data' => l(t('Edit'), "admin/structure/ctools-content/list/$item->name/edit"),
  85. 'class' => 'links',
  86. ),
  87. );
  88. // Only show 10.
  89. if (++$count >= 10) {
  90. break;
  91. }
  92. }
  93. if ($rows) {
  94. $content = theme('table', array('rows' => $rows, 'attributes' => array('class' => 'panels-manage')));
  95. }
  96. else {
  97. $content = '<p>' . t('There are no custom content panes.') . '</p>';
  98. }
  99. $vars['blocks']['ctools_custom_content'] = array(
  100. 'title' => t('Manage custom content'),
  101. 'link' => l(t('Go to list'), 'admin/structure/ctools-content'),
  102. 'content' => $content,
  103. 'class' => 'dashboard-content',
  104. 'section' => 'right',
  105. );
  106. }