views_content_plugin_display_panel_pane.inc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. <?php
  2. /**
  3. * The plugin that handles a panel_pane.
  4. */
  5. class views_content_plugin_display_panel_pane extends views_plugin_display {
  6. /**
  7. * If this variable is true, this display counts as a panel pane. We use
  8. * this variable so that other modules can create alternate pane displays.
  9. */
  10. var $panel_pane_display = TRUE;
  11. var $has_pane_conf = NULL;
  12. function option_definition() {
  13. $options = parent::option_definition();
  14. $options['pane_title'] = array('default' => '', 'translatable' => TRUE);
  15. $options['pane_description'] = array('default' => '', 'translatable' => TRUE);
  16. $options['pane_category'] = array(
  17. 'contains' => array(
  18. 'name' => array('default' => 'View panes', 'translatable' => TRUE),
  19. 'weight' => array('default' => 0),
  20. ),
  21. );
  22. $options['allow'] = array(
  23. 'contains' => array(
  24. 'use_pager' => array('default' => FALSE),
  25. 'items_per_page' => array('default' => FALSE),
  26. 'offset' => array('default' => FALSE),
  27. 'link_to_view' => array('default' => FALSE),
  28. 'more_link' => array('default' => FALSE),
  29. 'path_override' => array('default' => FALSE),
  30. 'title_override' => array('default' => FALSE),
  31. 'exposed_form' => array('default' => FALSE),
  32. 'fields_override' => array('default' => FALSE),
  33. ),
  34. );
  35. $options['argument_input'] = array('default' => array());
  36. $options['link_to_view'] = array('default' => 0);
  37. $options['inherit_panels_path'] = array('default' => 0);
  38. return $options;
  39. }
  40. function has_pane_conf() {
  41. return isset($this->has_pane_conf);
  42. }
  43. function set_pane_conf($conf = array()) {
  44. $this->set_option('pane_conf', $conf);
  45. $this->has_pane_conf = TRUE;
  46. }
  47. /**
  48. * Provide the summary for page options in the views UI.
  49. *
  50. * This output is returned as an array.
  51. */
  52. function options_summary(&$categories, &$options) {
  53. // It is very important to call the parent function here:
  54. parent::options_summary($categories, $options);
  55. $categories['panel_pane'] = array(
  56. 'title' => t('Pane settings'),
  57. 'column' => 'second',
  58. 'build' => array(
  59. '#weight' => -10,
  60. ),
  61. );
  62. $pane_title = $this->get_option('pane_title');
  63. if (empty($pane_title)) {
  64. $pane_title = t('Use view name');
  65. }
  66. if (drupal_strlen($pane_title) > 16) {
  67. $pane_title = drupal_substr($pane_title, 0, 16) . '...';
  68. }
  69. $options['pane_title'] = array(
  70. 'category' => 'panel_pane',
  71. 'title' => t('Admin title'),
  72. 'value' => $pane_title,
  73. );
  74. $pane_description = $this->get_option('pane_description');
  75. if (empty($pane_description)) {
  76. $pane_description = t('Use view description');
  77. }
  78. if (drupal_strlen($pane_description) > 16) {
  79. $pane_description = drupal_substr($pane_description, 0, 16) . '...';
  80. }
  81. $options['pane_description'] = array(
  82. 'category' => 'panel_pane',
  83. 'title' => t('Admin desc'),
  84. 'value' => $pane_description,
  85. );
  86. $category = $this->get_option('pane_category');
  87. $pane_category = $category['name'];
  88. if (empty($pane_category)) {
  89. $pane_category = t('View panes');
  90. }
  91. if (drupal_strlen($pane_category) > 16) {
  92. $pane_category = drupal_substr($pane_category, 0, 16) . '...';
  93. }
  94. $options['pane_category'] = array(
  95. 'category' => 'panel_pane',
  96. 'title' => t('Category'),
  97. 'value' => $pane_category,
  98. );
  99. $options['link_to_view'] = array(
  100. 'category' => 'panel_pane',
  101. 'title' => t('Link to view'),
  102. 'value' => $this->get_option('link_to_view') ? t('Yes') : t('No'),
  103. );
  104. $options['inherit_panels_path'] = array(
  105. 'category' => 'panel_pane',
  106. 'title' => t('Use Panel path'),
  107. 'value' => $this->get_option('inherit_panels_path') ? t('Yes') : t('No'),
  108. );
  109. $options['argument_input'] = array(
  110. 'category' => 'panel_pane',
  111. 'title' => t('Argument input'),
  112. 'value' => t('Edit'),
  113. );
  114. $allow = $this->get_option('allow');
  115. $filtered_allow = array_filter($allow);
  116. $options['allow'] = array(
  117. 'category' => 'panel_pane',
  118. 'title' => t('Allow settings'),
  119. 'value' => empty($filtered_allow) ? t('None') : ($allow === $filtered_allow ? t('All') : t('Some')),
  120. );
  121. }
  122. /**
  123. * Provide the default form for setting options.
  124. */
  125. function options_form(&$form, &$form_state) {
  126. // It is very important to call the parent function here:
  127. parent::options_form($form, $form_state);
  128. switch ($form_state['section']) {
  129. case 'allow':
  130. $form['#title'] .= t('Allow settings');
  131. $form['description'] = array(
  132. '#value' => '<div class="form-item description">' . t('Checked settings will be available in the panel pane config dialog for modification by the panels user. Unchecked settings will not be available and will only use the settings in this display.') . '</div>',
  133. );
  134. $options = array(
  135. 'use_pager' => t('Use pager'),
  136. 'items_per_page' => t('Items per page'),
  137. 'offset' => t('Pager offset'),
  138. 'link_to_view' => t('Link to view'),
  139. 'more_link' => t('More link'),
  140. 'path_override' => t('Path override'),
  141. 'title_override' => t('Title override'),
  142. 'exposed_form' => t('Use exposed widgets form as pane configuration'),
  143. 'fields_override' => t('Fields override'),
  144. );
  145. $allow = array_filter($this->get_option('allow'));
  146. $form['allow'] = array(
  147. '#type' => 'checkboxes',
  148. '#default_value' => $allow,
  149. '#options' => $options,
  150. );
  151. break;
  152. case 'pane_title':
  153. $form['#title'] .= t('Administrative title');
  154. $form['pane_title'] = array(
  155. '#type' => 'textfield',
  156. '#default_value' => $this->get_option('pane_title'),
  157. '#description' => t('This is the title that will appear for this view pane in the add content dialog. If left blank, the view name will be used.'),
  158. );
  159. break;
  160. case 'pane_description':
  161. $form['#title'] .= t('Administrative description');
  162. $form['pane_description'] = array(
  163. '#type' => 'textfield',
  164. '#default_value' => $this->get_option('pane_description'),
  165. '#description' => t('This is text that will be displayed when the user mouses over the pane in the add content dialog. If blank the view description will be used.'),
  166. );
  167. break;
  168. case 'pane_category':
  169. $form['#title'] .= t('Administrative description');
  170. $cat = $this->get_option('pane_category');
  171. $form['pane_category']['#tree'] = TRUE;
  172. $form['pane_category']['name'] = array(
  173. '#type' => 'textfield',
  174. '#default_value' => $cat['name'],
  175. '#description' => t('This is category the pane will appear in on the add content dialog.'),
  176. );
  177. $form['pane_category']['weight'] = array(
  178. '#title' => t('Weight'),
  179. '#type' => 'textfield',
  180. '#default_value' => $cat['weight'],
  181. '#description' => t('This is the default weight of the category. Note that if the weight of a category is defined in multiple places, only the first one Panels sees will get that definition, so if the weight does not appear to be working, check other places that the weight might be set.'),
  182. );
  183. break;
  184. case 'link_to_view':
  185. $form['#title'] .= t('Link pane title to view');
  186. $form['link_to_view'] = array(
  187. '#type' => 'select',
  188. '#options' => array(1 => t('Yes'), 0 => t('No')),
  189. '#default_value' => $this->get_option('link_to_view'),
  190. );
  191. break;
  192. case 'inherit_panels_path':
  193. $form['#title'] .= t('Inherit path from panel display');
  194. $form['inherit_panels_path'] = array(
  195. '#type' => 'select',
  196. '#options' => array(1 => t('Yes'), 0 => t('No')),
  197. '#default_value' => $this->get_option('inherit_panels_path'),
  198. '#description' => t('If yes, all links generated by Views, such as more links, summary links, and exposed input links will go to the panels display path, not the view, if the display has a path.'),
  199. );
  200. break;
  201. case 'argument_input':
  202. $form['#title'] .= t('Choose the data source for view arguments');
  203. $argument_input = $this->get_argument_input();
  204. ctools_include('context');
  205. ctools_include('dependent');
  206. $form['argument_input']['#tree'] = TRUE;
  207. $converters = ctools_context_get_all_converters();
  208. ksort($converters);
  209. foreach ($argument_input as $id => $argument) {
  210. $form['argument_input'][$id] = array(
  211. '#tree' => TRUE,
  212. );
  213. $safe = str_replace(array('][', '_', ' '), '-', $id);
  214. $type_id = 'edit-argument-input-' . $safe;
  215. $form['argument_input'][$id]['type'] = array(
  216. '#type' => 'select',
  217. '#options' => array(
  218. 'none' => t('No argument'),
  219. 'wildcard' => t('Argument wildcard'),
  220. 'context' => t('From context'),
  221. 'panel' => t('From panel argument'),
  222. 'fixed' => t('Fixed'),
  223. 'user' => t('Input on pane config'),
  224. ),
  225. '#id' => $type_id,
  226. '#title' => t('@arg source', array('@arg' => $argument['name'])),
  227. '#default_value' => $argument['type'],
  228. );
  229. $form['argument_input'][$id]['context'] = array(
  230. '#type' => 'select',
  231. '#title' => t('Required context'),
  232. '#description' => t('If "From context" is selected, which type of context to use.'),
  233. '#default_value' => $argument['context'],
  234. '#options' => $converters,
  235. '#dependency' => array($type_id => array('context')),
  236. );
  237. $form['argument_input'][$id]['context_optional'] = array(
  238. '#type' => 'checkbox',
  239. '#title' => t('Context is optional'),
  240. '#description' => t('This context need not be present for the pane to function. If you plan to use this, ensure that the argument handler can handle empty values gracefully.'),
  241. '#default_value' => $argument['context_optional'],
  242. '#dependency' => array($type_id => array('context')),
  243. );
  244. $form['argument_input'][$id]['panel'] = array(
  245. '#type' => 'select',
  246. '#title' => t('Panel argument'),
  247. '#description' => t('If "From panel argument" is selected, which panel argument to use.'),
  248. '#default_value' => $argument['panel'],
  249. '#options' => array(0 => t('First'), 1 => t('Second'), 2 => t('Third'), 3 => t('Fourth'), 4 => t('Fifth'), 5 => t('Sixth')),
  250. '#dependency' => array($type_id => array('panel')),
  251. );
  252. $form['argument_input'][$id]['fixed'] = array(
  253. '#type' => 'textfield',
  254. '#title' => t('Fixed argument'),
  255. '#description' => t('If "Fixed" is selected, what to use as an argument.'),
  256. '#default_value' => $argument['fixed'],
  257. '#dependency' => array($type_id => array('fixed')),
  258. );
  259. $form['argument_input'][$id]['label'] = array(
  260. '#type' => 'textfield',
  261. '#title' => t('Label'),
  262. '#description' => t('If this argument is presented to the panels user, what label to apply to it.'),
  263. '#default_value' => empty($argument['label']) ? $argument['name'] : $argument['label'],
  264. '#dependency' => array($type_id => array('user')),
  265. );
  266. }
  267. break;
  268. }
  269. }
  270. /**
  271. * Perform any necessary changes to the form values prior to storage.
  272. * There is no need for this function to actually store the data.
  273. */
  274. function options_submit(&$form, &$form_state) {
  275. // It is very important to call the parent function here:
  276. parent::options_submit($form, $form_state);
  277. switch ($form_state['section']) {
  278. case 'allow':
  279. case 'argument_input':
  280. case 'link_to_view':
  281. case 'inherit_panels_path':
  282. case 'pane_title':
  283. case 'pane_description':
  284. case 'pane_category':
  285. $this->set_option($form_state['section'], $form_state['values'][$form_state['section']]);
  286. break;
  287. }
  288. }
  289. /**
  290. * Adjust the array of argument input to match the current list of
  291. * arguments available for this display. This ensures that changing
  292. * the arguments doesn't cause the argument input field to just
  293. * break.
  294. */
  295. function get_argument_input() {
  296. $arguments = $this->get_option('argument_input');
  297. $handlers = $this->get_handlers('argument');
  298. // We use a separate output so as to seamlessly discard info for
  299. // arguments that no longer exist.
  300. $output = array();
  301. foreach ($handlers as $id => $handler) {
  302. if (empty($arguments[$id])) {
  303. $output[$id] = array(
  304. 'type' => 'none',
  305. 'context' => 'any',
  306. 'context_optional' => FALSE,
  307. 'panel' => 0,
  308. 'fixed' => '',
  309. 'name' => $handler->ui_name(),
  310. );
  311. }
  312. else {
  313. $output[$id] = $arguments[$id];
  314. $output[$id]['name'] = $handler->ui_name();
  315. }
  316. }
  317. return $output;
  318. }
  319. function use_more() {
  320. $allow = $this->get_option('allow');
  321. if (!$allow['more_link'] || !$this->has_pane_conf()) {
  322. return parent::use_more();
  323. }
  324. $conf = $this->get_option('pane_conf');
  325. return (bool) $conf['more_link'];
  326. }
  327. function get_path() {
  328. if (empty($this->view->override_path)) {
  329. return parent::get_path();
  330. }
  331. return $this->view->override_path;
  332. }
  333. function get_url() {
  334. if ($this->get_option('inherit_panels_path')) {
  335. return $this->get_path();
  336. }
  337. return parent::get_url();
  338. }
  339. function uses_exposed_form_in_block() {
  340. // We'll always allow the exposed form in a block, regardless of path.
  341. return TRUE;
  342. }
  343. /**
  344. * Determine if this display should display the exposed
  345. * filters widgets, so the view will know whether or not
  346. * to render them.
  347. *
  348. * Regardless of what this function
  349. * returns, exposed filters will not be used nor
  350. * displayed unless uses_exposed() returns TRUE.
  351. */
  352. function displays_exposed() {
  353. $conf = $this->get_option('allow');
  354. // If this is set, the exposed form is part of pane configuration, not
  355. // rendered normally.
  356. return empty($conf['exposed_form']);
  357. }
  358. }