views_plugin_display.inc

  1. cis7 sites/all/modules/ulmus/views/plugins/views_plugin_display.inc
  2. cle7 sites/all/modules/ulmus/views/plugins/views_plugin_display.inc
  3. ecd7 sites/all/modules/ulmus/views/plugins/views_plugin_display.inc
  4. elmsmedia7 sites/all/modules/ulmus/views/plugins/views_plugin_display.inc
  5. harmony7 sites/all/modules/ulmus/views/plugins/views_plugin_display.inc
  6. icor7 sites/all/modules/ulmus/views/plugins/views_plugin_display.inc
  7. meedjum_blog7 sites/all/modules/ulmus/views/plugins/views_plugin_display.inc
  8. mooc7 sites/all/modules/ulmus/views/plugins/views_plugin_display.inc

Contains the base display plugin.

Classes

Namesort descending Description
views_plugin_display The default display plugin handler. Display plugins handle options and basic mechanisms for different output methods.

File

sites/all/modules/ulmus/views/plugins/views_plugin_display.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Contains the base display plugin.
  5. */
  6. /**
  7. * @defgroup views_display_plugins Views display plugins
  8. * @{
  9. * Display plugins control how Views interact with the rest of Drupal.
  10. *
  11. * They can handle creating Views from a Drupal page hook; they can
  12. * handle creating Views from a Drupal block hook. They can also
  13. * handle creating Views from an external module source, such as
  14. * a Panels pane, or an insert view, or a CCK field type.
  15. *
  16. * @see hook_views_plugins()
  17. */
  18. /**
  19. * The default display plugin handler. Display plugins handle options and
  20. * basic mechanisms for different output methods.
  21. */
  22. class views_plugin_display extends views_plugin {
  23. /**
  24. * The top object of a view.
  25. *
  26. * @var view
  27. */
  28. var $view = NULL;
  29. var $handlers = array();
  30. /**
  31. * Stores all available display extenders.
  32. */
  33. var $extender = array();
  34. function init(&$view, &$display, $options = NULL) {
  35. $this->view = &$view;
  36. $this->display = &$display;
  37. // Load extenders as soon as possible.
  38. $this->extender = array();
  39. $extenders = views_get_enabled_display_extenders();
  40. // If you update to the dev version the registry might not be loaded yet.
  41. if (!empty($extenders) && class_exists('views_plugin_display_extender')) {
  42. foreach ($extenders as $extender) {
  43. $plugin = views_get_plugin('display_extender', $extender);
  44. if ($plugin) {
  45. $plugin->init($this->view, $this);
  46. $this->extender[$extender] = $plugin;
  47. }
  48. else {
  49. vpr('Invalid display extender @extender', array('@handler' => $extender));
  50. }
  51. }
  52. }
  53. // Track changes that the user should know about.
  54. $changed = FALSE;
  55. // Make some modifications:
  56. if (!isset($options) && isset($display->display_options)) {
  57. $options = $display->display_options;
  58. }
  59. if ($this->is_default_display() && isset($options['defaults'])) {
  60. unset($options['defaults']);
  61. }
  62. // Cache for unpack_options, but not if we are in the ui.
  63. static $unpack_options = array();
  64. if (empty($view->editing)) {
  65. $cid = 'unpack_options:' . md5(serialize(array($this->options, $options)));
  66. if (empty($unpack_options[$cid])) {
  67. $cache = views_cache_get($cid, TRUE);
  68. if (!empty($cache->data)) {
  69. $this->options = $cache->data;
  70. }
  71. else {
  72. $this->unpack_options($this->options, $options);
  73. views_cache_set($cid, $this->options, TRUE);
  74. }
  75. $unpack_options[$cid] = $this->options;
  76. }
  77. else {
  78. $this->options = $unpack_options[$cid];
  79. }
  80. }
  81. else {
  82. $this->unpack_options($this->options, $options);
  83. }
  84. // Translate changed settings:
  85. $items_per_page = $this->get_option('items_per_page');
  86. $offset = $this->get_option('offset');
  87. $use_pager = $this->get_option('use_pager');
  88. $pager = $this->get_option('pager');
  89. // Check if the pager options were already converted.
  90. // The pager settings of a Views 2.x view specifying 10 items with an
  91. // offset of 0 and no pager is the same as of a Views 3.x view with
  92. // default settings. In this case, the only way to determine which case we
  93. // are dealing with is checking the API version but that's only available
  94. // for exported Views as it's not stored in the database.
  95. // If you would like to change this code, really take care that you thought
  96. // of every possibility.
  97. // @TODO: Provide a way to convert the database views as well.
  98. if (((!empty($items_per_page) && $items_per_page != 10) || !empty($offset) || !empty($use_pager))
  99. || (!empty($view->api_version) && $view->api_version == 2)) {
  100. // Find out the right pager type.
  101. // If the view "use pager" it's a normal/full pager.
  102. if ($use_pager) {
  103. $type = 'full';
  104. }
  105. // If it does not use pager, but 0 items per page it should not page
  106. // else it should display just a certain amount of items.
  107. else {
  108. $type = $items_per_page ? 'some' : 'none';
  109. }
  110. // Setup the pager options.
  111. $pager = array(
  112. 'type' => $type,
  113. 'options' => array(
  114. 'offset' => intval($offset)
  115. ),
  116. );
  117. if ($items_per_page) {
  118. $pager['options']['items_per_page'] = $items_per_page;
  119. }
  120. // Setup the pager element.
  121. if ($id = $this->get_option('pager_element')) {
  122. $pager['options']['id'] = $id;
  123. }
  124. // Unset the previous options
  125. // After edit and save the view they will be erased
  126. $this->set_option('items_per_page', NULL);
  127. $this->set_option('offset', NULL);
  128. $this->set_option('use_pager', NULL);
  129. $this->set_option('pager', $pager);
  130. $changed = TRUE;
  131. }
  132. // Plugable headers, footer and empty texts are
  133. // not compatible with previous version of views
  134. // This code converts old values into a configured handler for each area
  135. foreach (array('header', 'footer', 'empty') as $area) {
  136. $converted = FALSE;
  137. if (isset($this->options[$area]) && !is_array($this->options[$area])) {
  138. if (!empty($this->options[$area])) {
  139. $content = $this->get_option($area);
  140. if (!empty($content) && !is_array($content)) {
  141. $format = $this->get_option($area . '_format');
  142. $options = array(
  143. 'id' => 'area',
  144. 'table' => 'views',
  145. 'field' => 'area',
  146. 'label' => '',
  147. 'relationship' => 'none',
  148. 'group_type' => 'group',
  149. 'content' => $content,
  150. 'format' => !empty($format) ? $format : filter_default_format(),
  151. );
  152. if ($area != 'empty' && $empty = $this->get_option($area . '_empty')) {
  153. $options['empty'] = $empty;
  154. }
  155. $this->set_option($area, array('text' => $options));
  156. $converted = TRUE;
  157. $changed = TRUE;
  158. }
  159. }
  160. // Ensure that options are at least an empty array
  161. if (!$converted) {
  162. $this->set_option($area, array());
  163. }
  164. }
  165. }
  166. // Convert distinct setting from display to query settings.
  167. $distinct = $this->get_option('distinct');
  168. if (!empty($distinct)) {
  169. $query_settings = $this->get_option('query');
  170. $query_settings['options']['distinct'] = $distinct;
  171. $this->set_option('query', $query_settings);
  172. // Clear the values
  173. $this->set_option('distinct', NULL);
  174. $changed = TRUE;
  175. }
  176. // Convert field language settings.
  177. $query_options = $this->get_option('query');
  178. if (isset($query_options['options']['field_language'])) {
  179. $this->set_option('field_language', $query_options['options']['field_language']);
  180. unset($query_options['options']['field_language']);
  181. $changed = TRUE;
  182. }
  183. if (isset($query_options['options']['field_language_add_to_query'])) {
  184. $this->set_option('field_language_add_to_query', $query_options['options']['field_language_add_to_query']);
  185. unset($query_options['options']['field_language_add_to_query']);
  186. $changed = TRUE;
  187. }
  188. $this->set_option('query', $query_options);
  189. // Convert filter groups.
  190. $filter_groups = $this->get_option('filter_groups');
  191. // Only convert if it wasn't converted yet, which is the case if there is a 0 group.
  192. if (isset($filter_groups['groups'][0])) {
  193. // Update filter groups.
  194. $filter_groups ['groups'] = views_array_key_plus($filter_groups['groups']);
  195. $this->set_option('filter_groups', $filter_groups);
  196. // Update the filter group on each filter.
  197. $filters = $this->get_option('filters');
  198. foreach ($filters as &$filter) {
  199. if (isset($filter['group'])) {
  200. $filter['group']++;
  201. }
  202. else {
  203. $filter['group'] = 1;
  204. }
  205. }
  206. $this->set_option('filters', $filters);
  207. $changed = TRUE;
  208. }
  209. // Filter groups were allowed to be rewritten without its filters, so
  210. // before this update the view was using the default values. To be sure that
  211. // the existing view isn't broken, don't use this overridden values but copy
  212. // them from the default display. Only do this if the filters are overridden
  213. // but the filter_groups are not marked as so.
  214. if (!$this->is_default_display() && !$this->options['defaults']['filters'] && $this->options['defaults']['filter_groups']) {
  215. // Set filter_groups to be overridden and save the value in the
  216. // display_options as well.
  217. $this->options['defaults']['filter_groups'] = FALSE;
  218. $this->display->display_options['defaults']['filter_groups'] = $this->options['defaults']['filter_groups'];
  219. // Copy the filter_groups from the default, and add them to the
  220. // display_options as well. $this->default_display is not initialized at
  221. // this point.
  222. $this->options['filter_groups'] = $this->view->display['default']->handler->options['filter_groups'];
  223. $this->display->display_options['filter_groups'] = $this->options['filter_groups'];
  224. $changed = TRUE;
  225. }
  226. // Mark the view as changed so the user has a chance to save it.
  227. if ($changed) {
  228. $this->view->changed = TRUE;
  229. }
  230. }
  231. function destroy() {
  232. parent::destroy();
  233. foreach ($this->handlers as $type => $handlers) {
  234. foreach ($handlers as $id => $handler) {
  235. if (is_object($handler)) {
  236. $this->handlers[$type][$id]->destroy();
  237. }
  238. }
  239. }
  240. if (isset($this->default_display)) {
  241. unset($this->default_display);
  242. }
  243. foreach ($this->extender as $extender) {
  244. $extender->destroy();
  245. }
  246. }
  247. /**
  248. * Determine if this display is the 'default' display which contains
  249. * fallback settings
  250. */
  251. function is_default_display() { return FALSE; }
  252. /**
  253. * Determine if this display uses exposed filters, so the view
  254. * will know whether or not to build them.
  255. */
  256. function uses_exposed() {
  257. if (!isset($this->has_exposed)) {
  258. foreach ($this->handlers as $type => $value) {
  259. foreach ($this->view->$type as $id => $handler) {
  260. if ($handler->can_expose() && $handler->is_exposed()) {
  261. // one is all we need; if we find it, return true.
  262. $this->has_exposed = TRUE;
  263. return TRUE;
  264. }
  265. }
  266. }
  267. $pager = $this->get_plugin('pager');
  268. if (isset($pager) && $pager->uses_exposed()) {
  269. $this->has_exposed = TRUE;
  270. return TRUE;
  271. }
  272. $this->has_exposed = FALSE;
  273. }
  274. return $this->has_exposed;
  275. }
  276. /**
  277. * Determine if this display should display the exposed
  278. * filters widgets, so the view will know whether or not
  279. * to render them.
  280. *
  281. * Regardless of what this function
  282. * returns, exposed filters will not be used nor
  283. * displayed unless uses_exposed() returns TRUE.
  284. */
  285. function displays_exposed() {
  286. return TRUE;
  287. }
  288. /**
  289. * Does the display use AJAX?
  290. */
  291. function use_ajax() {
  292. if (!empty($this->definition['use ajax'])) {
  293. return $this->get_option('use_ajax');
  294. }
  295. return FALSE;
  296. }
  297. /**
  298. * Does the display have a pager enabled?
  299. */
  300. function use_pager() {
  301. $pager = $this->get_plugin('pager');
  302. if ($pager) {
  303. return $pager->use_pager();
  304. }
  305. }
  306. /**
  307. * Does the display have a more link enabled?
  308. */
  309. function use_more() {
  310. if (!empty($this->definition['use more'])) {
  311. return $this->get_option('use_more');
  312. }
  313. return FALSE;
  314. }
  315. /**
  316. * Does the display have groupby enabled?
  317. */
  318. function use_group_by() {
  319. return $this->get_option('group_by');
  320. }
  321. /**
  322. * Should the enabled display more link be shown when no more items?
  323. */
  324. function use_more_always() {
  325. if (!empty($this->definition['use more'])) {
  326. return $this->get_option('use_more_always');
  327. }
  328. return FALSE;
  329. }
  330. /**
  331. * Does the display have custom link text?
  332. */
  333. function use_more_text() {
  334. if (!empty($this->definition['use more'])) {
  335. return $this->get_option('use_more_text');
  336. }
  337. return FALSE;
  338. }
  339. /**
  340. * Can this display accept attachments?
  341. */
  342. function accept_attachments() {
  343. if (empty($this->definition['accept attachments'])) {
  344. return FALSE;
  345. }
  346. if (!empty($this->view->argument) && $this->get_option('hide_attachment_summary')) {
  347. foreach ($this->view->argument as $argument_id => $argument) {
  348. if ($argument->needs_style_plugin() && empty($argument->argument_validated)) {
  349. return FALSE;
  350. }
  351. }
  352. }
  353. return TRUE;
  354. }
  355. /**
  356. * Allow displays to attach to other views.
  357. */
  358. function attach_to($display_id) { }
  359. /**
  360. * Static member function to list which sections are defaultable
  361. * and what items each section contains.
  362. */
  363. function defaultable_sections($section = NULL) {
  364. $sections = array(
  365. 'access' => array('access', 'access_options'),
  366. 'access_options' => array('access', 'access_options'),
  367. 'cache' => array('cache', 'cache_options'),
  368. 'cache_options' => array('cache', 'cache_options'),
  369. 'title' => array('title'),
  370. 'css_class' => array('css_class'),
  371. 'use_ajax' => array('use_ajax'),
  372. 'hide_attachment_summary' => array('hide_attachment_summary'),
  373. 'hide_admin_links' => array('hide_admin_links'),
  374. 'group_by' => array('group_by'),
  375. 'query' => array('query'),
  376. 'use_more' => array('use_more', 'use_more_always', 'use_more_text'),
  377. 'use_more_always' => array('use_more', 'use_more_always', 'use_more_text'),
  378. 'use_more_text' => array('use_more', 'use_more_always', 'use_more_text'),
  379. 'link_display' => array('link_display', 'link_url'),
  380. // Force these to cascade properly.
  381. 'style_plugin' => array('style_plugin', 'style_options', 'row_plugin', 'row_options'),
  382. 'style_options' => array('style_plugin', 'style_options', 'row_plugin', 'row_options'),
  383. 'row_plugin' => array('style_plugin', 'style_options', 'row_plugin', 'row_options'),
  384. 'row_options' => array('style_plugin', 'style_options', 'row_plugin', 'row_options'),
  385. 'pager' => array('pager', 'pager_options'),
  386. 'pager_options' => array('pager', 'pager_options'),
  387. 'exposed_form' => array('exposed_form', 'exposed_form_options'),
  388. 'exposed_form_options' => array('exposed_form', 'exposed_form_options'),
  389. // These guys are special
  390. 'header' => array('header'),
  391. 'footer' => array('footer'),
  392. 'empty' => array('empty'),
  393. 'relationships' => array('relationships'),
  394. 'fields' => array('fields'),
  395. 'sorts' => array('sorts'),
  396. 'arguments' => array('arguments'),
  397. 'filters' => array('filters', 'filter_groups'),
  398. 'filter_groups' => array('filters', 'filter_groups'),
  399. );
  400. // If the display cannot use a pager, then we cannot default it.
  401. if (empty($this->definition['use pager'])) {
  402. unset($sections['pager']);
  403. unset($sections['items_per_page']);
  404. }
  405. foreach ($this->extender as $extender) {
  406. $extender->defaultable_sections($sections, $section);
  407. }
  408. if ($section) {
  409. if (!empty($sections[$section])) {
  410. return $sections[$section];
  411. }
  412. }
  413. else {
  414. return $sections;
  415. }
  416. }
  417. function option_definition() {
  418. $options = array(
  419. 'defaults' => array(
  420. 'default' => array(
  421. 'access' => TRUE,
  422. 'cache' => TRUE,
  423. 'query' => TRUE,
  424. 'title' => TRUE,
  425. 'css_class' => TRUE,
  426. 'display_description' => FALSE,
  427. 'use_ajax' => TRUE,
  428. 'hide_attachment_summary' => TRUE,
  429. 'hide_admin_links' => TRUE,
  430. 'pager' => TRUE,
  431. 'pager_options' => TRUE,
  432. 'use_more' => TRUE,
  433. 'use_more_always' => TRUE,
  434. 'use_more_text' => TRUE,
  435. 'exposed_form' => TRUE,
  436. 'exposed_form_options' => TRUE,
  437. 'link_display' => TRUE,
  438. 'link_url' => '',
  439. 'group_by' => TRUE,
  440. 'style_plugin' => TRUE,
  441. 'style_options' => TRUE,
  442. 'row_plugin' => TRUE,
  443. 'row_options' => TRUE,
  444. 'header' => TRUE,
  445. 'footer' => TRUE,
  446. 'empty' => TRUE,
  447. 'relationships' => TRUE,
  448. 'fields' => TRUE,
  449. 'sorts' => TRUE,
  450. 'arguments' => TRUE,
  451. 'filters' => TRUE,
  452. 'filter_groups' => TRUE,
  453. ),
  454. 'export' => FALSE,
  455. ),
  456. 'title' => array(
  457. 'default' => '',
  458. 'translatable' => TRUE,
  459. ),
  460. 'enabled' => array(
  461. 'default' => TRUE,
  462. 'translatable' => FALSE,
  463. 'bool' => TRUE,
  464. ),
  465. 'display_comment' => array(
  466. 'default' => '',
  467. ),
  468. 'css_class' => array(
  469. 'default' => '',
  470. 'translatable' => FALSE,
  471. ),
  472. 'display_description' => array(
  473. 'default' => '',
  474. 'translatable' => TRUE,
  475. ),
  476. 'use_ajax' => array(
  477. 'default' => FALSE,
  478. 'bool' => TRUE,
  479. ),
  480. 'hide_attachment_summary' => array(
  481. 'default' => FALSE,
  482. 'bool' => TRUE,
  483. ),
  484. 'hide_admin_links' => array(
  485. 'default' => FALSE,
  486. 'bool' => TRUE,
  487. ),
  488. // This is legacy code:
  489. // Items_per/offset/use_pager is moved to the pager plugin
  490. // but the automatic update path needs this items defined, so don't remove it.
  491. // @see views_plugin_display::init()
  492. 'items_per_page' => array(
  493. 'default' => 10,
  494. ),
  495. 'offset' => array(
  496. 'default' => 0,
  497. ),
  498. 'use_pager' => array(
  499. 'default' => FALSE,
  500. 'bool' => TRUE,
  501. ),
  502. 'use_more' => array(
  503. 'default' => FALSE,
  504. 'bool' => TRUE,
  505. ),
  506. 'use_more_always' => array(
  507. 'default' => FALSE,
  508. 'bool' => TRUE,
  509. 'export' => 'export_option_always',
  510. ),
  511. 'use_more_text' => array(
  512. 'default' => 'more',
  513. 'translatable' => TRUE,
  514. ),
  515. 'link_display' => array(
  516. 'default' => '',
  517. ),
  518. 'link_url' => array(
  519. 'default' => '',
  520. ),
  521. 'group_by' => array(
  522. 'default' => FALSE,
  523. 'bool' => TRUE,
  524. ),
  525. 'field_language' => array(
  526. 'default' => '***CURRENT_LANGUAGE***',
  527. ),
  528. 'field_language_add_to_query' => array(
  529. 'default' => 1,
  530. ),
  531. // These types are all plugins that can have individual settings
  532. // and therefore need special handling.
  533. 'access' => array(
  534. 'contains' => array(
  535. 'type' => array('default' => 'none', 'export' => 'export_plugin', 'unpack_translatable' => 'unpack_plugin'),
  536. ),
  537. ),
  538. 'cache' => array(
  539. 'contains' => array(
  540. 'type' => array('default' => 'none', 'export' => 'export_plugin', 'unpack_translatable' => 'unpack_plugin'),
  541. ),
  542. ),
  543. 'query' => array(
  544. 'contains' => array(
  545. 'type' => array('default' => 'views_query', 'export' => 'export_plugin'),
  546. 'options' => array('default' => array(), 'export' => FALSE),
  547. ),
  548. ),
  549. // Note that exposed_form plugin has options in a separate array,
  550. // while access and cache do not. access and cache are legacy and
  551. // that pattern should not be repeated, but it is left as is to
  552. // reduce the need to modify older views. Let's consider the
  553. // pattern used here to be the template from which future plugins
  554. // should be copied.
  555. 'exposed_form' => array(
  556. 'contains' => array(
  557. 'type' => array('default' => 'basic', 'export' => 'export_plugin', 'unpack_translatable' => 'unpack_plugin'),
  558. 'options' => array('default' => array(), 'export' => FALSE),
  559. ),
  560. ),
  561. 'pager' => array(
  562. 'contains' => array(
  563. 'type' => array('default' => 'full', 'export' => 'export_plugin', 'unpack_translatable' => 'unpack_plugin'),
  564. 'options' => array('default' => array(), 'export' => FALSE),
  565. ),
  566. ),
  567. // Note that the styles have their options completely independent.
  568. // Like access and cache above, this is a legacy pattern and
  569. // should not be repeated.
  570. 'style_plugin' => array(
  571. 'default' => 'default',
  572. 'export' => 'export_style',
  573. 'unpack_translatable' => 'unpack_style',
  574. ),
  575. 'style_options' => array(
  576. 'default' => array(),
  577. 'export' => FALSE,
  578. ),
  579. 'row_plugin' => array(
  580. 'default' => 'fields',
  581. 'export' => 'export_style',
  582. 'unpack_translatable' => 'unpack_style',
  583. ),
  584. 'row_options' => array(
  585. 'default' => array(),
  586. 'export' => FALSE,
  587. ),
  588. 'exposed_block' => array(
  589. 'default' => FALSE,
  590. ),
  591. 'header' => array(
  592. 'default' => array(),
  593. 'export' => 'export_handler',
  594. 'unpack_translatable' => 'unpack_handler',
  595. ),
  596. 'footer' => array(
  597. 'default' => array(),
  598. 'export' => 'export_handler',
  599. 'unpack_translatable' => 'unpack_handler',
  600. ),
  601. 'empty' => array(
  602. 'default' => array(),
  603. 'export' => 'export_handler',
  604. 'unpack_translatable' => 'unpack_handler',
  605. ),
  606. // We want these to export last.
  607. // These are the 5 handler types.
  608. 'relationships' => array(
  609. 'default' => array(),
  610. 'export' => 'export_handler',
  611. 'unpack_translatable' => 'unpack_handler',
  612. ),
  613. 'fields' => array(
  614. 'default' => array(),
  615. 'export' => 'export_handler',
  616. 'unpack_translatable' => 'unpack_handler',
  617. ),
  618. 'sorts' => array(
  619. 'default' => array(),
  620. 'export' => 'export_handler',
  621. 'unpack_translatable' => 'unpack_handler',
  622. ),
  623. 'arguments' => array(
  624. 'default' => array(),
  625. 'export' => 'export_handler',
  626. 'unpack_translatable' => 'unpack_handler',
  627. ),
  628. 'filter_groups' => array(
  629. 'contains' => array(
  630. 'operator' => array('default' => 'AND'),
  631. 'groups' => array('default' => array(1 => 'AND')),
  632. ),
  633. ),
  634. 'filters' => array(
  635. 'default' => array(),
  636. 'export' => 'export_handler',
  637. 'unpack_translatable' => 'unpack_handler',
  638. ),
  639. );
  640. if (empty($this->definition['use pager'])) {
  641. $options['defaults']['default']['use_pager'] = FALSE;
  642. $options['defaults']['default']['items_per_page'] = FALSE;
  643. $options['defaults']['default']['offset'] = FALSE;
  644. $options['defaults']['default']['pager'] = FALSE;
  645. $options['pager']['contains']['type']['default'] = 'some';
  646. }
  647. if ($this->is_default_display()) {
  648. unset($options['defaults']);
  649. }
  650. foreach ($this->extender as $extender) {
  651. $extender->options_definition_alter($options);
  652. }
  653. return $options;
  654. }
  655. /**
  656. * Check to see if the display has a 'path' field.
  657. *
  658. * This is a pure function and not just a setting on the definition
  659. * because some displays (such as a panel pane) may have a path based
  660. * upon configuration.
  661. *
  662. * By default, displays do not have a path.
  663. */
  664. function has_path() { return FALSE; }
  665. /**
  666. * Check to see if the display has some need to link to another display.
  667. *
  668. * For the most part, displays without a path will use a link display. However,
  669. * sometimes displays that have a path might also need to link to another display.
  670. * This is true for feeds.
  671. */
  672. function uses_link_display() { return !$this->has_path(); }
  673. /**
  674. * Check to see if the display can put the exposed formin a block.
  675. *
  676. * By default, displays that do not have a path cannot disconnect
  677. * the exposed form and put it in a block, because the form has no
  678. * place to go and Views really wants the forms to go to a specific
  679. * page.
  680. */
  681. function uses_exposed_form_in_block() { return $this->has_path(); }
  682. /**
  683. * Check to see which display to use when creating links within
  684. * a view using this display.
  685. */
  686. function get_link_display() {
  687. $display_id = $this->get_option('link_display');
  688. // If unknown, pick the first one.
  689. if (empty($display_id) || empty($this->view->display[$display_id])) {
  690. foreach ($this->view->display as $display_id => $display) {
  691. if (!empty($display->handler) && $display->handler->has_path()) {
  692. return $display_id;
  693. }
  694. }
  695. }
  696. else {
  697. return $display_id;
  698. }
  699. // fall-through returns NULL
  700. }
  701. /**
  702. * Return the base path to use for this display.
  703. *
  704. * This can be overridden for displays that do strange things
  705. * with the path.
  706. */
  707. function get_path() {
  708. if ($this->has_path()) {
  709. return $this->get_option('path');
  710. }
  711. $display_id = $this->get_link_display();
  712. if ($display_id && !empty($this->view->display[$display_id]) && is_object($this->view->display[$display_id]->handler)) {
  713. return $this->view->display[$display_id]->handler->get_path();
  714. }
  715. if ($this->get_option('link_display') == 'custom_url' && $link_url = $this->get_option('link_url')) {
  716. return $link_url;
  717. }
  718. }
  719. function get_url() {
  720. return $this->view->get_url();
  721. }
  722. /**
  723. * Check to see if the display needs a breadcrumb
  724. *
  725. * By default, displays do not need breadcrumbs
  726. */
  727. function uses_breadcrumb() { return FALSE; }
  728. /**
  729. * Determine if a given option is set to use the default display or the
  730. * current display
  731. *
  732. * @return
  733. * TRUE for the default display
  734. */
  735. function is_defaulted($option) {
  736. return !$this->is_default_display() && !empty($this->default_display) && !empty($this->options['defaults'][$option]);
  737. }
  738. /**
  739. * Intelligently get an option either from this display or from the
  740. * default display, if directed to do so.
  741. */
  742. function get_option($option) {
  743. if ($this->is_defaulted($option)) {
  744. return $this->default_display->get_option($option);
  745. }
  746. if (array_key_exists($option, $this->options)) {
  747. return $this->options[$option];
  748. }
  749. }
  750. /**
  751. * Determine if the display's style uses fields.
  752. */
  753. function uses_fields() {
  754. $plugin = $this->get_plugin();
  755. if ($plugin) {
  756. return $plugin->uses_fields();
  757. }
  758. }
  759. /**
  760. * Get the instance of a plugin, for example style or row.
  761. *
  762. * @param string $type
  763. * The type of the plugin.
  764. * @param string $name
  765. * The name of the plugin defined in hook_views_plugins.
  766. *
  767. * @return views_plugin|FALSE
  768. */
  769. function get_plugin($type = 'style', $name = NULL) {
  770. static $cache = array();
  771. if (!isset($cache[$type][$name])) {
  772. switch ($type) {
  773. case 'style':
  774. case 'row':
  775. $option_name = $type . '_plugin';
  776. $options = $this->get_option($type . '_options');
  777. if (!$name) {
  778. $name = $this->get_option($option_name);
  779. }
  780. break;
  781. case 'query':
  782. $views_data = views_fetch_data($this->view->base_table);
  783. $name = !empty($views_data['table']['base']['query class']) ? $views_data['table']['base']['query class'] : 'views_query';
  784. default:
  785. $option_name = $type;
  786. $options = $this->get_option($type);
  787. if (!$name) {
  788. $name = $options['type'];
  789. }
  790. // access & cache store their options as siblings with the
  791. // type; all others use an 'options' array.
  792. if ($type != 'access' && $type != 'cache') {
  793. $options = $options['options'];
  794. }
  795. }
  796. $plugin = views_get_plugin($type, $name);
  797. if (!$plugin) {
  798. return;
  799. }
  800. if ($type != 'query') {
  801. $plugin->init($this->view, $this->display, $options);
  802. }
  803. else {
  804. $display_id = $this->is_defaulted($option_name) ? $this->display->id : 'default';
  805. $plugin->localization_keys = array($display_id, $type);
  806. if (!isset($this->base_field)) {
  807. $views_data = views_fetch_data($this->view->base_table);
  808. $this->view->base_field = !empty($views_data['table']['base']['field']) ? $views_data['table']['base']['field'] : '';
  809. }
  810. $plugin->init($this->view->base_table, $this->view->base_field, $options);
  811. }
  812. $cache[$type][$name] = $plugin;
  813. }
  814. return $cache[$type][$name];
  815. }
  816. /**
  817. * Get the handler object for a single handler.
  818. */
  819. function &get_handler($type, $id) {
  820. if (!isset($this->handlers[$type])) {
  821. $this->get_handlers($type);
  822. }
  823. if (isset($this->handlers[$type][$id])) {
  824. return $this->handlers[$type][$id];
  825. }
  826. // So we can return a reference.
  827. $null = NULL;
  828. return $null;
  829. }
  830. /**
  831. * Get a full array of handlers for $type. This caches them.
  832. */
  833. function get_handlers($type) {
  834. if (!isset($this->handlers[$type])) {
  835. $this->handlers[$type] = array();
  836. $types = views_object_types();
  837. $plural = $types[$type]['plural'];
  838. foreach ($this->get_option($plural) as $id => $info) {
  839. // If this is during form submission and there are temporary options
  840. // which can only appear if the view is in the edit cache, use those
  841. // options instead. This is used for AJAX multi-step stuff.
  842. if (isset($_POST['form_id']) && isset($this->view->temporary_options[$type][$id])) {
  843. $info = $this->view->temporary_options[$type][$id];
  844. }
  845. if ($info['id'] != $id) {
  846. $info['id'] = $id;
  847. }
  848. // If aggregation is on, the group type might override the actual
  849. // handler that is in use. This piece of code checks that and,
  850. // if necessary, sets the override handler.
  851. $override = NULL;
  852. if ($this->use_group_by() && !empty($info['group_type'])) {
  853. if (empty($this->view->query)) {
  854. $this->view->init_query();
  855. }
  856. $aggregate = $this->view->query->get_aggregation_info();
  857. if (!empty($aggregate[$info['group_type']]['handler'][$type])) {
  858. $override = $aggregate[$info['group_type']]['handler'][$type];
  859. }
  860. }
  861. if (!empty($types[$type]['type'])) {
  862. $handler_type = $types[$type]['type'];
  863. }
  864. else {
  865. $handler_type = $type;
  866. }
  867. $handler = views_get_handler($info['table'], $info['field'], $handler_type, $override);
  868. if ($handler) {
  869. // Special override for area types so they know where they come from.
  870. if ($handler_type == 'area') {
  871. $handler->handler_type = $type;
  872. }
  873. $handler->init($this->view, $info);
  874. $this->handlers[$type][$id] = &$handler;
  875. }
  876. // Prevent reference problems.
  877. unset($handler);
  878. }
  879. }
  880. return $this->handlers[$type];
  881. }
  882. /**
  883. * Retrieve a list of fields for the current display with the
  884. * relationship associated if it exists.
  885. *
  886. * @param $groupable_only
  887. * Return only an array of field labels from handler that return TRUE
  888. * from use_string_group_by method.
  889. */
  890. function get_field_labels() {
  891. // Use func_get_arg so the function signature isn't amended
  892. // but we can still pass TRUE into the function to filter
  893. // by groupable handlers.
  894. $args = func_get_args();
  895. $groupable_only = isset($args[0]) ? $args[0] : FALSE;
  896. $options = array();
  897. foreach ($this->get_handlers('relationship') as $relationship => $handler) {
  898. if ($label = $handler->label()) {
  899. $relationships[$relationship] = $label;
  900. }
  901. else {
  902. $relationships[$relationship] = $handler->ui_name();
  903. }
  904. }
  905. foreach ($this->get_handlers('field') as $id => $handler) {
  906. if ($groupable_only && !$handler->use_string_group_by()) {
  907. // Continue to next handler if it's not groupable.
  908. continue;
  909. }
  910. if ($label = $handler->label()) {
  911. $options[$id] = $label;
  912. }
  913. else {
  914. $options[$id] = $handler->ui_name();
  915. }
  916. if (!empty($handler->options['relationship']) && !empty($relationships[$handler->options['relationship']])) {
  917. $options[$id] = '(' . $relationships[$handler->options['relationship']] . ') ' . $options[$id];
  918. }
  919. }
  920. return $options;
  921. }
  922. /**
  923. * Intelligently set an option either from this display or from the
  924. * default display, if directed to do so.
  925. */
  926. function set_option($option, $value) {
  927. if ($this->is_defaulted($option)) {
  928. return $this->default_display->set_option($option, $value);
  929. }
  930. // Set this in two places: On the handler where we'll notice it
  931. // but also on the display object so it gets saved. This should
  932. // only be a temporary fix.
  933. $this->display->display_options[$option] = $value;
  934. return $this->options[$option] = $value;
  935. }
  936. /**
  937. * Set an option and force it to be an override.
  938. */
  939. function override_option($option, $value) {
  940. $this->set_override($option, FALSE);
  941. $this->set_option($option, $value);
  942. }
  943. /**
  944. * Because forms may be split up into sections, this provides
  945. * an easy URL to exactly the right section. Don't override this.
  946. */
  947. function option_link($text, $section, $class = '', $title = '') {
  948. views_add_js('ajax');
  949. if (!empty($class)) {
  950. $text = '<span>' . $text . '</span>';
  951. }
  952. if (!trim($text)) {
  953. $text = t('Broken field');
  954. }
  955. if (empty($title)) {
  956. $title = $text;
  957. }
  958. return l($text, 'admin/structure/views/nojs/display/' . $this->view->name . '/' . $this->display->id . '/' . $section, array('attributes' => array('class' => 'views-ajax-link ' . $class, 'title' => $title, 'id' => drupal_html_id('views-' . $this->display->id . '-' . $section)), 'html' => TRUE));
  959. }
  960. /**
  961. * Returns to tokens for arguments.
  962. *
  963. * This function is similar to views_handler_field::get_render_tokens()
  964. * but without fields tokens.
  965. */
  966. function get_arguments_tokens() {
  967. $tokens = array();
  968. if (!empty($this->view->build_info['substitutions'])) {
  969. $tokens = $this->view->build_info['substitutions'];
  970. }
  971. $count = 0;
  972. foreach ($this->view->display_handler->get_handlers('argument') as $arg => $handler) {
  973. $token = '%' . ++$count;
  974. if (!isset($tokens[$token])) {
  975. $tokens[$token] = '';
  976. }
  977. // Use strip tags as there should never be HTML in the path.
  978. // However, we need to preserve special characters like " that
  979. // were removed by check_plain().
  980. $tokens['!' . $count] = isset($this->view->args[$count - 1]) ? strip_tags(decode_entities($this->view->args[$count - 1])) : '';
  981. }
  982. return $tokens;
  983. }
  984. /**
  985. * Provide the default summary for options in the views UI.
  986. *
  987. * This output is returned as an array.
  988. */
  989. function options_summary(&$categories, &$options) {
  990. $categories = array(
  991. 'title' => array(
  992. 'title' => t('Title'),
  993. 'column' => 'first',
  994. ),
  995. 'format' => array(
  996. 'title' => t('Format'),
  997. 'column' => 'first',
  998. ),
  999. 'filters' => array(
  1000. 'title' => t('Filters'),
  1001. 'column' => 'first',
  1002. ),
  1003. 'fields' => array(
  1004. 'title' => t('Fields'),
  1005. 'column' => 'first',
  1006. ),
  1007. 'pager' => array(
  1008. 'title' => t('Pager'),
  1009. 'column' => 'second',
  1010. ),
  1011. 'exposed' => array(
  1012. 'title' => t('Exposed form'),
  1013. 'column' => 'third',
  1014. 'build' => array(
  1015. '#weight' => 1,
  1016. ),
  1017. ),
  1018. 'access' => array(
  1019. 'title' => '',
  1020. 'column' => 'second',
  1021. 'build' => array(
  1022. '#weight' => -5,
  1023. ),
  1024. ),
  1025. 'other' => array(
  1026. 'title' => t('Other'),
  1027. 'column' => 'third',
  1028. 'build' => array(
  1029. '#weight' => 2,
  1030. ),
  1031. ),
  1032. );
  1033. if ($this->display->id != 'default') {
  1034. $options['display_id'] = array(
  1035. 'category' => 'other',
  1036. 'title' => t('Machine Name'),
  1037. 'value' => !empty($this->display->new_id) ? check_plain($this->display->new_id) : check_plain($this->display->id),
  1038. 'desc' => t('Change the machine name of this display.'),
  1039. );
  1040. }
  1041. $display_comment = check_plain(drupal_substr($this->get_option('display_comment'), 0, 10));
  1042. $options['display_comment'] = array(
  1043. 'category' => 'other',
  1044. 'title' => t('Comment'),
  1045. 'value' => !empty($display_comment) ? $display_comment : t('No comment'),
  1046. 'desc' => t('Comment or document this display.'),
  1047. );
  1048. $title = strip_tags($this->get_option('title'));
  1049. if (!$title) {
  1050. $title = t('None');
  1051. }
  1052. $options['title'] = array(
  1053. 'category' => 'title',
  1054. 'title' => t('Title'),
  1055. 'value' => $title,
  1056. 'desc' => t('Change the title that this display will use.'),
  1057. );
  1058. $style_plugin = views_fetch_plugin_data('style', $this->get_option('style_plugin'));
  1059. $style_plugin_instance = $this->get_plugin('style');
  1060. $style_summary = empty($style_plugin['title']) ? t('Missing style plugin') : $style_plugin_instance->summary_title();
  1061. $style_title = empty($style_plugin['title']) ? t('Missing style plugin') : $style_plugin_instance->plugin_title();
  1062. $style = '';
  1063. $options['style_plugin'] = array(
  1064. 'category' => 'format',
  1065. 'title' => t('Format'),
  1066. 'value' => $style_title,
  1067. 'setting' => $style_summary,
  1068. 'desc' => t('Change the way content is formatted.'),
  1069. );
  1070. // This adds a 'Settings' link to the style_options setting if the style has options.
  1071. if (!empty($style_plugin['uses options'])) {
  1072. $options['style_plugin']['links']['style_options'] = t('Change settings for this format');
  1073. }
  1074. if (!empty($style_plugin['uses row plugin'])) {
  1075. $row_plugin = views_fetch_plugin_data('row', $this->get_option('row_plugin'));
  1076. $row_plugin_instance = $this->get_plugin('row');
  1077. $row_summary = empty($row_plugin['title']) ? t('Missing style plugin') : $row_plugin_instance->summary_title();
  1078. $row_title = empty($row_plugin['title']) ? t('Missing style plugin') : $row_plugin_instance->plugin_title();
  1079. $options['row_plugin'] = array(
  1080. 'category' => 'format',
  1081. 'title' => t('Show'),
  1082. 'value' => $row_title,
  1083. 'setting' => $row_summary,
  1084. 'desc' => t('Change the way each row in the view is styled.'),
  1085. );
  1086. // This adds a 'Settings' link to the row_options setting if the row style has options.
  1087. if (!empty($row_plugin['uses options'])) {
  1088. $options['row_plugin']['links']['row_options'] = t('Change settings for this style');
  1089. }
  1090. }
  1091. if (!empty($this->definition['use ajax'])) {
  1092. $options['use_ajax'] = array(
  1093. 'category' => 'other',
  1094. 'title' => t('Use AJAX'),
  1095. 'value' => $this->get_option('use_ajax') ? t('Yes') : t('No'),
  1096. 'desc' => t('Change whether or not this display will use AJAX.'),
  1097. );
  1098. }
  1099. if (!empty($this->definition['accept attachments'])) {
  1100. $options['hide_attachment_summary'] = array(
  1101. 'category' => 'other',
  1102. 'title' => t('Hide attachments in summary'),
  1103. 'value' => $this->get_option('hide_attachment_summary') ? t('Yes') : t('No'),
  1104. 'desc' => t('Change whether or not to display attachments when displaying a contextual filter summary.'),
  1105. );
  1106. }
  1107. if (!isset($this->definition['contextual links locations']) || !empty($this->definition['contextual links locations'])) {
  1108. $options['hide_admin_links'] = array(
  1109. 'category' => 'other',
  1110. 'title' => t('Hide contextual links'),
  1111. 'value' => $this->get_option('hide_admin_links') ? t('Yes') : t('No'),
  1112. 'desc' => t('Change whether or not to display contextual links for this view.'),
  1113. );
  1114. }
  1115. $pager_plugin = $this->get_plugin('pager');
  1116. if (!$pager_plugin) {
  1117. // default to the no pager plugin.
  1118. $pager_plugin = views_get_plugin('pager', 'none');
  1119. }
  1120. $pager_str = $pager_plugin->summary_title();
  1121. $options['pager'] = array(
  1122. 'category' => 'pager',
  1123. 'title' => t('Use pager'),
  1124. 'value' => $pager_plugin->plugin_title(),
  1125. 'setting' => $pager_str,
  1126. 'desc' => t("Change this display's pager setting."),
  1127. );
  1128. // If pagers aren't allowed, change the text of the item:
  1129. if (empty($this->definition['use pager'])) {
  1130. $options['pager']['title'] = t('Items to display');
  1131. }
  1132. if (!empty($pager_plugin->definition['uses options'])) {
  1133. $options['pager']['links']['pager_options'] = t('Change settings for this pager type.');
  1134. }
  1135. if (!empty($this->definition['use more'])) {
  1136. $options['use_more'] = array(
  1137. 'category' => 'pager',
  1138. 'title' => t('More link'),
  1139. 'value' => $this->get_option('use_more') ? t('Yes') : t('No'),
  1140. 'desc' => t('Specify whether this display will provide a "more" link.'),
  1141. );
  1142. }
  1143. $this->view->init_query();
  1144. if ($this->view->query->get_aggregation_info()) {
  1145. $options['group_by'] = array(
  1146. 'category' => 'other',
  1147. 'title' => t('Use aggregation'),
  1148. 'value' => $this->get_option('group_by') ? t('Yes') : t('No'),
  1149. 'desc' => t('Allow grouping and aggregation (calculation) of fields.'),
  1150. );
  1151. }
  1152. $options['query'] = array(
  1153. 'category' => 'other',
  1154. 'title' => t('Query settings'),
  1155. 'value' => t('Settings'),
  1156. 'desc' => t('Allow to set some advanced settings for the query plugin'),
  1157. );
  1158. $languages = array(
  1159. '***CURRENT_LANGUAGE***' => t("Current user's language"),
  1160. '***DEFAULT_LANGUAGE***' => t("Default site language"),
  1161. LANGUAGE_NONE => t('Language neutral'),
  1162. );
  1163. if (module_exists('locale')) {
  1164. $languages = array_merge($languages, locale_language_list());
  1165. }
  1166. $field_language = array();
  1167. $options['field_language'] = array(
  1168. 'category' => 'other',
  1169. 'title' => t('Field Language'),
  1170. 'value' => $languages[$this->get_option('field_language')],
  1171. 'desc' => t('All fields which support translations will be displayed in the selected language.'),
  1172. );
  1173. $access_plugin = $this->get_plugin('access');
  1174. if (!$access_plugin) {
  1175. // default to the no access control plugin.
  1176. $access_plugin = views_get_plugin('access', 'none');
  1177. }
  1178. $access_str = $access_plugin->summary_title();
  1179. $options['access'] = array(
  1180. 'category' => 'access',
  1181. 'title' => t('Access'),
  1182. 'value' => $access_plugin->plugin_title(),
  1183. 'setting' => $access_str,
  1184. 'desc' => t('Specify access control type for this display.'),
  1185. );
  1186. if (!empty($access_plugin->definition['uses options'])) {
  1187. $options['access']['links']['access_options'] = t('Change settings for this access type.');
  1188. }
  1189. $cache_plugin = $this->get_plugin('cache');
  1190. if (!$cache_plugin) {
  1191. // default to the no cache control plugin.
  1192. $cache_plugin = views_get_plugin('cache', 'none');
  1193. }
  1194. $cache_str = $cache_plugin->summary_title();
  1195. $options['cache'] = array(
  1196. 'category' => 'other',
  1197. 'title' => t('Caching'),
  1198. 'value' => $cache_plugin->plugin_title(),
  1199. 'setting' => $cache_str,
  1200. 'desc' => t('Specify caching type for this display.'),
  1201. );
  1202. if (!empty($cache_plugin->definition['uses options'])) {
  1203. $options['cache']['links']['cache_options'] = t('Change settings for this caching type.');
  1204. }
  1205. if (!empty($access_plugin->definition['uses options'])) {
  1206. $options['access']['links']['access_options'] = t('Change settings for this access type.');
  1207. }
  1208. if ($this->uses_link_display()) {
  1209. $display_id = $this->get_link_display();
  1210. $link_display = empty($this->view->display[$display_id]) ? t('None') : check_plain($this->view->display[$display_id]->display_title);
  1211. $link_display = $this->get_option('link_display') == 'custom_url' ? t('Custom URL') : $link_display;
  1212. $options['link_display'] = array(
  1213. 'category' => 'other',
  1214. 'title' => t('Link display'),
  1215. 'value' => $link_display,
  1216. 'desc' => t('Specify which display or custom url this display will link to.'),
  1217. );
  1218. }
  1219. if ($this->uses_exposed_form_in_block()) {
  1220. $options['exposed_block'] = array(
  1221. 'category' => 'exposed',
  1222. 'title' => t('Exposed form in block'),
  1223. 'value' => $this->get_option('exposed_block') ? t('Yes') : t('No'),
  1224. 'desc' => t('Allow the exposed form to appear in a block instead of the view.'),
  1225. );
  1226. }
  1227. $exposed_form_plugin = $this->get_plugin('exposed_form');
  1228. if (!$exposed_form_plugin) {
  1229. // default to the no cache control plugin.
  1230. $exposed_form_plugin = views_get_plugin('exposed_form', 'basic');
  1231. }
  1232. $exposed_form_str = $exposed_form_plugin->summary_title();
  1233. $options['exposed_form'] = array(
  1234. 'category' => 'exposed',
  1235. 'title' => t('Exposed form style'),
  1236. 'value' => $exposed_form_plugin->plugin_title(),
  1237. 'setting' => $exposed_form_str,
  1238. 'desc' => t('Select the kind of exposed filter to use.'),
  1239. );
  1240. if (!empty($exposed_form_plugin->definition['uses options'])) {
  1241. $options['exposed_form']['links']['exposed_form_options'] = t('Exposed form settings for this exposed form style.');
  1242. }
  1243. $css_class = check_plain(trim($this->get_option('css_class')));
  1244. if (!$css_class) {
  1245. $css_class = t('None');
  1246. }
  1247. $options['css_class'] = array(
  1248. 'category' => 'other',
  1249. 'title' => t('CSS class'),
  1250. 'value' => $css_class,
  1251. 'desc' => t('Change the CSS class name(s) that will be added to this display.'),
  1252. );
  1253. $options['analyze-theme'] = array(
  1254. 'category' => 'other',
  1255. 'title' => t('Theme'),
  1256. 'value' => t('Information'),
  1257. 'desc' => t('Get information on how to theme this display'),
  1258. );
  1259. foreach ($this->extender as $extender) {
  1260. $extender->options_summary($categories, $options);
  1261. }
  1262. }
  1263. /**
  1264. * Provide the default form for setting options.
  1265. */
  1266. function options_form(&$form, &$form_state) {
  1267. parent::options_form($form, $form_state);
  1268. if ($this->defaultable_sections($form_state['section'])) {
  1269. views_ui_standard_display_dropdown($form, $form_state, $form_state['section']);
  1270. }
  1271. $form['#title'] = check_plain($this->display->display_title) . ': ';
  1272. // Set the 'section' to hilite on the form.
  1273. // If it's the item we're looking at is pulling from the default display,
  1274. // reflect that. Don't use is_defaulted since we want it to show up even
  1275. // on the default display.
  1276. if (!empty($this->options['defaults'][$form_state['section']])) {
  1277. $form['#section'] = 'default-' . $form_state['section'];
  1278. }
  1279. else {
  1280. $form['#section'] = $this->display->id . '-' . $form_state['section'];
  1281. }
  1282. switch ($form_state['section']) {
  1283. case 'display_id':
  1284. $form['#title'] .= t('The machine name of this display');
  1285. $form['display_id'] = array(
  1286. '#type' => 'textfield',
  1287. '#description' => t('This is machine name of the display.'),
  1288. '#default_value' => !empty($this->display->new_id) ? $this->display->new_id : $this->display->id,
  1289. '#required' => TRUE,
  1290. '#size' => 64,
  1291. );
  1292. break;
  1293. case 'display_title':
  1294. $form['#title'] .= t('The name and the description of this display');
  1295. $form['display_title'] = array(
  1296. '#title' => t('Name'),
  1297. '#type' => 'textfield',
  1298. '#description' => t('This name will appear only in the administrative interface for the View.'),
  1299. '#default_value' => $this->display->display_title,
  1300. );
  1301. $form['display_description'] = array(
  1302. '#title' => t('Description'),
  1303. '#type' => 'textfield',
  1304. '#description' => t('This description will appear only in the administrative interface for the View.'),
  1305. '#default_value' => $this->get_option('display_description'),
  1306. );
  1307. break;
  1308. case 'display_comment':
  1309. $form['#title'] .= t("This display's comments");
  1310. $form['display_comment'] = array(
  1311. '#type' => 'textarea',
  1312. '#description' => t('This value will be seen and used only within the Views UI and can be used to document this display. You can use this to provide notes for other or future maintainers of your site about how or why this display is configured.'),
  1313. '#default_value' => $this->get_option('display_comment'),
  1314. );
  1315. break;
  1316. case 'title':
  1317. $form['#title'] .= t('The title of this view');
  1318. $form['title'] = array(
  1319. '#type' => 'textfield',
  1320. '#description' => t('This title will be displayed with the view, wherever titles are normally displayed; i.e, as the page title, block title, etc.'),
  1321. '#default_value' => $this->get_option('title'),
  1322. );
  1323. break;
  1324. case 'css_class':
  1325. $form['#title'] .= t('CSS class');
  1326. $form['css_class'] = array(
  1327. '#type' => 'textfield',
  1328. '#description' => t('The CSS class names will be added to the view. This enables you to use specific CSS code for each view. You may define multiples classes separated by spaces.'),
  1329. '#default_value' => $this->get_option('css_class'),
  1330. );
  1331. break;
  1332. case 'use_ajax':
  1333. $form['#title'] .= t('Use AJAX when available to load this view');
  1334. $form['description'] = array(
  1335. '#markup' => '<div class="description form-item">' . t('If set, this view will use an AJAX mechanism for paging, table sorting and exposed filters. This means the entire page will not refresh. It is not recommended that you use this if this view is the main content of the page as it will prevent deep linking to specific pages, but it is very useful for side content.') . '</div>',
  1336. );
  1337. $form['use_ajax'] = array(
  1338. '#type' => 'radios',
  1339. '#options' => array(1 => t('Yes'), 0 => t('No')),
  1340. '#default_value' => $this->get_option('use_ajax') ? 1 : 0,
  1341. );
  1342. break;
  1343. case 'hide_attachment_summary':
  1344. $form['#title'] .= t('Hide attachments when displaying a contextual filter summary');
  1345. $form['hide_attachment_summary'] = array(
  1346. '#type' => 'radios',
  1347. '#options' => array(1 => t('Yes'), 0 => t('No')),
  1348. '#default_value' => $this->get_option('hide_attachment_summary') ? 1 : 0,
  1349. );
  1350. break;
  1351. case 'hide_admin_links':
  1352. $form['#title'] .= t('Hide contextual links on this view.');
  1353. $form['hide_admin_links'] = array(
  1354. '#type' => 'radios',
  1355. '#options' => array(1 => t('Yes'), 0 => t('No')),
  1356. '#default_value' => $this->get_option('hide_admin_links') ? 1 : 0,
  1357. );
  1358. break;
  1359. case 'use_more':
  1360. $form['#title'] .= t('Add a more link to the bottom of the display.');
  1361. $form['use_more'] = array(
  1362. '#type' => 'checkbox',
  1363. '#title' => t('Create more link'),
  1364. '#description' => t("This will add a more link to the bottom of this view, which will link to the page view. If you have more than one page view, the link will point to the display specified in 'Link display' section under advanced. You can override the url at the link display setting."),
  1365. '#default_value' => $this->get_option('use_more'),
  1366. );
  1367. $form['use_more_always'] = array(
  1368. '#type' => 'checkbox',
  1369. '#title' => t("Display 'more' link only if there is more content"),
  1370. '#description' => t("Leave this unchecked to display the 'more' link even if there are no more items to display."),
  1371. '#default_value' => !$this->get_option('use_more_always'),
  1372. '#dependency' => array(
  1373. 'edit-use-more' => array(TRUE),
  1374. ),
  1375. );
  1376. $form['use_more_text'] = array(
  1377. '#type' => 'textfield',
  1378. '#title' => t('More link text'),
  1379. '#description' => t("The text to display for the more link."),
  1380. '#default_value' => $this->get_option('use_more_text'),
  1381. '#dependency' => array(
  1382. 'edit-use-more' => array(TRUE),
  1383. ),
  1384. );
  1385. break;
  1386. case 'group_by':
  1387. $form['#title'] .= t('Allow grouping and aggregation (calculation) of fields.');
  1388. $form['group_by'] = array(
  1389. '#type' => 'checkbox',
  1390. '#title' => t('Aggregate'),
  1391. '#description' => t('If enabled, some fields may become unavailable. All fields that are selected for grouping will be collapsed to one record per distinct value. Other fields which are selected for aggregation will have the function run on them. For example, you can group nodes on title and count the number of nids in order to get a list of duplicate titles.'),
  1392. '#default_value' => $this->get_option('group_by'),
  1393. );
  1394. break;
  1395. case 'access':
  1396. $form['#title'] .= t('Access restrictions');
  1397. $form['access'] = array(
  1398. '#prefix' => '<div class="clearfix">',
  1399. '#suffix' => '</div>',
  1400. '#tree' => TRUE,
  1401. );
  1402. $access = $this->get_option('access');
  1403. $form['access']['type'] = array(
  1404. '#type' => 'radios',
  1405. '#options' => views_fetch_plugin_names('access', NULL, array($this->view->base_table)),
  1406. '#default_value' => $access['type'],
  1407. );
  1408. $access_plugin = views_fetch_plugin_data('access', $access['type']);
  1409. if (!empty($access_plugin['uses options'])) {
  1410. $form['markup'] = array(
  1411. '#prefix' => '<div class="form-item description">',
  1412. '#markup' => t('You may also adjust the !settings for the currently selected access restriction.', array('!settings' => $this->option_link(t('settings'), 'access_options'))),
  1413. '#suffix' => '</div>',
  1414. );
  1415. }
  1416. break;
  1417. case 'access_options':
  1418. $access = $this->get_option('access');
  1419. $plugin = $this->get_plugin('access');
  1420. $form['#title'] .= t('Access options');
  1421. if ($plugin) {
  1422. $form['#help_topic'] = $plugin->definition['help topic'];
  1423. $form['#help_module'] = $plugin->definition['module'];
  1424. $form['access_options'] = array(
  1425. '#tree' => TRUE,
  1426. );
  1427. $form['access_options']['type'] = array(
  1428. '#type' => 'value',
  1429. '#value' => $access['type'],
  1430. );
  1431. $plugin->options_form($form['access_options'], $form_state);
  1432. }
  1433. break;
  1434. case 'cache':
  1435. $form['#title'] .= t('Caching');
  1436. $form['cache'] = array(
  1437. '#prefix' => '<div class="clearfix">',
  1438. '#suffix' => '</div>',
  1439. '#tree' => TRUE,
  1440. );
  1441. $cache = $this->get_option('cache');
  1442. $form['cache']['type'] = array(
  1443. '#type' => 'radios',
  1444. '#options' => views_fetch_plugin_names('cache', NULL, array($this->view->base_table)),
  1445. '#default_value' => $cache['type'],
  1446. );
  1447. $cache_plugin = views_fetch_plugin_data('cache', $cache['type']);
  1448. if (!empty($cache_plugin['uses options'])) {
  1449. $form['markup'] = array(
  1450. '#prefix' => '<div class="form-item description">',
  1451. '#suffix' => '</div>',
  1452. '#markup' => t('You may also adjust the !settings for the currently selected cache mechanism.', array('!settings' => $this->option_link(t('settings'), 'cache_options'))),
  1453. );
  1454. }
  1455. break;
  1456. case 'cache_options':
  1457. $cache = $this->get_option('cache');
  1458. $plugin = $this->get_plugin('cache');
  1459. $form['#title'] .= t('Caching options');
  1460. if ($plugin) {
  1461. $form['#help_topic'] = $plugin->definition['help topic'];
  1462. $form['#help_module'] = $plugin->definition['module'];
  1463. $form['cache_options'] = array(
  1464. '#tree' => TRUE,
  1465. );
  1466. $form['cache_options']['type'] = array(
  1467. '#type' => 'value',
  1468. '#value' => $cache['type'],
  1469. );
  1470. $plugin->options_form($form['cache_options'], $form_state);
  1471. }
  1472. break;
  1473. case 'query':
  1474. $query_options = $this->get_option('query');
  1475. $plugin_name = $query_options['type'];
  1476. $form['#title'] .= t('Query options');
  1477. $this->view->init_query();
  1478. if ($this->view->query) {
  1479. if (isset($this->view->query->definition['help topic'])) {
  1480. $form['#help_topic'] = $this->view->query->definition['help topic'];
  1481. }
  1482. if (isset($this->view->query->definition['module'])) {
  1483. $form['#help_module'] = $this->view->query->definition['module'];
  1484. }
  1485. $form['query'] = array(
  1486. '#tree' => TRUE,
  1487. 'type' => array(
  1488. '#type' => 'value',
  1489. '#value' => $plugin_name,
  1490. ),
  1491. 'options' => array(
  1492. '#tree' => TRUE,
  1493. ),
  1494. );
  1495. $this->view->query->options_form($form['query']['options'], $form_state);
  1496. }
  1497. break;
  1498. case 'field_language':
  1499. $form['#title'] .= t('Field Language');
  1500. $entities = entity_get_info();
  1501. $entity_tables = array();
  1502. $has_translation_handlers = FALSE;
  1503. foreach ($entities as $type => $entity_info) {
  1504. $entity_tables[] = $entity_info['base table'];
  1505. if (!empty($entity_info['translation'])) {
  1506. $has_translation_handlers = TRUE;
  1507. }
  1508. }
  1509. // Doesn't make sense to show a field setting here if we aren't querying
  1510. // an entity base table. Also, we make sure that there's at least one
  1511. // entity type with a translation handler attached.
  1512. if (in_array($this->view->base_table, $entity_tables) && $has_translation_handlers) {
  1513. $languages = array(
  1514. '***CURRENT_LANGUAGE***' => t("Current user's language"),
  1515. '***DEFAULT_LANGUAGE***' => t("Default site language"),
  1516. LANGUAGE_NONE => t('Language neutral'),
  1517. );
  1518. $languages = array_merge($languages, views_language_list());
  1519. $form['field_language'] = array(
  1520. '#type' => 'select',
  1521. '#title' => t('Field Language'),
  1522. '#description' => t('All fields which support translations will be displayed in the selected language.'),
  1523. '#options' => $languages,
  1524. '#default_value' => $this->get_option('field_language'),
  1525. );
  1526. $form['field_language_add_to_query'] = array(
  1527. '#type' => 'checkbox',
  1528. '#title' => t('When needed, add the field language condition to the query'),
  1529. '#default_value' => $this->get_option('field_language_add_to_query'),
  1530. );
  1531. }
  1532. else {
  1533. $form['field_language']['#markup'] = t("You don't have translatable entity types.");
  1534. }
  1535. break;
  1536. case 'style_plugin':
  1537. $form['#title'] .= t('How should this view be styled');
  1538. $form['#help_topic'] = 'style';
  1539. $form['style_plugin'] = array(
  1540. '#type' => 'radios',
  1541. '#options' => views_fetch_plugin_names('style', $this->get_style_type(), array($this->view->base_table)),
  1542. '#default_value' => $this->get_option('style_plugin'),
  1543. '#description' => t('If the style you choose has settings, be sure to click the settings button that will appear next to it in the View summary.'),
  1544. );
  1545. $style_plugin = views_fetch_plugin_data('style', $this->get_option('style_plugin'));
  1546. if (!empty($style_plugin['uses options'])) {
  1547. $form['markup'] = array(
  1548. '#markup' => '<div class="form-item description">' . t('You may also adjust the !settings for the currently selected style.', array('!settings' => $this->option_link(t('settings'), 'style_options'))) . '</div>',
  1549. );
  1550. }
  1551. break;
  1552. case 'style_options':
  1553. $form['#title'] .= t('Style options');
  1554. $style = TRUE;
  1555. $type = 'style_plugin';
  1556. $name = $this->get_option('style_plugin');
  1557. case 'row_options':
  1558. if (!isset($name)) {
  1559. $name = $this->get_option('row_plugin');
  1560. }
  1561. // if row, $style will be empty.
  1562. if (empty($style)) {
  1563. $form['#title'] .= t('Row style options');
  1564. $type = 'row_plugin';
  1565. }
  1566. $plugin = $this->get_plugin(empty($style) ? 'row' : 'style');
  1567. if ($plugin) {
  1568. if (isset($plugin->definition['help topic'])) {
  1569. $form['#help_topic'] = $plugin->definition['help topic'];
  1570. $form['#help_module'] = $plugin->definition['module'];
  1571. }
  1572. $form[$form_state['section']] = array(
  1573. '#tree' => TRUE,
  1574. );
  1575. $plugin->options_form($form[$form_state['section']], $form_state);
  1576. }
  1577. break;
  1578. case 'row_plugin':
  1579. $form['#title'] .= t('How should each row in this view be styled');
  1580. $form['#help_topic'] = 'style-row';
  1581. $form['row_plugin'] = array(
  1582. '#type' => 'radios',
  1583. '#options' => views_fetch_plugin_names('row', $this->get_style_type(), array($this->view->base_table)),
  1584. '#default_value' => $this->get_option('row_plugin'),
  1585. );
  1586. $row_plugin = views_fetch_plugin_data('row', $this->get_option('row_plugin'));
  1587. if (!empty($row_plugin['uses options'])) {
  1588. $form['markup'] = array(
  1589. '#markup' => '<div class="form-item description">' . t('You may also adjust the !settings for the currently selected row style.', array('!settings' => $this->option_link(t('settings'), 'row_options'))) . '</div>',
  1590. );
  1591. }
  1592. break;
  1593. case 'link_display':
  1594. $form['#title'] .= t('Which display to use for path');
  1595. foreach ($this->view->display as $display_id => $display) {
  1596. if ($display->handler->has_path()) {
  1597. $options[$display_id] = $display->display_title;
  1598. }
  1599. }
  1600. $options['custom_url'] = t('Custom URL');
  1601. if (count($options)) {
  1602. $form['link_display'] = array(
  1603. '#type' => 'radios',
  1604. '#options' => $options,
  1605. '#description' => t("Which display to use to get this display's path for things like summary links, rss feed links, more links, etc."),
  1606. '#default_value' => $this->get_option('link_display'),
  1607. );
  1608. }
  1609. $options = array();
  1610. $count = 0; // This lets us prepare the key as we want it printed.
  1611. foreach ($this->view->display_handler->get_handlers('argument') as $arg => $handler) {
  1612. $options[t('Arguments')]['%' . ++$count] = t('@argument title', array('@argument' => $handler->ui_name()));
  1613. $options[t('Arguments')]['!' . $count] = t('@argument input', array('@argument' => $handler->ui_name()));
  1614. }
  1615. // Default text.
  1616. // We have some options, so make a list.
  1617. $output = '';
  1618. if (!empty($options)) {
  1619. $output = t('<p>The following tokens are available for this link.</p>');
  1620. foreach (array_keys($options) as $type) {
  1621. if (!empty($options[$type])) {
  1622. $items = array();
  1623. foreach ($options[$type] as $key => $value) {
  1624. $items[] = $key . ' == ' . $value;
  1625. }
  1626. $output .= theme('item_list',
  1627. array(
  1628. 'items' => $items,
  1629. 'type' => $type
  1630. ));
  1631. }
  1632. }
  1633. }
  1634. $form['link_url'] = array(
  1635. '#type' => 'textfield',
  1636. '#title' => t('Custom URL'),
  1637. '#default_value' => $this->get_option('link_url'),
  1638. '#description' => t('A Drupal path or external URL the more link will point to. Note that this will override the link display setting above.') . $output,
  1639. '#dependency' => array('radio:link_display' => array('custom_url')),
  1640. );
  1641. break;
  1642. case 'analyze-theme':
  1643. $form['#title'] .= t('Theming information');
  1644. $form['#help_topic'] = 'analyze-theme';
  1645. if (isset($_POST['theme'])) {
  1646. $this->theme = $_POST['theme'];
  1647. }
  1648. elseif (empty($this->theme)) {
  1649. $this->theme = variable_get('theme_default', 'bartik');
  1650. }
  1651. if (isset($GLOBALS['theme']) && $GLOBALS['theme'] == $this->theme) {
  1652. $this->theme_registry = theme_get_registry();
  1653. $theme_engine = $GLOBALS['theme_engine'];
  1654. }
  1655. else {
  1656. $themes = list_themes();
  1657. $theme = $themes[$this->theme];
  1658. // Find all our ancestor themes and put them in an array.
  1659. $base_theme = array();
  1660. $ancestor = $this->theme;
  1661. while ($ancestor && isset($themes[$ancestor]->base_theme)) {
  1662. $ancestor = $themes[$ancestor]->base_theme;
  1663. $base_theme[] = $themes[$ancestor];
  1664. }
  1665. // The base themes should be initialized in the right order.
  1666. $base_theme = array_reverse($base_theme);
  1667. // This code is copied directly from _drupal_theme_initialize()
  1668. $theme_engine = NULL;
  1669. // Initialize the theme.
  1670. if (isset($theme->engine)) {
  1671. // Include the engine.
  1672. include_once DRUPAL_ROOT . '/' . $theme->owner;
  1673. $theme_engine = $theme->engine;
  1674. if (function_exists($theme_engine . '_init')) {
  1675. foreach ($base_theme as $base) {
  1676. call_user_func($theme_engine . '_init', $base);
  1677. }
  1678. call_user_func($theme_engine . '_init', $theme);
  1679. }
  1680. }
  1681. else {
  1682. // include non-engine theme files
  1683. foreach ($base_theme as $base) {
  1684. // Include the theme file or the engine.
  1685. if (!empty($base->owner)) {
  1686. include_once DRUPAL_ROOT . '/' . $base->owner;
  1687. }
  1688. }
  1689. // and our theme gets one too.
  1690. if (!empty($theme->owner)) {
  1691. include_once DRUPAL_ROOT . '/' . $theme->owner;
  1692. }
  1693. }
  1694. $this->theme_registry = _theme_load_registry($theme, $base_theme, $theme_engine);
  1695. }
  1696. // If there's a theme engine involved, we also need to know its extension
  1697. // so we can give the proper filename.
  1698. $this->theme_extension = '.tpl.php';
  1699. if (isset($theme_engine)) {
  1700. $extension_function = $theme_engine . '_extension';
  1701. if (function_exists($extension_function)) {
  1702. $this->theme_extension = $extension_function();
  1703. }
  1704. }
  1705. $funcs = array();
  1706. // Get theme functions for the display. Note that some displays may
  1707. // not have themes. The 'feed' display, for example, completely
  1708. // delegates to the style.
  1709. if (!empty($this->definition['theme'])) {
  1710. $funcs[] = $this->option_link(t('Display output'), 'analyze-theme-display') . ': ' . $this->format_themes($this->theme_functions());
  1711. $themes = $this->additional_theme_functions();
  1712. if ($themes) {
  1713. foreach ($themes as $theme) {
  1714. $funcs[] = $this->option_link(t('Alternative display output'), 'analyze-theme-display') . ': ' . $this->format_themes($theme);
  1715. }
  1716. }
  1717. }
  1718. $plugin = $this->get_plugin();
  1719. if ($plugin) {
  1720. $funcs[] = $this->option_link(t('Style output'), 'analyze-theme-style') . ': ' . $this->format_themes($plugin->theme_functions(), $plugin->additional_theme_functions());
  1721. $themes = $plugin->additional_theme_functions();
  1722. if ($themes) {
  1723. foreach ($themes as $theme) {
  1724. $funcs[] = $this->option_link(t('Alternative style'), 'analyze-theme-style') . ': ' . $this->format_themes($theme);
  1725. }
  1726. }
  1727. if ($plugin->uses_row_plugin()) {
  1728. $row_plugin = $this->get_plugin('row');
  1729. if ($row_plugin) {
  1730. $funcs[] = $this->option_link(t('Row style output'), 'analyze-theme-row') . ': ' . $this->format_themes($row_plugin->theme_functions());
  1731. $themes = $row_plugin->additional_theme_functions();
  1732. if ($themes) {
  1733. foreach ($themes as $theme) {
  1734. $funcs[] = $this->option_link(t('Alternative row style'), 'analyze-theme-row') . ': ' . $this->format_themes($theme);
  1735. }
  1736. }
  1737. }
  1738. }
  1739. if ($plugin->uses_fields()) {
  1740. foreach ($this->get_handlers('field') as $id => $handler) {
  1741. $funcs[] = $this->option_link(t('Field @field (ID: @id)', array('@field' => $handler->ui_name(), '@id' => $id)), 'analyze-theme-field') . ': ' . $this->format_themes($handler->theme_functions());
  1742. }
  1743. }
  1744. }
  1745. $form['important'] = array(
  1746. '#markup' => '<div class="form-item description"><p>' . t('This section lists all possible templates for the display plugin and for the style plugins, ordered roughly from the least specific to the most specific. The active template for each plugin -- which is the most specific template found on the system -- is highlighted in bold.') . '</p></div>',
  1747. );
  1748. if (isset($this->view->display[$this->view->current_display]->new_id)) {
  1749. $form['important']['new_id'] = array(
  1750. '#prefix' => '<div class="description">',
  1751. '#suffix' => '</div>',
  1752. '#value' => t("<strong>Important!</strong> You have changed the display's machine name. Anything that attached to this display specifically, such as theming, may stop working until it is updated. To see theme suggestions for it, you need to save the view."),
  1753. );
  1754. }
  1755. foreach (list_themes() as $key => $theme) {
  1756. if (!empty($theme->info['hidden'])) {
  1757. continue;
  1758. }
  1759. $options[$key] = $theme->info['name'];
  1760. }
  1761. $form['box'] = array(
  1762. '#prefix' => '<div class="container-inline">',
  1763. '#suffix' => '</div>',
  1764. );
  1765. $form['box']['theme'] = array(
  1766. '#type' => 'select',
  1767. '#options' => $options,
  1768. '#default_value' => $this->theme,
  1769. );
  1770. $form['box']['change'] = array(
  1771. '#type' => 'submit',
  1772. '#value' => t('Change theme'),
  1773. '#submit' => array('views_ui_edit_display_form_change_theme'),
  1774. );
  1775. $form['analysis'] = array(
  1776. '#markup' => '<div class="form-item">' . theme('item_list', array('items' => $funcs)) . '</div>',
  1777. );
  1778. $form['rescan_button'] = array(
  1779. '#prefix' => '<div class="form-item">',
  1780. '#suffix' => '</div>',
  1781. );
  1782. $form['rescan_button']['button'] = array(
  1783. '#type' => 'submit',
  1784. '#value' => t('Rescan template files'),
  1785. '#submit' => array('views_ui_config_item_form_rescan'),
  1786. );
  1787. $form['rescan_button']['markup'] = array(
  1788. '#markup' => '<div class="description">' . t("<strong>Important!</strong> When adding, removing, or renaming template files, it is necessary to make Drupal aware of the changes by making it rescan the files on your system. By clicking this button you clear Drupal's theme registry and thereby trigger this rescanning process. The highlighted templates above will then reflect the new state of your system.") . '</div>',
  1789. );
  1790. $form_state['ok_button'] = TRUE;
  1791. break;
  1792. case 'analyze-theme-display':
  1793. $form['#title'] .= t('Theming information (display)');
  1794. $output = '<p>' . t('Back to !info.', array('!info' => $this->option_link(t('theming information'), 'analyze-theme'))) . '</p>';
  1795. if (empty($this->definition['theme'])) {
  1796. $output .= t('This display has no theming information');
  1797. }
  1798. else {
  1799. $output .= '<p>' . t('This is the default theme template used for this display.') . '</p>';
  1800. $output .= '<pre>' . check_plain(file_get_contents('./' . $this->definition['theme path'] . '/' . strtr($this->definition['theme'], '_', '-') . '.tpl.php')) . '</pre>';
  1801. }
  1802. if (!empty($this->definition['additional themes'])) {
  1803. foreach ($this->definition['additional themes'] as $theme => $type) {
  1804. $output .= '<p>' . t('This is an alternative template for this display.') . '</p>';
  1805. $output .= '<pre>' . check_plain(file_get_contents('./' . $this->definition['theme path'] . '/' . strtr($theme, '_', '-') . '.tpl.php')) . '</pre>';
  1806. }
  1807. }
  1808. $form['analysis'] = array(
  1809. '#markup' => '<div class="form-item">' . $output . '</div>',
  1810. );
  1811. $form_state['ok_button'] = TRUE;
  1812. break;
  1813. case 'analyze-theme-style':
  1814. $form['#title'] .= t('Theming information (style)');
  1815. $output = '<p>' . t('Back to !info.', array('!info' => $this->option_link(t('theming information'), 'analyze-theme'))) . '</p>';
  1816. $plugin = $this->get_plugin();
  1817. if (empty($plugin->definition['theme'])) {
  1818. $output .= t('This display has no style theming information');
  1819. }
  1820. else {
  1821. $output .= '<p>' . t('This is the default theme template used for this style.') . '</p>';
  1822. $output .= '<pre>' . check_plain(file_get_contents('./' . $plugin->definition['theme path'] . '/' . strtr($plugin->definition['theme'], '_', '-') . '.tpl.php')) . '</pre>';
  1823. }
  1824. if (!empty($plugin->definition['additional themes'])) {
  1825. foreach ($plugin->definition['additional themes'] as $theme => $type) {
  1826. $output .= '<p>' . t('This is an alternative template for this style.') . '</p>';
  1827. $output .= '<pre>' . check_plain(file_get_contents('./' . $plugin->definition['theme path'] . '/' . strtr($theme, '_', '-') . '.tpl.php')) . '</pre>';
  1828. }
  1829. }
  1830. $form['analysis'] = array(
  1831. '#markup' => '<div class="form-item">' . $output . '</div>',
  1832. );
  1833. $form_state['ok_button'] = TRUE;
  1834. break;
  1835. case 'analyze-theme-row':
  1836. $form['#title'] .= t('Theming information (row style)');
  1837. $output = '<p>' . t('Back to !info.', array('!info' => $this->option_link(t('theming information'), 'analyze-theme'))) . '</p>';
  1838. $plugin = $this->get_plugin('row');
  1839. if (empty($plugin->definition['theme'])) {
  1840. $output .= t('This display has no row style theming information');
  1841. }
  1842. else {
  1843. $output .= '<p>' . t('This is the default theme template used for this row style.') . '</p>';
  1844. $output .= '<pre>' . check_plain(file_get_contents('./' . $plugin->definition['theme path'] . '/' . strtr($plugin->definition['theme'], '_', '-') . '.tpl.php')) . '</pre>';
  1845. }
  1846. if (!empty($plugin->definition['additional themes'])) {
  1847. foreach ($plugin->definition['additional themes'] as $theme => $type) {
  1848. $output .= '<p>' . t('This is an alternative template for this row style.') . '</p>';
  1849. $output .= '<pre>' . check_plain(file_get_contents('./' . $plugin->definition['theme path'] . '/' . strtr($theme, '_', '-') . '.tpl.php')) . '</pre>';
  1850. }
  1851. }
  1852. $form['analysis'] = array(
  1853. '#markup' => '<div class="form-item">' . $output . '</div>',
  1854. );
  1855. $form_state['ok_button'] = TRUE;
  1856. break;
  1857. case 'analyze-theme-field':
  1858. $form['#title'] .= t('Theming information (row style)');
  1859. $output = '<p>' . t('Back to !info.', array('!info' => $this->option_link(t('theming information'), 'analyze-theme'))) . '</p>';
  1860. $output .= '<p>' . t('This is the default theme template used for this row style.') . '</p>';
  1861. // Field templates aren't registered the normal way...and they're always
  1862. // this one, anyhow.
  1863. $output .= '<pre>' . check_plain(file_get_contents(drupal_get_path('module', 'views') . '/theme/views-view-field.tpl.php')) . '</pre>';
  1864. $form['analysis'] = array(
  1865. '#markup' => '<div class="form-item">' . $output . '</div>',
  1866. );
  1867. $form_state['ok_button'] = TRUE;
  1868. break;
  1869. case 'exposed_block':
  1870. $form['#title'] .= t('Put the exposed form in a block');
  1871. $form['description'] = array(
  1872. '#markup' => '<div class="description form-item">' . t('If set, any exposed widgets will not appear with this view. Instead, a block will be made available to the Drupal block administration system, and the exposed form will appear there. Note that this block must be enabled manually, Views will not enable it for you.') . '</div>',
  1873. );
  1874. $form['exposed_block'] = array(
  1875. '#type' => 'radios',
  1876. '#options' => array(1 => t('Yes'), 0 => t('No')),
  1877. '#default_value' => $this->get_option('exposed_block') ? 1 : 0,
  1878. );
  1879. break;
  1880. case 'exposed_form':
  1881. $form['#title'] .= t('Exposed Form');
  1882. $form['exposed_form'] = array(
  1883. '#prefix' => '<div class="clearfix">',
  1884. '#suffix' => '</div>',
  1885. '#tree' => TRUE,
  1886. );
  1887. $exposed_form = $this->get_option('exposed_form');
  1888. $form['exposed_form']['type'] = array(
  1889. '#type' => 'radios',
  1890. '#options' => views_fetch_plugin_names('exposed_form', NULL, array($this->view->base_table)),
  1891. '#default_value' => $exposed_form['type'],
  1892. );
  1893. $exposed_form_plugin = views_fetch_plugin_data('exposed_form', $exposed_form['type']);
  1894. if (!empty($exposed_form_plugin['uses options'])) {
  1895. $form['markup'] = array(
  1896. '#prefix' => '<div class="form-item description">',
  1897. '#suffix' => '</div>',
  1898. '#markup' => t('You may also adjust the !settings for the currently selected style.', array('!settings' => $this->option_link(t('settings'), 'exposed_form_options'))),
  1899. );
  1900. }
  1901. break;
  1902. case 'exposed_form_options':
  1903. $plugin = $this->get_plugin('exposed_form');
  1904. $form['#title'] .= t('Exposed form options');
  1905. if ($plugin) {
  1906. $form['#help_topic'] = $plugin->definition['help topic'];
  1907. $form['exposed_form_options'] = array(
  1908. '#tree' => TRUE,
  1909. );
  1910. $plugin->options_form($form['exposed_form_options'], $form_state);
  1911. }
  1912. break;
  1913. case 'pager':
  1914. $form['#title'] .= t('Select which pager, if any, to use for this view');
  1915. $form['pager'] = array(
  1916. '#prefix' => '<div class="clearfix">',
  1917. '#suffix' => '</div>',
  1918. '#tree' => TRUE,
  1919. );
  1920. $pager = $this->get_option('pager');
  1921. $form['pager']['type'] = array(
  1922. '#type' => 'radios',
  1923. '#options' => views_fetch_plugin_names('pager', empty($this->definition['use pager']) ? 'basic' : NULL, array($this->view->base_table)),
  1924. '#default_value' => $pager['type'],
  1925. );
  1926. $pager_plugin = views_fetch_plugin_data('pager', $pager['type'], array($this->view->base_table));
  1927. if (!empty($pager_plugin['uses options'])) {
  1928. $form['markup'] = array(
  1929. '#prefix' => '<div class="form-item description">',
  1930. '#suffix' => '</div>',
  1931. '#markup' => t('You may also adjust the !settings for the currently selected pager.', array('!settings' => $this->option_link(t('settings'), 'pager_options'))),
  1932. );
  1933. }
  1934. break;
  1935. case 'pager_options':
  1936. $plugin = $this->get_plugin('pager');
  1937. $form['#title'] .= t('Pager options');
  1938. if ($plugin) {
  1939. $form['#help_topic'] = $plugin->definition['help topic'];
  1940. $form['pager_options'] = array(
  1941. '#tree' => TRUE,
  1942. );
  1943. $plugin->options_form($form['pager_options'], $form_state);
  1944. }
  1945. break;
  1946. }
  1947. foreach ($this->extender as $extender) {
  1948. $extender->options_form($form, $form_state);
  1949. }
  1950. }
  1951. /**
  1952. * Format a list of theme templates for output by the theme info helper.
  1953. */
  1954. function format_themes($themes) {
  1955. $registry = $this->theme_registry;
  1956. $extension = $this->theme_extension;
  1957. $output = '';
  1958. $picked = FALSE;
  1959. foreach ($themes as $theme) {
  1960. $template = strtr($theme, '_', '-') . $extension;
  1961. if (!$picked && !empty($registry[$theme])) {
  1962. $template_path = isset($registry[$theme]['path']) ? $registry[$theme]['path'] . '/' : './';
  1963. if (file_exists($template_path . $template)) {
  1964. $hint = t('File found in folder @template-path', array('@template-path' => $template_path));
  1965. $template = '<strong title="'. $hint .'">' . $template . '</strong>';
  1966. }
  1967. else {
  1968. $template = '<strong class="error">' . $template . ' ' . t('(File not found, in folder @template-path)', array('@template-path' => $template_path)) . '</strong>';
  1969. }
  1970. $picked = TRUE;
  1971. }
  1972. $fixed[] = $template;
  1973. }
  1974. return implode(', ', array_reverse($fixed));
  1975. }
  1976. /**
  1977. * Validate the options form.
  1978. */
  1979. function options_validate(&$form, &$form_state) {
  1980. switch ($form_state['section']) {
  1981. case 'display_title':
  1982. if (empty($form_state['values']['display_title'])) {
  1983. form_error($form['display_title'], t('Display title may not be empty.'));
  1984. }
  1985. break;
  1986. case 'css_class':
  1987. $css_class = $form_state['values']['css_class'];
  1988. if (preg_match('/[^a-zA-Z0-9-_ ]/', $css_class)) {
  1989. form_error($form['css_class'], t('CSS classes must be alphanumeric or dashes only.'));
  1990. }
  1991. break;
  1992. case 'display_id':
  1993. if ($form_state['values']['display_id']) {
  1994. if (preg_match('/[^a-z0-9_]/', $form_state['values']['display_id'])) {
  1995. form_error($form['display_id'], t('Display name must be letters, numbers, or underscores only.'));
  1996. }
  1997. foreach ($this->view->display as $id => $display) {
  1998. if ($id != $this->view->current_display && ($form_state['values']['display_id'] == $id || (isset($display->new_id) && $form_state['values']['display_id'] == $display->new_id))) {
  1999. form_error($form['display_id'], t('Display id should be unique.'));
  2000. }
  2001. }
  2002. }
  2003. break;
  2004. case 'style_options':
  2005. $style = TRUE;
  2006. case 'row_options':
  2007. // if row, $style will be empty.
  2008. $plugin = $this->get_plugin(empty($style) ? 'row' : 'style');
  2009. if ($plugin) {
  2010. $plugin->options_validate($form[$form_state['section']], $form_state);
  2011. }
  2012. break;
  2013. case 'access_options':
  2014. $plugin = $this->get_plugin('access');
  2015. if ($plugin) {
  2016. $plugin->options_validate($form['access_options'], $form_state);
  2017. }
  2018. break;
  2019. case 'query':
  2020. if ($this->view->query) {
  2021. $this->view->query->options_validate($form['query'], $form_state);
  2022. }
  2023. break;
  2024. case 'cache_options':
  2025. $plugin = $this->get_plugin('cache');
  2026. if ($plugin) {
  2027. $plugin->options_validate($form['cache_options'], $form_state);
  2028. }
  2029. break;
  2030. case 'exposed_form_options':
  2031. $plugin = $this->get_plugin('exposed_form');
  2032. if ($plugin) {
  2033. $plugin->options_validate($form['exposed_form_options'], $form_state);
  2034. }
  2035. break;
  2036. case 'pager_options':
  2037. $plugin = $this->get_plugin('pager');
  2038. if ($plugin) {
  2039. $plugin->options_validate($form['pager_options'], $form_state);
  2040. }
  2041. break;
  2042. }
  2043. foreach ($this->extender as $extender) {
  2044. $extender->options_validate($form, $form_state);
  2045. }
  2046. }
  2047. /**
  2048. * Perform any necessary changes to the form values prior to storage.
  2049. * There is no need for this function to actually store the data.
  2050. */
  2051. function options_submit(&$form, &$form_state) {
  2052. // Not sure I like this being here, but it seems (?) like a logical place.
  2053. $cache_plugin = $this->get_plugin('cache');
  2054. if ($cache_plugin) {
  2055. $cache_plugin->cache_flush();
  2056. }
  2057. $section = $form_state['section'];
  2058. switch ($section) {
  2059. case 'display_id':
  2060. if (isset($form_state['values']['display_id'])) {
  2061. $this->display->new_id = $form_state['values']['display_id'];
  2062. }
  2063. break;
  2064. case 'display_title':
  2065. $this->display->display_title = $form_state['values']['display_title'];
  2066. $this->set_option('display_description', $form_state['values']['display_description']);
  2067. break;
  2068. case 'access':
  2069. $access = $this->get_option('access');
  2070. if ($access['type'] != $form_state['values']['access']['type']) {
  2071. $plugin = views_get_plugin('access', $form_state['values']['access']['type']);
  2072. if ($plugin) {
  2073. $access = array('type' => $form_state['values']['access']['type']);
  2074. $this->set_option('access', $access);
  2075. if (!empty($plugin->definition['uses options'])) {
  2076. views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('access_options'));
  2077. }
  2078. }
  2079. }
  2080. break;
  2081. case 'access_options':
  2082. $plugin = views_get_plugin('access', $form_state['values'][$section]['type']);
  2083. if ($plugin) {
  2084. $plugin->options_submit($form['access_options'], $form_state);
  2085. $this->set_option('access', $form_state['values'][$section]);
  2086. }
  2087. break;
  2088. case 'cache':
  2089. $cache = $this->get_option('cache');
  2090. if ($cache['type'] != $form_state['values']['cache']['type']) {
  2091. $plugin = views_get_plugin('cache', $form_state['values']['cache']['type']);
  2092. if ($plugin) {
  2093. $cache = array('type' => $form_state['values']['cache']['type']);
  2094. $this->set_option('cache', $cache);
  2095. if (!empty($plugin->definition['uses options'])) {
  2096. views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('cache_options'));
  2097. }
  2098. }
  2099. }
  2100. break;
  2101. case 'cache_options':
  2102. $plugin = views_get_plugin('cache', $form_state['values'][$section]['type']);
  2103. if ($plugin) {
  2104. $plugin->options_submit($form['cache_options'], $form_state);
  2105. $this->set_option('cache', $form_state['values'][$section]);
  2106. }
  2107. break;
  2108. case 'query':
  2109. $plugin = $this->get_plugin('query');
  2110. if ($plugin) {
  2111. $plugin->options_submit($form['query']['options'], $form_state);
  2112. $this->set_option('query', $form_state['values'][$section]);
  2113. }
  2114. break;
  2115. case 'link_display':
  2116. $this->set_option('link_url', $form_state['values']['link_url']);
  2117. case 'title':
  2118. case 'css_class':
  2119. case 'display_comment':
  2120. $this->set_option($section, $form_state['values'][$section]);
  2121. break;
  2122. case 'field_language':
  2123. $this->set_option('field_language', $form_state['values']['field_language']);
  2124. $this->set_option('field_language_add_to_query', $form_state['values']['field_language_add_to_query']);
  2125. break;
  2126. case 'use_ajax':
  2127. case 'hide_attachment_summary':
  2128. case 'hide_admin_links':
  2129. $this->set_option($section, (bool)$form_state['values'][$section]);
  2130. break;
  2131. case 'use_more':
  2132. $this->set_option($section, intval($form_state['values'][$section]));
  2133. $this->set_option('use_more_always', !intval($form_state['values']['use_more_always']));
  2134. $this->set_option('use_more_text', $form_state['values']['use_more_text']);
  2135. case 'distinct':
  2136. $this->set_option($section, $form_state['values'][$section]);
  2137. break;
  2138. case 'group_by':
  2139. $this->set_option($section, $form_state['values'][$section]);
  2140. break;
  2141. case 'row_plugin':
  2142. // This if prevents resetting options to default if they don't change
  2143. // the plugin.
  2144. if ($this->get_option($section) != $form_state['values'][$section]) {
  2145. $plugin = views_get_plugin('row', $form_state['values'][$section]);
  2146. if ($plugin) {
  2147. $this->set_option($section, $form_state['values'][$section]);
  2148. $this->set_option('row_options', array());
  2149. // send ajax form to options page if we use it.
  2150. if (!empty($plugin->definition['uses options'])) {
  2151. views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('row_options'));
  2152. }
  2153. }
  2154. }
  2155. break;
  2156. case 'style_plugin':
  2157. // This if prevents resetting options to default if they don't change
  2158. // the plugin.
  2159. if ($this->get_option($section) != $form_state['values'][$section]) {
  2160. $plugin = views_get_plugin('style', $form_state['values'][$section]);
  2161. if ($plugin) {
  2162. $this->set_option($section, $form_state['values'][$section]);
  2163. $this->set_option('style_options', array());
  2164. // send ajax form to options page if we use it.
  2165. if (!empty($plugin->definition['uses options'])) {
  2166. views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('style_options'));
  2167. }
  2168. }
  2169. }
  2170. break;
  2171. case 'style_options':
  2172. $style = TRUE;
  2173. case 'row_options':
  2174. // if row, $style will be empty.
  2175. $plugin = $this->get_plugin(empty($style) ? 'row' : 'style');
  2176. if ($plugin) {
  2177. $plugin->options_submit($form['options'][$section], $form_state);
  2178. }
  2179. $this->set_option($section, $form_state['values'][$section]);
  2180. break;
  2181. case 'exposed_block':
  2182. $this->set_option($section, (bool) $form_state['values'][$section]);
  2183. break;
  2184. case 'exposed_form':
  2185. $exposed_form = $this->get_option('exposed_form');
  2186. if ($exposed_form['type'] != $form_state['values']['exposed_form']['type']) {
  2187. $plugin = views_get_plugin('exposed_form', $form_state['values']['exposed_form']['type']);
  2188. if ($plugin) {
  2189. $exposed_form = array('type' => $form_state['values']['exposed_form']['type'], 'options' => array());
  2190. $this->set_option('exposed_form', $exposed_form);
  2191. if (!empty($plugin->definition['uses options'])) {
  2192. views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('exposed_form_options'));
  2193. }
  2194. }
  2195. }
  2196. break;
  2197. case 'exposed_form_options':
  2198. $plugin = $this->get_plugin('exposed_form');
  2199. if ($plugin) {
  2200. $exposed_form = $this->get_option('exposed_form');
  2201. $plugin->options_submit($form['exposed_form_options'], $form_state);
  2202. $exposed_form['options'] = $form_state['values'][$section];
  2203. $this->set_option('exposed_form', $exposed_form);
  2204. }
  2205. break;
  2206. case 'pager':
  2207. $pager = $this->get_option('pager');
  2208. if ($pager['type'] != $form_state['values']['pager']['type']) {
  2209. $plugin = views_get_plugin('pager', $form_state['values']['pager']['type']);
  2210. if ($plugin) {
  2211. // Because pagers have very similar options, let's allow pagers to
  2212. // try to carry the options over.
  2213. $plugin->init($this->view, $this->display, $pager['options']);
  2214. $pager = array('type' => $form_state['values']['pager']['type'], 'options' => $plugin->options);
  2215. $this->set_option('pager', $pager);
  2216. if (!empty($plugin->definition['uses options'])) {
  2217. views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('pager_options'));
  2218. }
  2219. }
  2220. }
  2221. break;
  2222. case 'pager_options':
  2223. $plugin = $this->get_plugin('pager');
  2224. if ($plugin) {
  2225. $pager = $this->get_option('pager');
  2226. $plugin->options_submit($form['pager_options'], $form_state);
  2227. $pager['options'] = $form_state['values'][$section];
  2228. $this->set_option('pager', $pager);
  2229. }
  2230. break;
  2231. }
  2232. foreach ($this->extender as $extender) {
  2233. $extender->options_submit($form, $form_state);
  2234. }
  2235. }
  2236. /**
  2237. * If override/revert was clicked, perform the proper toggle.
  2238. */
  2239. function options_override($form, &$form_state) {
  2240. $this->set_override($form_state['section']);
  2241. }
  2242. /**
  2243. * Flip the override setting for the given section.
  2244. *
  2245. * @param string $section
  2246. * Which option should be marked as overridden, for example "filters".
  2247. * @param bool $new_state
  2248. * Select the new state of the option.
  2249. * - TRUE: Revert to default.
  2250. * - FALSE: Mark it as overridden.
  2251. */
  2252. function set_override($section, $new_state = NULL) {
  2253. $options = $this->defaultable_sections($section);
  2254. if (!$options) {
  2255. return;
  2256. }
  2257. if (!isset($new_state)) {
  2258. $new_state = empty($this->options['defaults'][$section]);
  2259. }
  2260. // For each option that is part of this group, fix our settings.
  2261. foreach ($options as $option) {
  2262. if ($new_state) {
  2263. // Revert to defaults.
  2264. unset($this->options[$option]);
  2265. unset($this->display->display_options[$option]);
  2266. }
  2267. else {
  2268. // copy existing values into our display.
  2269. $this->options[$option] = $this->get_option($option);
  2270. $this->display->display_options[$option] = $this->options[$option];
  2271. }
  2272. $this->options['defaults'][$option] = $new_state;
  2273. $this->display->display_options['defaults'][$option] = $new_state;
  2274. }
  2275. }
  2276. /**
  2277. * Inject anything into the query that the display handler needs.
  2278. */
  2279. function query() {
  2280. foreach ($this->extender as $extender) {
  2281. $extender->query();
  2282. }
  2283. }
  2284. /**
  2285. * Not all display plugins will support filtering
  2286. */
  2287. function render_filters() { }
  2288. /**
  2289. * Not all display plugins will suppert pager rendering.
  2290. */
  2291. function render_pager() {
  2292. return TRUE;
  2293. }
  2294. /**
  2295. * Render the 'more' link
  2296. */
  2297. function render_more_link() {
  2298. if ($this->use_more() && ($this->use_more_always() || (!empty($this->view->query->pager) && $this->view->query->pager->has_more_records()))) {
  2299. $path = $this->get_path();
  2300. if ($this->get_option('link_display') == 'custom_url' && $override_path = $this->get_option('link_url')) {
  2301. $tokens = $this->get_arguments_tokens();
  2302. $path = strtr($override_path, $tokens);
  2303. }
  2304. if ($path) {
  2305. if (empty($override_path)) {
  2306. $path = $this->view->get_url(NULL, $path);
  2307. }
  2308. $url_options = array();
  2309. if (!empty($this->view->exposed_raw_input)) {
  2310. $url_options['query'] = $this->view->exposed_raw_input;
  2311. }
  2312. $theme = views_theme_functions('views_more', $this->view, $this->display);
  2313. $path = check_url(url($path, $url_options));
  2314. return theme($theme, array('more_url' => $path, 'link_text' => check_plain($this->use_more_text()), 'view' => $this->view));
  2315. }
  2316. }
  2317. }
  2318. /**
  2319. * Legacy functions.
  2320. */
  2321. /**
  2322. * Render the header of the view.
  2323. */
  2324. function render_header() {
  2325. $empty = !empty($this->view->result);
  2326. return $this->render_area('header', $empty);
  2327. }
  2328. /**
  2329. * Render the footer of the view.
  2330. */
  2331. function render_footer() {
  2332. $empty = !empty($this->view->result);
  2333. return $this->render_area('footer', $empty);
  2334. }
  2335. function render_empty() {
  2336. return $this->render_area('empty');
  2337. }
  2338. /**
  2339. * If this display creates a block, implement one of these.
  2340. */
  2341. function hook_block_list($delta = 0, $edit = array()) { return array(); }
  2342. /**
  2343. * If this display creates a page with a menu item, implement it here.
  2344. */
  2345. function hook_menu() { return array(); }
  2346. /**
  2347. * Render this display.
  2348. */
  2349. function render() {
  2350. return theme($this->theme_functions(), array('view' => $this->view));
  2351. }
  2352. function render_area($area, $empty = FALSE) {
  2353. $return = '';
  2354. foreach ($this->get_handlers($area) as $area) {
  2355. $return .= $area->render($empty);
  2356. }
  2357. return $return;
  2358. }
  2359. /**
  2360. * Determine if the user has access to this display of the view.
  2361. */
  2362. function access($account = NULL) {
  2363. if (!isset($account)) {
  2364. global $user;
  2365. $account = $user;
  2366. }
  2367. // Full override.
  2368. if (user_access('access all views', $account)) {
  2369. return TRUE;
  2370. }
  2371. $plugin = $this->get_plugin('access');
  2372. if ($plugin) {
  2373. return $plugin->access($account);
  2374. }
  2375. // fallback to all access if no plugin.
  2376. return TRUE;
  2377. }
  2378. /**
  2379. * Set up any variables on the view prior to execution. These are separated
  2380. * from execute because they are extremely common and unlikely to be
  2381. * overridden on an individual display.
  2382. */
  2383. function pre_execute() {
  2384. $this->view->set_use_ajax($this->use_ajax());
  2385. if ($this->use_more() && !$this->use_more_always()) {
  2386. $this->view->get_total_rows = TRUE;
  2387. }
  2388. $this->view->init_handlers();
  2389. if ($this->uses_exposed()) {
  2390. $exposed_form = $this->get_plugin('exposed_form');
  2391. $exposed_form->pre_execute();
  2392. }
  2393. foreach ($this->extender as $extender) {
  2394. $extender->pre_execute();
  2395. }
  2396. if ($this->get_option('hide_admin_links')) {
  2397. $this->view->hide_admin_links = TRUE;
  2398. }
  2399. }
  2400. /**
  2401. * When used externally, this is how a view gets run and returns
  2402. * data in the format required.
  2403. *
  2404. * The base class cannot be executed.
  2405. */
  2406. function execute() { }
  2407. /**
  2408. * Fully render the display for the purposes of a live preview or
  2409. * some other AJAXy reason.
  2410. */
  2411. function preview() { return $this->view->render(); }
  2412. /**
  2413. * Displays can require a certain type of style plugin. By default, they will
  2414. * be 'normal'.
  2415. */
  2416. function get_style_type() { return 'normal'; }
  2417. /**
  2418. * Make sure the display and all associated handlers are valid.
  2419. *
  2420. * @return
  2421. * Empty array if the display is valid; an array of error strings if it is not.
  2422. */
  2423. function validate() {
  2424. $errors = array();
  2425. // Make sure displays that use fields HAVE fields.
  2426. if ($this->uses_fields()) {
  2427. $fields = FALSE;
  2428. foreach ($this->get_handlers('field') as $field) {
  2429. if (empty($field->options['exclude'])) {
  2430. $fields = TRUE;
  2431. }
  2432. }
  2433. if (!$fields) {
  2434. $errors[] = t('Display "@display" uses fields but there are none defined for it or all are excluded.', array('@display' => $this->display->display_title));
  2435. }
  2436. }
  2437. if ($this->has_path() && !$this->get_option('path')) {
  2438. $errors[] = t('Display "@display" uses a path but the path is undefined.', array('@display' => $this->display->display_title));
  2439. }
  2440. // Validate style plugin
  2441. $style = $this->get_plugin();
  2442. if (empty($style)) {
  2443. $errors[] = t('Display "@display" has an invalid style plugin.', array('@display' => $this->display->display_title));
  2444. }
  2445. else {
  2446. $result = $style->validate();
  2447. if (!empty($result) && is_array($result)) {
  2448. $errors = array_merge($errors, $result);
  2449. }
  2450. }
  2451. // Validate query plugin.
  2452. $query = $this->get_plugin('query');
  2453. $result = $query->validate();
  2454. if (!empty($result) && is_array($result)) {
  2455. $errors = array_merge($errors, $result);
  2456. }
  2457. // Validate handlers
  2458. foreach (views_object_types() as $type => $info) {
  2459. foreach ($this->get_handlers($type) as $handler) {
  2460. $result = $handler->validate();
  2461. if (!empty($result) && is_array($result)) {
  2462. $errors = array_merge($errors, $result);
  2463. }
  2464. }
  2465. }
  2466. return $errors;
  2467. }
  2468. /**
  2469. * Check if the provided identifier is unique.
  2470. *
  2471. * @param string $id
  2472. * The id of the handler which is checked.
  2473. * @param string $identifier
  2474. * The actual get identifier configured in the exposed settings.
  2475. *
  2476. * @return bool
  2477. * Returns whether the identifier is unique on all handlers.
  2478. *
  2479. */
  2480. function is_identifier_unique($id, $identifier) {
  2481. foreach (views_object_types() as $type => $info) {
  2482. foreach ($this->get_handlers($type) as $key => $handler) {
  2483. if ($handler->can_expose() && $handler->is_exposed()) {
  2484. if ($handler->is_a_group()) {
  2485. if ($id != $key && $identifier == $handler->options['group_info']['identifier']) {
  2486. return FALSE;
  2487. }
  2488. }
  2489. else {
  2490. if ($id != $key && $identifier == $handler->options['expose']['identifier']) {
  2491. return FALSE;
  2492. }
  2493. }
  2494. }
  2495. }
  2496. }
  2497. return TRUE;
  2498. }
  2499. /**
  2500. * Provide the block system with any exposed widget blocks for this display.
  2501. */
  2502. function get_special_blocks() {
  2503. $blocks = array();
  2504. if ($this->uses_exposed_form_in_block()) {
  2505. $delta = '-exp-' . $this->view->name . '-' . $this->display->id;
  2506. $desc = t('Exposed form: @view-@display_id', array('@view' => $this->view->name, '@display_id' => $this->display->id));
  2507. $blocks[$delta] = array(
  2508. 'info' => $desc,
  2509. 'cache' => DRUPAL_NO_CACHE,
  2510. );
  2511. }
  2512. return $blocks;
  2513. }
  2514. /**
  2515. * Render any special blocks provided for this display.
  2516. */
  2517. function view_special_blocks($type) {
  2518. if ($type == '-exp') {
  2519. // avoid interfering with the admin forms.
  2520. if (arg(0) == 'admin' && arg(1) == 'structure' && arg(2) == 'views') {
  2521. return;
  2522. }
  2523. $this->view->init_handlers();
  2524. if ($this->uses_exposed() && $this->get_option('exposed_block')) {
  2525. $exposed_form = $this->get_plugin('exposed_form');
  2526. return array(
  2527. 'content' => $exposed_form->render_exposed_form(TRUE),
  2528. );
  2529. }
  2530. }
  2531. }
  2532. /**
  2533. * Override of export_option()
  2534. *
  2535. * Because displays do not want to export options that are NOT overridden from the
  2536. * default display, we need some special handling during the export process.
  2537. */
  2538. function export_option($indent, $prefix, $storage, $option, $definition, $parents) {
  2539. // The $prefix is wrong because we store our actual options a little differently:
  2540. $prefix = '$handler->display->display_options';
  2541. $output = '';
  2542. if (!$parents && !$this->is_default_display()) {
  2543. // Do not export items that are not overridden.
  2544. if ($this->is_defaulted($option)) {
  2545. return;
  2546. }
  2547. // If this is not defaulted and is overrideable, flip the switch to say this
  2548. // is overridden.
  2549. if ($this->defaultable_sections($option)) {
  2550. $output .= $indent . $prefix . "['defaults']['$option'] = FALSE;\n";
  2551. }
  2552. }
  2553. $output .= parent::export_option($indent, $prefix, $storage, $option, $definition, $parents);
  2554. return $output;
  2555. }
  2556. /**
  2557. * Special method to export items that have handlers.
  2558. *
  2559. * This method was specified in the option_definition() as the method to utilize to
  2560. * export fields, filters, sort criteria, relationships and arguments. This passes
  2561. * the export off to the individual handlers so that they can export themselves
  2562. * properly.
  2563. */
  2564. function export_handler($indent, $prefix, $storage, $option, $definition, $parents) {
  2565. $output = '';
  2566. // cut the 's' off because the data is stored as the plural form but we need
  2567. // the singular form. Who designed that anyway? Oh yeah, I did. :(
  2568. if ($option != 'header' && $option != 'footer' && $option != 'empty') {
  2569. $type = substr($option, 0, -1);
  2570. }
  2571. else {
  2572. $type = $option;
  2573. }
  2574. $types = views_object_types();
  2575. foreach ($storage[$option] as $id => $info) {
  2576. if (!empty($types[$type]['type'])) {
  2577. $handler_type = $types[$type]['type'];
  2578. }
  2579. else {
  2580. $handler_type = $type;
  2581. }
  2582. // If aggregation is on, the group type might override the actual
  2583. // handler that is in use. This piece of code checks that and,
  2584. // if necessary, sets the override handler.
  2585. $override = NULL;
  2586. if ($this->use_group_by() && !empty($info['group_type'])) {
  2587. if (empty($this->view->query)) {
  2588. $this->view->init_query();
  2589. }
  2590. $aggregate = $this->view->query->get_aggregation_info();
  2591. if (!empty($aggregate[$info['group_type']]['handler'][$type])) {
  2592. $override = $aggregate[$info['group_type']]['handler'][$type];
  2593. }
  2594. }
  2595. $handler = views_get_handler($info['table'], $info['field'], $handler_type, $override);
  2596. if ($handler) {
  2597. $handler->init($this->view, $info);
  2598. $output .= $indent . '/* ' . $types[$type]['stitle'] . ': ' . $handler->ui_name() . " */\n";
  2599. $output .= $handler->export_options($indent, $prefix . "['$option']['$id']");
  2600. }
  2601. // Prevent reference problems.
  2602. unset($handler);
  2603. }
  2604. return $output;
  2605. }
  2606. /**
  2607. * Special handling for the style export.
  2608. *
  2609. * Styles are stored as style_plugin and style_options or row_plugin and
  2610. * row_options accordingly. The options are told not to export, and the
  2611. * export for the plugin should export both.
  2612. */
  2613. function export_style($indent, $prefix, $storage, $option, $definition, $parents) {
  2614. $output = '';
  2615. $style_plugin = $this->get_plugin();
  2616. if ($option == 'style_plugin') {
  2617. $type = 'style';
  2618. $options_field = 'style_options';
  2619. $plugin = $style_plugin;
  2620. }
  2621. else {
  2622. if (!$style_plugin || !$style_plugin->uses_row_plugin()) {
  2623. return;
  2624. }
  2625. $type = 'row';
  2626. $options_field = 'row_options';
  2627. $plugin = $this->get_plugin('row');
  2628. // If the style plugin doesn't use row plugins, don't even bother.
  2629. }
  2630. if ($plugin) {
  2631. // Write which plugin to use.
  2632. $value = $this->get_option($option);
  2633. $output .= $indent . $prefix . "['$option'] = '$value';\n";
  2634. // Pass off to the plugin to export itself.
  2635. $output .= $plugin->export_options($indent, $prefix . "['$options_field']");
  2636. }
  2637. return $output;
  2638. }
  2639. /**
  2640. * Special handling for plugin export
  2641. *
  2642. * Plugins other than styles are stored in array with 'type' being the key
  2643. * to the plugin. For modern plugins, the options are stored in the 'options'
  2644. * array, but for legacy plugins (access and cache) options are stored as
  2645. * siblings to the type.
  2646. */
  2647. function export_plugin($indent, $prefix, $storage, $option, $definition, $parents) {
  2648. $output = '';
  2649. $plugin_type = end($parents);
  2650. $plugin = $this->get_plugin($plugin_type);
  2651. if ($plugin) {
  2652. // Write which plugin to use.
  2653. $value = $storage[$option];
  2654. $new_prefix = $prefix . "['$plugin_type']";
  2655. $output .= $indent . $new_prefix . "['$option'] = '$value';\n";
  2656. if ($plugin_type != 'access' && $plugin_type!= 'cache') {
  2657. $new_prefix .= "['options']";
  2658. }
  2659. // Pass off to the plugin to export itself.
  2660. $output .= $plugin->export_options($indent, $new_prefix);
  2661. }
  2662. return $output;
  2663. }
  2664. function unpack_style($indent, $prefix, $storage, $option, $definition, $parents) {
  2665. $output = '';
  2666. $style_plugin = $this->get_plugin();
  2667. if ($option == 'style_plugin') {
  2668. $type = 'style';
  2669. $options_field = 'style_options';
  2670. $plugin = $style_plugin;
  2671. }
  2672. else {
  2673. if (!$style_plugin || !$style_plugin->uses_row_plugin()) {
  2674. return;
  2675. }
  2676. $type = 'row';
  2677. $options_field = 'row_options';
  2678. $plugin = $this->get_plugin('row');
  2679. // If the style plugin doesn't use row plugins, don't even bother.
  2680. }
  2681. if ($plugin) {
  2682. return $plugin->unpack_translatables($translatable, $parents);
  2683. }
  2684. }
  2685. /**
  2686. * Special handling for plugin unpacking.
  2687. */
  2688. function unpack_plugin(&$translatable, $storage, $option, $definition, $parents) {
  2689. $plugin_type = end($parents);
  2690. $plugin = $this->get_plugin($plugin_type);
  2691. if ($plugin) {
  2692. // Write which plugin to use.
  2693. return $plugin->unpack_translatables($translatable, $parents);
  2694. }
  2695. }
  2696. /**
  2697. * Special method to unpack items that have handlers.
  2698. *
  2699. * This method was specified in the option_definition() as the method to utilize to
  2700. * export fields, filters, sort criteria, relationships and arguments. This passes
  2701. * the export off to the individual handlers so that they can export themselves
  2702. * properly.
  2703. */
  2704. function unpack_handler(&$translatable, $storage, $option, $definition, $parents) {
  2705. $output = '';
  2706. // cut the 's' off because the data is stored as the plural form but we need
  2707. // the singular form. Who designed that anyway? Oh yeah, I did. :(
  2708. if ($option != 'header' && $option != 'footer' && $option != 'empty') {
  2709. $type = substr($option, 0, -1);
  2710. }
  2711. else {
  2712. $type = $option;
  2713. }
  2714. $types = views_object_types();
  2715. foreach ($storage[$option] as $id => $info) {
  2716. if (!empty($types[$type]['type'])) {
  2717. $handler_type = $types[$type]['type'];
  2718. }
  2719. else {
  2720. $handler_type = $type;
  2721. }
  2722. $handler = views_get_handler($info['table'], $info['field'], $handler_type);
  2723. if ($handler) {
  2724. $handler->init($this->view, $info);
  2725. $handler->unpack_translatables($translatable, array_merge($parents, array($type, $info['table'], $info['id'])));
  2726. }
  2727. // Prevent reference problems.
  2728. unset($handler);
  2729. }
  2730. return $output;
  2731. }
  2732. /**
  2733. * Provide some helpful text for the arguments.
  2734. * The result should contain of an array with
  2735. * - filter value present: The title of the fieldset in the argument
  2736. * where you can configure what should be done with a given argument.
  2737. * - filter value not present: The tiel of the fieldset in the argument
  2738. * where you can configure what should be done if the argument does not
  2739. * exist.
  2740. * - description: A description about how arguments comes to the display.
  2741. * For example blocks don't get it from url.
  2742. */
  2743. function get_argument_text() {
  2744. return array(
  2745. 'filter value not present' => t('When the filter value is <em>NOT</em> available'),
  2746. 'filter value present' => t('When the filter value <em>IS</em> available or a default is provided'),
  2747. 'description' => t("This display does not have a source for contextual filters, so no contextual filter value will be available unless you select 'Provide default'."),
  2748. );
  2749. }
  2750. /**
  2751. * Provide some helpful text for pagers.
  2752. *
  2753. * The result should contain of an array within
  2754. * - items per page title
  2755. */
  2756. function get_pager_text() {
  2757. return array(
  2758. 'items per page title' => t('Items to display'),
  2759. 'items per page description' => t('The number of items to display. Enter 0 for no limit.')
  2760. );
  2761. }
  2762. }
  2763. /**
  2764. * @}
  2765. */
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.