panels_renderer_editor.class.php 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071
  1. <?php
  2. /**
  3. * @file
  4. * Class file to control the main Panels editor.
  5. */
  6. class panels_renderer_editor extends panels_renderer_standard {
  7. /**
  8. * An array of AJAX commands to return. If populated it will automatically
  9. * be used by the AJAX router.
  10. */
  11. var $commands = array();
  12. var $admin = TRUE;
  13. /**
  14. * Set to true if edit links (for panes and regions) should not be displayed.
  15. * This can be used for special edit modes such as layout change and layout
  16. * builder that do not actually have real content.
  17. */
  18. var $no_edit_links = FALSE;
  19. // -------------------------------------------------------------------------.
  20. /**
  21. * Display edit rendering.
  22. */
  23. function edit() {
  24. $form_state = array(
  25. 'display' => &$this->display,
  26. 'renderer' => &$this,
  27. 'content_types' => $this->cache->content_types,
  28. 'no_redirect' => TRUE,
  29. 'display_title' => !empty($this->cache->display_title),
  30. 'cache key' => $this->display->cache_key,
  31. );
  32. $output = drupal_build_form('panels_edit_display_form', $form_state);
  33. if (empty($form_state['executed']) || !empty($form_state['clicked_button']['preview'])) {
  34. return $output;
  35. }
  36. if (!empty($form_state['clicked_button']['#save-display'])) {
  37. drupal_set_message(t('Panel content has been updated.'));
  38. panels_save_display($this->display);
  39. }
  40. else {
  41. drupal_set_message(t('Your changes have been discarded.'));
  42. }
  43. panels_cache_clear('display', $this->display->did);
  44. return $this->display;
  45. }
  46. function add_meta() {
  47. parent::add_meta();
  48. if ($this->admin) {
  49. ctools_include('ajax');
  50. ctools_include('modal');
  51. ctools_modal_add_js();
  52. ctools_add_js('panels-base', 'panels');
  53. ctools_add_js('display_editor', 'panels');
  54. ctools_add_css('panels_dnd', 'panels');
  55. ctools_add_css('panels_admin', 'panels');
  56. drupal_add_library('system', 'ui');
  57. }
  58. }
  59. function render() {
  60. // Pass through to normal rendering if not in admin mode.
  61. if (!$this->admin) {
  62. return parent::render();
  63. }
  64. $this->add_meta();
  65. $output = '<div class="panels-dnd" id="panels-dnd-main">';
  66. $output .= $this->render_layout();
  67. $output .= '</div>';
  68. return $output;
  69. }
  70. function render_region($region_id, $panes) {
  71. // Pass through to normal rendering if not in admin mode.
  72. if (!$this->admin) {
  73. return parent::render_region($region_id, $panes);
  74. }
  75. $content = implode('', $panes);
  76. $panel_buttons = $this->get_region_links($region_id);
  77. $output = "<div class='panel-region' id='panel-region-$region_id'>";
  78. $output .= $panel_buttons;
  79. $output .= "<h2 class='label'>" . check_plain($this->plugins['layout']['regions'][$region_id]) . "</h2>";
  80. $output .= $content;
  81. $output .= "</div>";
  82. return $output;
  83. }
  84. function render_pane(&$pane) {
  85. // Pass through to normal rendering if not in admin mode.
  86. if (!$this->admin) {
  87. return parent::render_pane($pane);
  88. }
  89. ctools_include('content');
  90. $content_type = ctools_get_content_type($pane->type);
  91. // This is just used for the title bar of the pane, not the content itself.
  92. // If we know the content type, use the appropriate title for that type,
  93. // otherwise, set the title using the content itself.
  94. $title = ctools_content_admin_title($content_type, $pane->subtype, $pane->configuration, $this->display->context);
  95. if (!$title) {
  96. $title = t('Deleted/missing content type @type', array('@type' => $pane->type));
  97. }
  98. $buttons = $this->get_pane_links($pane, $content_type);
  99. // Render administrative buttons for the pane.
  100. $block = new stdClass();
  101. if (empty($content_type)) {
  102. $block->title = '<em>' . t('Missing content type') . '</em>';
  103. $block->content = t('This pane\'s content type is either missing or has been deleted. This pane will not render.');
  104. }
  105. else {
  106. $block = ctools_content_admin_info($content_type, $pane->subtype, $pane->configuration, $this->display->context);
  107. }
  108. $grabber_class = 'grab-title grabber';
  109. // If there are region locks, add them.
  110. if (!empty($pane->locks['type'])) {
  111. if ($pane->locks['type'] == 'regions') {
  112. $settings['Panels']['RegionLock'][$pane->pid] = $pane->locks['regions'];
  113. drupal_add_js($settings, 'setting');
  114. }
  115. elseif ($pane->locks['type'] == 'immovable') {
  116. $grabber_class = 'grab-title not-grabber';
  117. }
  118. }
  119. $output = '';
  120. $class = 'panel-pane';
  121. if (empty($pane->shown)) {
  122. $class .= ' hidden-pane';
  123. }
  124. if (isset($this->display->title_pane) && $this->display->title_pane == $pane->pid) {
  125. $class .= ' panel-pane-is-title';
  126. }
  127. $output = '<div class="' . $class . '" id="panel-pane-' . $pane->pid . '">';
  128. if (empty($block->title)) {
  129. $block->title = t('No title');
  130. }
  131. $output .= '<div class="' . $grabber_class . '">';
  132. if ($buttons) {
  133. $output .= '<span class="buttons">' . $buttons . '</span>';
  134. }
  135. $output .= '<span class="text" title="' . check_plain($title) . '">' . $title . '</span>';
  136. $output .= '</div>';
  137. // Grabber.
  138. $output .= '<div class="panel-pane-collapsible">';
  139. $output .= '<div class="pane-title">' . $block->title . '</div>';
  140. $output .= '<div class="pane-content">' . filter_xss_admin(render($block->content)) . '</div>';
  141. $output .= '</div>';
  142. // panel-pane-collapsible.
  143. $output .= '</div>';
  144. // panel-pane.
  145. return $output;
  146. }
  147. /**
  148. * Get the style links.
  149. *
  150. * This is abstracted out since we have styles on both panes and regions.
  151. */
  152. function get_style_links($type, $id = NULL) {
  153. $info = $this->get_style($type, $id);
  154. $style = $info[0];
  155. $conf = $info[1];
  156. $style_title = isset($style['title']) ? $style['title'] : t('Default');
  157. $style_links['title'] = array(
  158. 'title' => $style_title,
  159. 'attributes' => array('class' => array('panels-text')),
  160. );
  161. $style_links['change'] = array(
  162. 'title' => t('Change'),
  163. 'href' => $this->get_url('style-type', $type, $id),
  164. 'attributes' => array('class' => array('ctools-use-modal')),
  165. );
  166. $function = $type != 'pane' ? 'settings form' : 'pane settings form';
  167. if (panels_plugin_get_function('styles', $style, $function)) {
  168. $style_links['settings'] = array(
  169. 'title' => t('Settings'),
  170. 'href' => $this->get_url('style-settings', $type, $id),
  171. 'attributes' => array('class' => array('ctools-use-modal')),
  172. );
  173. }
  174. return $style_links;
  175. }
  176. /**
  177. * Get the links for a panel display.
  178. *
  179. * This is abstracted out for easy ajax replacement.
  180. */
  181. function get_display_links() {
  182. $links = array();
  183. if (user_access('administer panels display styles')) {
  184. $style_links = $this->get_style_links('display');
  185. $links[] = array(
  186. 'title' => '<span class="dropdown-header">' . t('Style') . '</span>' . theme_links(array('links' => $style_links, 'attributes' => array(), 'heading' => array())),
  187. 'html' => TRUE,
  188. 'attributes' => array('class' => array('panels-sub-menu')),
  189. );
  190. }
  191. if (user_access('use panels caching features')) {
  192. $links[] = array(
  193. 'title' => '<hr />',
  194. 'html' => TRUE,
  195. );
  196. $method = isset($this->display->cache['method']) ? $this->display->cache['method'] : 0;
  197. $info = panels_get_cache($method);
  198. $cache_method = isset($info['title']) ? $info['title'] : t('No caching');
  199. $cache_links[] = array(
  200. 'title' => $cache_method,
  201. 'attributes' => array('class' => array('panels-text')),
  202. );
  203. $cache_links[] = array(
  204. 'title' => t('Change'),
  205. 'href' => $this->get_url('cache-method', 'display'),
  206. 'attributes' => array('class' => array('ctools-use-modal')),
  207. );
  208. if (panels_plugin_get_function('cache', $info, 'settings form')) {
  209. $cache_links[] = array(
  210. 'title' => t('Settings'),
  211. 'href' => $this->get_url('cache-settings', 'display'),
  212. 'attributes' => array('class' => array('ctools-use-modal')),
  213. );
  214. }
  215. $links[] = array(
  216. 'title' => '<span class="dropdown-header">' . t('Caching') . '</span>' . theme_links(array('links' => $cache_links, 'attributes' => array(), 'heading' => array())),
  217. 'html' => TRUE,
  218. 'attributes' => array('class' => array('panels-sub-menu')),
  219. );
  220. }
  221. return theme('ctools_dropdown', array('title' => t('Display settings'), 'links' => $links, 'class' => 'panels-display-links'));
  222. }
  223. /**
  224. * Render the links to display when editing a region.
  225. */
  226. function get_region_links($region_id) {
  227. if (!empty($this->no_edit_links)) {
  228. return '';
  229. }
  230. $links = array();
  231. $links[] = array(
  232. 'title' => t('Add content'),
  233. 'href' => $this->get_url('select-content', $region_id),
  234. 'attributes' => array(
  235. 'class' => array('ctools-use-modal'),
  236. ),
  237. );
  238. if (user_access('administer panels region styles')) {
  239. $links[] = array(
  240. 'title' => '<hr />',
  241. 'html' => TRUE,
  242. );
  243. $style_links = $this->get_style_links('region', $region_id);
  244. $links[] = array(
  245. 'title' => '<span class="dropdown-header">' . t('Style') . '</span>' . theme_links(array('links' => $style_links, 'attributes' => array(), 'heading' => array())),
  246. 'html' => TRUE,
  247. 'attributes' => array('class' => array('panels-sub-menu')),
  248. );
  249. }
  250. return theme('ctools_dropdown', array('title' => theme('image', array('path' => ctools_image_path('icon-addcontent.png', 'panels'))), 'links' => $links, 'image' => TRUE, 'class' => 'pane-add-link panels-region-links-' . $region_id));
  251. }
  252. /**
  253. * Render the links to display when editing a pane.
  254. */
  255. function get_pane_links($pane, $content_type) {
  256. if (!empty($this->no_edit_links)) {
  257. return '';
  258. }
  259. $links = array();
  260. if (!empty($pane->shown)) {
  261. $links['top']['disabled'] = array(
  262. 'title' => t('Disable this pane'),
  263. 'href' => $this->get_url('hide', $pane->pid),
  264. 'attributes' => array('class' => array('use-ajax')),
  265. );
  266. }
  267. else {
  268. $links['top']['enable'] = array(
  269. 'title' => t('Enable this pane'),
  270. 'href' => $this->get_url('show', $pane->pid),
  271. 'attributes' => array('class' => array('use-ajax')),
  272. );
  273. }
  274. if (isset($this->display->title_pane) && $this->display->title_pane == $pane->pid) {
  275. $links['top']['panels-set-title'] = array(
  276. 'title' => t('&#x2713;Panel title'),
  277. 'html' => TRUE,
  278. );
  279. }
  280. else {
  281. $links['top']['panels-set-title'] = array(
  282. 'title' => t('Panel title'),
  283. 'href' => $this->get_url('panel-title', $pane->pid),
  284. 'attributes' => array('class' => array('use-ajax')),
  285. );
  286. }
  287. $subtype = ctools_content_get_subtype($content_type, $pane->subtype);
  288. if (ctools_content_editable($content_type, $subtype, $pane->configuration)) {
  289. $links['top']['settings'] = array(
  290. 'title' => isset($content_type['edit text']) ? $content_type['edit text'] : t('Settings'),
  291. 'href' => $this->get_url('edit-pane', $pane->pid),
  292. 'attributes' => array('class' => array('ctools-use-modal')),
  293. );
  294. }
  295. if (user_access('administer advanced pane settings')) {
  296. $links['top']['css'] = array(
  297. 'title' => t('CSS properties'),
  298. 'href' => $this->get_url('pane-css', $pane->pid),
  299. 'attributes' => array('class' => array('ctools-use-modal')),
  300. );
  301. }
  302. if (user_access('administer panels styles')) {
  303. $links['style'] = $this->get_style_links('pane', $pane->pid);
  304. }
  305. if (user_access('administer pane access')) {
  306. $contexts = $this->display->context;
  307. // Make sure we have the logged in user context.
  308. if (!isset($contexts['logged-in-user'])) {
  309. $contexts['logged-in-user'] = ctools_access_get_loggedin_context();
  310. }
  311. $visibility_links = array();
  312. if (!empty($pane->access['plugins'])) {
  313. foreach ($pane->access['plugins'] as $id => $test) {
  314. $plugin = ctools_get_access_plugin($test['name']);
  315. $access_title = isset($plugin['title']) ? $plugin['title'] : t('Broken/missing access plugin %plugin', array('%plugin' => $test['name']));
  316. $access_description = ctools_access_summary($plugin, $contexts, $test);
  317. $visibility_links[] = array(
  318. 'title' => $access_description,
  319. 'href' => $this->get_url('access-configure-test', $pane->pid, $id),
  320. 'attributes' => array('class' => array('ctools-use-modal', 'panels-italic')),
  321. );
  322. }
  323. }
  324. if (empty($visibility_links)) {
  325. $visibility_links['no_rules'] = array(
  326. 'title' => t('No rules'),
  327. 'attributes' => array('class' => array('panels-text')),
  328. );
  329. }
  330. $visibility_links['add_rule'] = array(
  331. 'title' => t('Add new rule'),
  332. 'href' => $this->get_url('access-add-test', $pane->pid),
  333. 'attributes' => array('class' => array('ctools-use-modal')),
  334. );
  335. $visibility_links['settings'] = array(
  336. 'title' => t('Settings'),
  337. 'href' => $this->get_url('access-settings', $pane->pid),
  338. 'attributes' => array('class' => array('ctools-use-modal')),
  339. );
  340. $links['visibility'] = $visibility_links;
  341. }
  342. if (user_access('use panels locks')) {
  343. $lock_type = !empty($pane->locks['type']) ? $pane->locks['type'] : 'none';
  344. switch ($lock_type) {
  345. case 'immovable':
  346. $lock_method = t('Immovable');
  347. break;
  348. case 'regions':
  349. $lock_method = t('Regions');
  350. break;
  351. case 'none':
  352. default:
  353. $lock_method = t('No lock');
  354. break;
  355. }
  356. $lock_links['lock'] = array(
  357. 'title' => $lock_method,
  358. 'attributes' => array('class' => array('panels-text')),
  359. );
  360. $lock_links['change'] = array(
  361. 'title' => t('Change'),
  362. 'href' => $this->get_url('lock', $pane->pid),
  363. 'attributes' => array('class' => array('ctools-use-modal')),
  364. );
  365. $links['lock'] = $lock_links;
  366. }
  367. if (panels_get_caches() && user_access('use panels caching features')) {
  368. $method = isset($pane->cache['method']) ? $pane->cache['method'] : 0;
  369. $info = panels_get_cache($method);
  370. $cache_method = isset($info['title']) ? $info['title'] : t('No caching');
  371. $cache_links['title'] = array(
  372. 'title' => $cache_method,
  373. 'attributes' => array('class' => array('panels-text')),
  374. );
  375. $cache_links['change'] = array(
  376. 'title' => t('Change'),
  377. 'href' => $this->get_url('cache-method', $pane->pid),
  378. 'attributes' => array('class' => array('ctools-use-modal')),
  379. );
  380. if (panels_plugin_get_function('cache', $info, 'settings form')) {
  381. $cache_links['settings'] = array(
  382. 'title' => t('Settings'),
  383. 'href' => $this->get_url('cache-settings', $pane->pid),
  384. 'attributes' => array('class' => array('ctools-use-modal')),
  385. );
  386. }
  387. $links['cache'] = $cache_links;
  388. }
  389. $links['bottom']['remove'] = array(
  390. 'title' => t('Remove'),
  391. 'href' => '#',
  392. 'attributes' => array(
  393. 'class' => array('pane-delete'),
  394. 'id' => "pane-delete-panel-pane-$pane->pid",
  395. ),
  396. );
  397. // Allow others to add/remove links from pane context menu.
  398. // Grouped by 'top', 'style', 'visibility', 'lock', 'cache' and 'bottom'.
  399. drupal_alter('get_pane_links', $links, $pane, $content_type);
  400. $dropdown_links = $links['top'];
  401. $category_labels = array(
  402. 'style' => 'Style',
  403. 'visibility' => 'Visibility rules',
  404. 'lock' => 'Locking',
  405. 'cache' => 'Caching',
  406. );
  407. foreach ($category_labels as $category => $label) {
  408. if (array_key_exists($category, $links)) {
  409. $dropdown_links[] = array(
  410. 'title' => '<hr />',
  411. 'html' => TRUE,
  412. );
  413. $dropdown_links[] = array(
  414. 'title' => '<span class="dropdown-header">' . t($label) . '</span>' . theme_links(array('links' => $links[$category], 'attributes' => array(), 'heading' => array())),
  415. 'html' => TRUE,
  416. 'attributes' => array('class' => array('panels-sub-menu')),
  417. );
  418. }
  419. }
  420. $dropdown_links[] = array(
  421. 'title' => '<hr />',
  422. 'html' => TRUE,
  423. );
  424. $dropdown_links = array_merge($dropdown_links, $links['bottom']);
  425. return theme('ctools_dropdown', array('title' => theme('image', array('path' => ctools_image_path('icon-configure.png', 'panels'))), 'links' => $dropdown_links, 'image' => TRUE));
  426. }
  427. // -----------------------------------------------------------------------
  428. // Display edit AJAX callbacks and helpers.
  429. /**
  430. * Generate a URL path for the AJAX editor.
  431. */
  432. function get_url() {
  433. $args = func_get_args();
  434. $command = array_shift($args);
  435. $url = 'panels/ajax/' . $this->plugin['name'] . '/' . $command . '/' . $this->display->cache_key;
  436. if ($args) {
  437. $url .= '/' . implode('/', $args);
  438. }
  439. return $url;
  440. }
  441. /**
  442. * Get the Panels storage oparation for a given renderer AJAX method.
  443. *
  444. * @param string $method
  445. * The method name.
  446. *
  447. * @return string
  448. * The Panels storage op.
  449. */
  450. function get_panels_storage_op_for_ajax($method) {
  451. switch ($method) {
  452. case 'ajax_show':
  453. case 'ajax_hide':
  454. case 'ajax_select_content':
  455. case 'ajax_add_pane':
  456. case 'ajax_edit_pane':
  457. case 'ajax_panel_title':
  458. case 'ajax_cache_method':
  459. case 'ajax_cache_settings':
  460. case 'ajax_style_type':
  461. case 'ajax_style_settings':
  462. case 'ajax_pane_css':
  463. case 'ajax_lock':
  464. case 'ajax_access_settings':
  465. case 'ajax_access_add_test':
  466. case 'ajax_access_configure_test':
  467. case 'ajax_layout':
  468. case 'ajax_style':
  469. return 'update';
  470. }
  471. return parent::get_panels_storage_op_for_ajax($method);
  472. }
  473. /**
  474. * AJAX command to show a pane.
  475. */
  476. function ajax_show($pid = NULL) {
  477. if (empty($this->display->content[$pid])) {
  478. ctools_ajax_render_error(t('Invalid pane id.'));
  479. }
  480. $this->display->content[$pid]->shown = TRUE;
  481. panels_edit_cache_set($this->cache);
  482. $this->command_update_pane($pid);
  483. }
  484. /**
  485. * AJAX command to show a pane.
  486. */
  487. function ajax_hide($pid = NULL) {
  488. if (empty($this->display->content[$pid])) {
  489. ctools_ajax_render_error(t('Invalid pane id.'));
  490. }
  491. $this->display->content[$pid]->shown = FALSE;
  492. panels_edit_cache_set($this->cache);
  493. $this->command_update_pane($pid);
  494. }
  495. /**
  496. * AJAX command to present a dialog with a list of available content.
  497. */
  498. function ajax_select_content($region = NULL, $category = NULL) {
  499. if (!array_key_exists($region, $this->plugins['layout']['regions'])) {
  500. ctools_modal_render(t('Error'), t('Invalid input'));
  501. }
  502. $title = t('Add content to !s', array('!s' => $this->plugins['layout']['regions'][$region]));
  503. $categories = $this->get_categories($this->cache->content_types);
  504. if (empty($categories)) {
  505. $output = t('There are no content types you may add to this display.');
  506. }
  507. else {
  508. $output = theme('panels_add_content_modal', array('renderer' => $this, 'categories' => $categories, 'category' => $category, 'region' => $region));
  509. }
  510. $this->commands[] = ctools_modal_command_display($title, $output);
  511. // Give keybord focus to the first item in the category we just loaded.
  512. if (!empty($category)) {
  513. $this->commands[] = ajax_command_invoke(".panels-add-content-modal .panels-section-columns :focusable:first", 'focus');
  514. }
  515. }
  516. /**
  517. * Return the category name and the category key of a given content
  518. * type.
  519. *
  520. * @todo -- this should be in CTools.
  521. */
  522. function get_category($content_type) {
  523. if (!empty($content_type['top level'])) {
  524. $category = 'root';
  525. }
  526. elseif (isset($content_type['category'])) {
  527. if (is_array($content_type['category'])) {
  528. list($category, $weight) = $content_type['category'];
  529. }
  530. else {
  531. $category = $content_type['category'];
  532. }
  533. }
  534. else {
  535. $category = t('Uncategorized');
  536. }
  537. return array(preg_replace('/[^a-z0-9]/', '-', strtolower($category)), $category);
  538. }
  539. /**
  540. * Create a list of categories from all of the content type.
  541. *
  542. * @return array
  543. * An array of categories. Each entry in the array will also be an array
  544. * with 'title' as the printable title of the category, and 'content'
  545. * being an array of all content in the category. Each item in the 'content'
  546. * array contain the array plugin definition so that it can be later
  547. * found in the content array. They will be keyed by the title so that they
  548. * can be sorted.
  549. */
  550. function get_categories($content_types) {
  551. $categories = array();
  552. $category_names = array();
  553. foreach ($content_types as $type_name => $subtypes) {
  554. foreach ($subtypes as $subtype_name => $content_type) {
  555. list($category_key, $category) = $this->get_category($content_type);
  556. if (empty($categories[$category_key])) {
  557. $categories[$category_key] = array(
  558. 'title' => $category,
  559. 'content' => array(),
  560. );
  561. $category_names[$category_key] = $category;
  562. }
  563. $content_title = filter_xss_admin($content_type['title']);
  564. // Ensure content with the same title doesn't overwrite each other.
  565. while (isset($categories[$category_key]['content'][$content_title])) {
  566. $content_title .= '-';
  567. }
  568. $categories[$category_key]['content'][$content_title] = $content_type;
  569. $categories[$category_key]['content'][$content_title]['type_name'] = $type_name;
  570. $categories[$category_key]['content'][$content_title]['subtype_name'] = $subtype_name;
  571. }
  572. }
  573. // Now sort.
  574. natcasesort($category_names);
  575. foreach ($category_names as $category => $name) {
  576. $output[$category] = $categories[$category];
  577. }
  578. return $output;
  579. }
  580. /**
  581. * AJAX entry point to add a new pane.
  582. */
  583. function ajax_add_pane($region = NULL, $type_name = NULL, $subtype_name = NULL, $step = NULL) {
  584. $content_type = ctools_get_content_type($type_name);
  585. $subtype = ctools_content_get_subtype($content_type, $subtype_name);
  586. // Determine if we are adding a different pane than previously cached. This
  587. // is used to load the different pane into cache so that multistep forms
  588. // have the correct context instead of a previously cached version that
  589. // does not match the pane currently being added.
  590. $is_different_pane = FALSE;
  591. if (isset($this->cache) && isset($this->cache->new_pane)) {
  592. $diff_type = $type_name != $this->cache->new_pane->type;
  593. $diff_subtype = $subtype_name != $this->cache->new_pane->subtype;
  594. $is_different_pane = $diff_type || $diff_subtype;
  595. }
  596. if (!isset($step) || !isset($this->cache->new_pane) || $is_different_pane) {
  597. $pane = panels_new_pane($type_name, $subtype_name, TRUE);
  598. $this->cache->new_pane = &$pane;
  599. }
  600. else {
  601. $pane = &$this->cache->new_pane;
  602. }
  603. $form_state = array(
  604. 'display' => &$this->cache->display,
  605. 'contexts' => $this->cache->display->context,
  606. 'pane' => &$pane,
  607. 'cache_key' => $this->display->cache_key,
  608. 'display cache' => &$this->cache,
  609. 'ajax' => TRUE,
  610. 'modal' => TRUE,
  611. // This will force the system to not automatically render.
  612. 'modal return' => TRUE,
  613. 'commands' => array(),
  614. );
  615. $form_info = array(
  616. 'path' => $this->get_url('add-pane', $region, $type_name, $subtype_name, '%step'),
  617. 'show cancel' => TRUE,
  618. 'next callback' => 'panels_ajax_edit_pane_next',
  619. 'finish callback' => 'panels_ajax_edit_pane_finish',
  620. 'cancel callback' => 'panels_ajax_edit_pane_cancel',
  621. );
  622. $output = ctools_content_form('add', $form_info, $form_state, $content_type, $pane->subtype, $subtype, $pane->configuration, $step);
  623. // If $rc is FALSE, there was no actual form.
  624. if ($output === FALSE || !empty($form_state['complete'])) {
  625. // References get blown away with AJAX caching. This will fix that.
  626. $pane = $form_state['pane'];
  627. unset($this->cache->new_pane);
  628. // Add the pane to the display.
  629. $this->display->add_pane($pane, $region);
  630. panels_edit_cache_set($this->cache);
  631. // Tell the client to draw the pane.
  632. $this->command_add_pane($pane);
  633. // Dismiss the modal.
  634. $this->commands[] = ctools_modal_command_dismiss();
  635. }
  636. elseif (!empty($form_state['cancel'])) {
  637. // If cancelling, return to the activity.
  638. list($category_key, $category) = $this->get_category($subtype);
  639. $this->ajax_select_content($region, $category_key);
  640. }
  641. else {
  642. // This overwrites any previous commands.
  643. $this->commands = ctools_modal_form_render($form_state, $output);
  644. }
  645. }
  646. /**
  647. * AJAX entry point to edit a pane.
  648. */
  649. function ajax_edit_pane($pid = NULL, $step = NULL) {
  650. if (empty($this->cache->display->content[$pid])) {
  651. ctools_modal_render(t('Error'), t('Invalid pane id.'));
  652. }
  653. $pane = &$this->cache->display->content[$pid];
  654. $content_type = ctools_get_content_type($pane->type);
  655. $subtype = ctools_content_get_subtype($content_type, $pane->subtype);
  656. $form_state = array(
  657. 'display' => &$this->cache->display,
  658. 'contexts' => $this->cache->display->context,
  659. 'pane' => &$pane,
  660. 'display cache' => &$this->cache,
  661. 'ajax' => TRUE,
  662. 'modal' => TRUE,
  663. 'modal return' => TRUE,
  664. 'commands' => array(),
  665. );
  666. $form_info = array(
  667. 'path' => $this->get_url('edit-pane', $pid, '%step'),
  668. 'show cancel' => TRUE,
  669. 'next callback' => 'panels_ajax_edit_pane_next',
  670. 'finish callback' => 'panels_ajax_edit_pane_finish',
  671. 'cancel callback' => 'panels_ajax_edit_pane_cancel',
  672. );
  673. $output = ctools_content_form('edit', $form_info, $form_state, $content_type, $pane->subtype, $subtype, $pane->configuration, $step);
  674. // If $rc is FALSE, there was no actual form.
  675. if ($output === FALSE || !empty($form_state['cancel'])) {
  676. // Dismiss the modal.
  677. $this->commands[] = ctools_modal_command_dismiss();
  678. }
  679. elseif (!empty($form_state['complete'])) {
  680. // References get blown away with AJAX caching. This will fix that.
  681. $this->cache->display->content[$pid] = $form_state['pane'];
  682. // Conditionally overwrite the context for this panel if present in the form state.
  683. if (!empty($form_state['display_cache']->display->context)) {
  684. $this->cache->display->context = $form_state['display_cache']->display->context;
  685. }
  686. panels_edit_cache_set($this->cache);
  687. $this->command_update_pane($pid);
  688. $this->commands[] = ctools_modal_command_dismiss();
  689. }
  690. else {
  691. // This overwrites any previous commands.
  692. $this->commands = ctools_modal_form_render($form_state, $output);
  693. }
  694. }
  695. /**
  696. * AJAX entry point to select which pane is currently the title.
  697. *
  698. * @param string $pid
  699. * The pane id for the pane object whose title state we're setting.
  700. */
  701. function ajax_panel_title($pid = NULL) {
  702. if (empty($this->display->content[$pid])) {
  703. ctools_ajax_render_error(t('Invalid pane id.'));
  704. }
  705. $pane = &$this->display->content[$pid];
  706. $old_title = !empty($this->display->title_pane) ? $this->display->title_pane : NULL;
  707. $this->display->title_pane = $pid;
  708. panels_edit_cache_set($this->cache);
  709. $this->command_update_pane($pane);
  710. if ($old_title && !empty($this->cache->display->content[$old_title])) {
  711. $this->command_update_pane($this->cache->display->content[$old_title]);
  712. }
  713. }
  714. /**
  715. * AJAX entry point to configure the cache method for a pane or the display.
  716. *
  717. * @param string $pid
  718. * Either a pane id for a pane in the display, or 'display' to edit the
  719. * display cache settings.
  720. */
  721. function ajax_cache_method($pid = NULL) {
  722. ctools_include('content');
  723. // This lets us choose whether we're doing the display's cache or
  724. // a pane's.
  725. if ($pid == 'display') {
  726. $conf = &$this->display->cache;
  727. $title = t('Cache method for this display');
  728. }
  729. elseif (!empty($this->display->content[$pid])) {
  730. $pane = &$this->display->content[$pid];
  731. $subtype = ctools_content_get_subtype($pane->type, $pane->subtype);
  732. $conf = &$pane->cache;
  733. $title = t('Cache method for !subtype_title', array('!subtype_title' => $subtype['title']));
  734. }
  735. else {
  736. ctools_modal_render(t('Error'), t('Invalid pane id.'));
  737. }
  738. $form_state = array(
  739. 'display' => &$this->display,
  740. 'conf' => &$conf,
  741. 'title' => $title,
  742. 'ajax' => TRUE,
  743. );
  744. $output = ctools_modal_form_wrapper('panels_edit_cache_method_form', $form_state);
  745. if (empty($form_state['executed'])) {
  746. $this->commands = $output;
  747. return;
  748. }
  749. // Preserve this; this way we don't actually change the method until they
  750. // have saved the form.
  751. $info = panels_get_cache($form_state['method']);
  752. $function = panels_plugin_get_function('cache', $info, 'settings form');
  753. if (!$function) {
  754. $conf['method'] = $form_state['method'];
  755. $conf['settings'] = array();
  756. panels_edit_cache_set($this->cache);
  757. $this->commands[] = ctools_modal_command_dismiss();
  758. if ($pid != 'display') {
  759. $this->command_update_pane($pane);
  760. }
  761. else {
  762. $this->command_update_display_links();
  763. }
  764. }
  765. else {
  766. $this->cache->method = $form_state['method'];
  767. panels_edit_cache_set($this->cache);
  768. // Send them to next form.
  769. return $this->ajax_cache_settings($pid);
  770. }
  771. }
  772. /**
  773. * AJAX entry point to configure the cache settings for a pane or the display.
  774. *
  775. * @param string $pid
  776. * Either a pane id for a pane in the display, or 'display' to edit the
  777. * display cache settings.
  778. */
  779. function ajax_cache_settings($pid = 0) {
  780. ctools_include('content');
  781. // This lets us choose whether we're doing the display's cache or
  782. // a pane's.
  783. if ($pid == 'display') {
  784. $conf = &$this->display->cache;
  785. $title = t('Cache settings for this display');
  786. }
  787. elseif (!empty($this->display->content[$pid])) {
  788. $pane = &$this->display->content[$pid];
  789. $subtype = ctools_content_get_subtype($pane->type, $pane->subtype);
  790. $conf = &$pane->cache;
  791. $title = t('Cache settings for !subtype_title', array('!subtype_title' => $subtype['title']));
  792. }
  793. else {
  794. ctools_modal_render(t('Error'), t('Invalid pane id.'));
  795. }
  796. if (isset($this->cache->method) && (empty($conf['method']) || $conf['method'] != $this->cache->method)) {
  797. $conf['method'] = $this->cache->method;
  798. $info = panels_get_cache($conf['method']);
  799. $conf['settings'] = isset($info['defaults']) ? $info['defaults'] : array();
  800. }
  801. $form_state = array(
  802. 'display' => &$this->display,
  803. 'pid' => $pid,
  804. 'conf' => &$conf,
  805. 'ajax' => TRUE,
  806. 'title' => $title,
  807. 'url' => url($this->get_url('cache-settings', $pid), array('absolute' => TRUE)),
  808. );
  809. $output = ctools_modal_form_wrapper('panels_edit_cache_settings_form', $form_state);
  810. if (empty($form_state['executed'])) {
  811. $this->commands = $output;
  812. return;
  813. }
  814. panels_edit_cache_set($this->cache);
  815. $this->commands[] = ctools_modal_command_dismiss();
  816. if ($pid != 'display') {
  817. $this->command_update_pane($pane);
  818. }
  819. else {
  820. $this->command_update_display_links();
  821. }
  822. }
  823. /**
  824. * AJAX entry point to select the style for a display, region or pane.
  825. *
  826. * @param string $type
  827. * Either display, region or pane
  828. * @param $pid
  829. * The pane id, if a pane. The region id, if a region.
  830. */
  831. function ajax_style_type($type, $pid = NULL) {
  832. // This lets us choose whether we're doing the display's cache or
  833. // a pane's.
  834. switch ($type) {
  835. case 'display':
  836. $style = isset($this->display->panel_settings['style']) ? $this->display->panel_settings['style'] : 'default';
  837. $title = t('Default style for this display');
  838. break;
  839. case 'region':
  840. $style = isset($this->display->panel_settings[$pid]['style']) ? $this->display->panel_settings[$pid]['style'] : '-1';
  841. // -1 signifies to use the default setting.
  842. $title = t('Panel style for region "!region"', array('!region' => $this->plugins['layout']['regions'][$pid]));
  843. break;
  844. case 'pane':
  845. ctools_include('content');
  846. $pane = &$this->display->content[$pid];
  847. $style = isset($pane->style['style']) ? $pane->style['style'] : 'default';
  848. $title = ctools_content_admin_title($pane->type, $pane->subtype, $pane->configuration, $this->display->context);
  849. if (!$title) {
  850. $title = $pane->type;
  851. }
  852. $title = t('Pane style for "!title"', array('!title' => $title));
  853. break;
  854. default:
  855. ctools_modal_render(t('Error'), t('Invalid pane id.'));
  856. }
  857. $info = $this->get_style($type, $pid);
  858. $style_plugin = $info[0];
  859. $style_settings = $info[1];
  860. // Backward compatibility: Translate old-style stylizer to new style
  861. // stylizer.
  862. if ($style == 'stylizer' && !empty($style_settings['style']) && $style_settings['style'] != '$') {
  863. $style = 'stylizer:' . $style_settings['style'];
  864. }
  865. $form_state = array(
  866. 'display' => &$this->display,
  867. 'style' => $style,
  868. 'pane' => ($type == 'pane') ? $this->display->content[$pid] : NULL,
  869. 'title' => $title,
  870. 'ajax' => TRUE,
  871. 'type' => $type,
  872. );
  873. $output = ctools_modal_form_wrapper('panels_edit_style_type_form', $form_state);
  874. if (empty($form_state['executed'])) {
  875. $this->commands = $output;
  876. return;
  877. }
  878. // Preserve this; this way we don't actually change the method until they
  879. // have saved the form.
  880. $style = panels_get_style($form_state['style']);
  881. $function = panels_plugin_get_function('styles', $style, ($type == 'pane') ? 'pane settings form' : 'settings form');
  882. if (!$function) {
  883. if (isset($this->cache->style)) {
  884. unset($this->cache->style);
  885. }
  886. // If there's no settings form, just change the style and exit.
  887. switch ($type) {
  888. case 'display':
  889. $this->display->panel_settings['style'] = $form_state['style'];
  890. if (isset($this->display->panel_settings['style_settings']['default'])) {
  891. unset($this->display->panel_settings['style_settings']['default']);
  892. }
  893. break;
  894. case 'region':
  895. $this->display->panel_settings[$pid]['style'] = $form_state['style'];
  896. if (isset($this->display->panel_settings['style_settings'][$pid])) {
  897. unset($this->display->panel_settings['style_settings'][$pid]);
  898. }
  899. break;
  900. case 'pane':
  901. $pane->style['style'] = $form_state['style'];
  902. if (isset($pane->style['settings'])) {
  903. unset($pane->style['settings']);
  904. }
  905. break;
  906. }
  907. panels_edit_cache_set($this->cache);
  908. $this->commands[] = ctools_modal_command_dismiss();
  909. if ($type == 'pane') {
  910. $this->command_update_pane($pane);
  911. }
  912. elseif ($type == 'region') {
  913. $this->command_update_region_links($pid);
  914. }
  915. else {
  916. $this->command_update_display_links();
  917. }
  918. }
  919. else {
  920. if ($form_state['style'] != $form_state['old_style']) {
  921. $this->cache->style = $form_state['style'];
  922. panels_edit_cache_set($this->cache);
  923. }
  924. // Send them to next form.
  925. return $this->ajax_style_settings($type, $pid);
  926. }
  927. }
  928. /**
  929. * Get the appropriate style from the panel in the cache.
  930. *
  931. * Since we have styles for regions, panes and the display itself, and
  932. * they are stored differently, we use this method to simplify getting
  933. * style information into a way that's easy to cope with.
  934. */
  935. function get_style($type, $pid = '') {
  936. if (isset($this->cache->style)) {
  937. $style = panels_get_style($this->cache->style);
  938. $defaults = isset($style['defaults']) ? $style['defaults'] : array();
  939. // Get the &$conf variable based upon whose style we're editing.
  940. switch ($type) {
  941. case 'display':
  942. $this->display->panel_settings['style'] = $this->cache->style;
  943. $this->display->panel_settings['style_settings']['default'] = $defaults;
  944. break;
  945. case 'region':
  946. $this->display->panel_settings[$pid]['style'] = $this->cache->style;
  947. $this->display->panel_settings['style_settings'][$pid] = $defaults;
  948. break;
  949. case 'pane':
  950. $pane = &$this->display->content[$pid];
  951. $pane->style['style'] = $this->cache->style;
  952. $pane->style['settings'] = $defaults;
  953. $conf = &$pane->style['settings'];
  954. break;
  955. }
  956. }
  957. else {
  958. switch ($type) {
  959. case 'display':
  960. $style = panels_get_style((!empty($this->display->panel_settings['style'])) ? $this->display->panel_settings['style'] : 'default');
  961. break;
  962. case 'region':
  963. $style = panels_get_style((!empty($this->display->panel_settings[$pid]['style'])) ? $this->display->panel_settings[$pid]['style'] : '-1');
  964. break;
  965. case 'pane':
  966. $pane = &$this->display->content[$pid];
  967. $style = panels_get_style(!empty($pane->style['style']) ? $pane->style['style'] : 'default');
  968. break;
  969. }
  970. }
  971. // Set up our $conf reference.
  972. switch ($type) {
  973. case 'display':
  974. $conf = &$this->display->panel_settings['style_settings']['default'];
  975. break;
  976. case 'region':
  977. $conf = &$this->display->panel_settings['style_settings'][$pid];
  978. break;
  979. case 'pane':
  980. ctools_include('content');
  981. $pane = &$this->display->content[$pid];
  982. $conf = &$pane->style['settings'];
  983. break;
  984. }
  985. // Backward compatibility: Translate old-style stylizer to new style
  986. // stylizer.
  987. if ($style['name'] == 'stylizer' && !empty($conf['style']) && $conf['style'] != '$') {
  988. $style = panels_get_style('stylizer:' . $conf['style']);
  989. }
  990. return array($style, &$conf);
  991. }
  992. /**
  993. * AJAX entry point to configure the style for a display, region or pane.
  994. *
  995. * @param string $type
  996. * Either display, region or pane
  997. * @param $pid
  998. * The pane id, if a pane. The region id, if a region.
  999. */
  1000. function ajax_style_settings($type, $pid = '') {
  1001. $info = $this->get_style($type, $pid);
  1002. $style = $info[0];
  1003. $conf = &$info[1];
  1004. switch ($type) {
  1005. case 'display':
  1006. $title = t('Style settings for @style (display)', array('@style' => $style['title']));
  1007. break;
  1008. case 'region':
  1009. $title = t('Style settings for style @style (Region "!region")', array('@style' => $style['title'], '!region' => $this->plugins['layout']['regions'][$pid]));
  1010. break;
  1011. case 'pane':
  1012. ctools_include('content');
  1013. $pane = &$this->display->content[$pid];
  1014. $subtype = ctools_content_get_subtype($pane->type, $pane->subtype);
  1015. $title = t('Style settings for style @style (Pane "!pane")', array('@style' => $style['title'], '!pane' => $subtype['title']));
  1016. break;
  1017. }
  1018. $form_state = array(
  1019. 'display' => &$this->display,
  1020. 'type' => $type,
  1021. 'pid' => $pid,
  1022. 'conf' => &$conf,
  1023. 'style' => $style,
  1024. 'ajax' => TRUE,
  1025. 'title' => $title,
  1026. 'url' => url($this->get_url('style-settings', $type, $pid), array('absolute' => TRUE)),
  1027. 'renderer' => &$this,
  1028. );
  1029. $output = ctools_modal_form_wrapper('panels_edit_style_settings_form', $form_state);
  1030. if (empty($form_state['executed'])) {
  1031. $this->commands = $output;
  1032. return;
  1033. }
  1034. if (isset($this->cache->style)) {
  1035. unset($this->cache->style);
  1036. }
  1037. if (!empty($form_state['cancel'])) {
  1038. // The cache must be saved prior to dismissing the modal.
  1039. panels_edit_cache_set($this->cache);
  1040. $this->commands[] = ctools_modal_command_dismiss();
  1041. return;
  1042. }
  1043. // Copy settings from form state back into the cache.
  1044. if (!empty($form_state['values']['settings'])) {
  1045. if ($type == 'pane') {
  1046. $this->cache->display->content[$pid]->style['settings'] = $form_state['values']['settings'];
  1047. }
  1048. elseif ($type == 'region') {
  1049. $this->cache->display->panel_settings['style_settings'][$pid] = $form_state['values']['settings'];
  1050. }
  1051. }
  1052. panels_edit_cache_set($this->cache);
  1053. $this->commands[] = ctools_modal_command_dismiss();
  1054. if ($type == 'pane') {
  1055. $this->command_update_pane($pane);
  1056. }
  1057. elseif ($type == 'region') {
  1058. $this->command_update_region_links($pid);
  1059. }
  1060. else {
  1061. $this->command_update_display_links();
  1062. }
  1063. }
  1064. /**
  1065. * AJAX entry point to configure CSS for a pane.
  1066. *
  1067. * @param $pid
  1068. * The pane id to edit.
  1069. */
  1070. function ajax_pane_css($pid = NULL) {
  1071. if (empty($this->display->content[$pid])) {
  1072. ctools_modal_render(t('Error'), t('Invalid pane id.'));
  1073. }
  1074. $pane = &$this->display->content[$pid];
  1075. $subtype = ctools_content_get_subtype($pane->type, $pane->subtype);
  1076. $form_state = array(
  1077. 'display' => &$this->display,
  1078. 'pane' => &$pane,
  1079. 'ajax' => TRUE,
  1080. 'title' => t('Configure CSS on !subtype_title', array('!subtype_title' => $subtype['title'])),
  1081. );
  1082. $output = ctools_modal_form_wrapper('panels_edit_configure_pane_css_form', $form_state);
  1083. if (empty($form_state['executed'])) {
  1084. $this->commands = $output;
  1085. return;
  1086. }
  1087. panels_edit_cache_set($this->cache);
  1088. $this->command_update_pane($pid);
  1089. $this->commands[] = ctools_modal_command_dismiss();
  1090. }
  1091. /**
  1092. * AJAX entry point to configure CSS for a pane.
  1093. *
  1094. * @param $pid
  1095. * The pane id to edit.
  1096. */
  1097. function ajax_lock($pid = NULL) {
  1098. if (empty($this->display->content[$pid])) {
  1099. ctools_modal_render(t('Error'), t('Invalid pane id.'));
  1100. }
  1101. $pane = &$this->display->content[$pid];
  1102. $subtype = ctools_content_get_subtype($pane->type, $pane->subtype);
  1103. $form_state = array(
  1104. 'display' => &$this->display,
  1105. 'pane' => &$pane,
  1106. 'ajax' => TRUE,
  1107. 'title' => t('Configure lock on !subtype_title', array('!subtype_title' => $subtype['title'])),
  1108. );
  1109. $output = ctools_modal_form_wrapper('panels_edit_configure_pane_lock_form', $form_state);
  1110. if (empty($form_state['executed'])) {
  1111. $this->commands = $output;
  1112. return;
  1113. }
  1114. panels_edit_cache_set($this->cache);
  1115. $this->command_update_pane($pid);
  1116. $this->commands[] = ctools_modal_command_dismiss();
  1117. }
  1118. /**
  1119. * AJAX entry point to configure access settings for a pane.
  1120. *
  1121. * @param $pid
  1122. * The pane id to edit.
  1123. */
  1124. function ajax_access_settings($pid = NULL) {
  1125. if (empty($this->display->content[$pid])) {
  1126. ctools_modal_render(t('Error'), t('Invalid pane id.'));
  1127. }
  1128. $pane = &$this->display->content[$pid];
  1129. $subtype = ctools_content_get_subtype($pane->type, $pane->subtype);
  1130. $form_state = array(
  1131. 'display' => &$this->display,
  1132. 'pane' => &$pane,
  1133. 'ajax' => TRUE,
  1134. 'title' => t('Access settings on !subtype_title', array('!subtype_title' => $subtype['title'])),
  1135. );
  1136. $output = ctools_modal_form_wrapper('panels_edit_configure_access_settings_form', $form_state);
  1137. if (empty($form_state['executed'])) {
  1138. $this->commands = $output;
  1139. return;
  1140. }
  1141. panels_edit_cache_set($this->cache);
  1142. $this->command_update_pane($pid);
  1143. $this->commands[] = ctools_modal_command_dismiss();
  1144. }
  1145. /**
  1146. * AJAX entry point for to add a visibility rule.
  1147. */
  1148. function ajax_access_add_test($pid = NULL) {
  1149. if (empty($this->display->content[$pid])) {
  1150. ctools_modal_render(t('Error'), t('Invalid pane id.'));
  1151. }
  1152. $pane = &$this->display->content[$pid];
  1153. $subtype = ctools_content_get_subtype($pane->type, $pane->subtype);
  1154. $form_state = array(
  1155. 'display' => &$this->display,
  1156. 'pane' => &$pane,
  1157. 'ajax' => TRUE,
  1158. 'title' => t('Add visibility rule for !subtype_title', array('!subtype_title' => $subtype['title'])),
  1159. );
  1160. $output = ctools_modal_form_wrapper('panels_edit_add_access_test_form', $form_state);
  1161. if (!empty($form_state['executed'])) {
  1162. // Set up the plugin in cache.
  1163. $plugin = ctools_get_access_plugin($form_state['values']['type']);
  1164. $this->cache->new_plugin = ctools_access_new_test($plugin);
  1165. panels_edit_cache_set($this->cache);
  1166. // Go to the next step.
  1167. return $this->ajax_access_configure_test($pid, 'add');
  1168. }
  1169. $this->commands = $output;
  1170. }
  1171. /**
  1172. * AJAX entry point for to configure vsibility rule.
  1173. */
  1174. function ajax_access_configure_test($pid = NULL, $id = NULL) {
  1175. if (empty($this->display->content[$pid])) {
  1176. ctools_modal_render(t('Error'), t('Invalid pane id.'));
  1177. }
  1178. $pane = &$this->display->content[$pid];
  1179. $subtype = ctools_content_get_subtype($pane->type, $pane->subtype);
  1180. // Set this up here because $id gets changed later.
  1181. $url = $this->get_url('access-configure-test', $pid, $id);
  1182. // If we're adding a new one, get the stored data from cache and
  1183. // add it. It's stored as a cache so that if this is closed
  1184. // we don't accidentally add an unconfigured plugin.
  1185. if ($id == 'add') {
  1186. $pane->access['plugins'][] = $this->cache->new_plugin;
  1187. $id = max(array_keys($pane->access['plugins']));
  1188. }
  1189. elseif (empty($pane->access['plugins'][$id])) {
  1190. ctools_modal_render(t('Error'), t('Invalid test id.'));
  1191. }
  1192. $form_state = array(
  1193. 'display' => &$this->display,
  1194. 'pane' => &$pane,
  1195. 'ajax' => TRUE,
  1196. 'title' => t('Configure visibility rule for !subtype_title', array('!subtype_title' => $subtype['title'])),
  1197. 'test' => &$pane->access['plugins'][$id],
  1198. 'plugin' => ctools_get_access_plugin($pane->access['plugins'][$id]['name']),
  1199. 'url' => url($url, array('absolute' => TRUE)),
  1200. );
  1201. $output = ctools_modal_form_wrapper('panels_edit_configure_access_test_form', $form_state);
  1202. if (empty($form_state['executed'])) {
  1203. $this->commands = $output;
  1204. return;
  1205. }
  1206. // Unset the new plugin.
  1207. if (isset($this->cache->new_plugin)) {
  1208. unset($this->cache->new_plugin);
  1209. }
  1210. if (!empty($form_state['remove'])) {
  1211. unset($pane->access['plugins'][$id]);
  1212. }
  1213. panels_edit_cache_set($this->cache);
  1214. $this->command_update_pane($pid);
  1215. $this->commands[] = ctools_modal_command_dismiss();
  1216. }
  1217. /**
  1218. * AJAX Router function for layout owned AJAX calls.
  1219. *
  1220. * Layouts like the flexible layout builder need callbacks of their own.
  1221. * This allows those layouts to simply declare their callbacks and use
  1222. * them with $this->get_url('layout', $command).
  1223. */
  1224. function ajax_layout() {
  1225. $args = func_get_args();
  1226. if (empty($args)) {
  1227. return MENU_NOT_FOUND;
  1228. }
  1229. $command = array_shift($args);
  1230. if (empty($this->plugins['layout']['ajax'][$command]) || !function_exists($this->plugins['layout']['ajax'][$command])) {
  1231. return MENU_NOT_FOUND;
  1232. }
  1233. // Make sure the this is always available to the called functions.
  1234. array_unshift($args, $this);
  1235. return call_user_func_array($this->plugins['layout']['ajax'][$command], $args);
  1236. }
  1237. /**
  1238. * AJAX Router function for style owned AJAX calls.
  1239. *
  1240. * Styles like the stylizer need AJAX callbacks of their own. This
  1241. * allows the system to figure out which style is being referenced,
  1242. * load it, and execute the callback.
  1243. *
  1244. * This allows those layouts to simply declare their callbacks and use
  1245. * them using $this->get_url('style', $command, $type, $pid).
  1246. */
  1247. function ajax_style() {
  1248. $args = func_get_args();
  1249. if (count($args) < 3) {
  1250. return MENU_NOT_FOUND;
  1251. }
  1252. $command = array_shift($args);
  1253. $type = array_shift($args);
  1254. $pid = array_shift($args);
  1255. $info = $this->get_style($type, $pid);
  1256. $style = $info[0];
  1257. $conf = &$info[1];
  1258. if (empty($style['ajax'][$command]) || !function_exists($style['ajax'][$command])) {
  1259. return MENU_NOT_FOUND;
  1260. }
  1261. // Make sure the this is always available to the called functions.
  1262. $args = array_merge(array(&$this, $style, &$conf, $type, $pid), $args);
  1263. return call_user_func_array($style['ajax'][$command], $args);
  1264. }
  1265. // ------------------------------------------------------------------------
  1266. // AJAX command generators
  1267. //
  1268. // These are used to make sure that child implementations can control their
  1269. // own AJAX commands as needed.
  1270. /**
  1271. * Create a command array to redraw a pane.
  1272. */
  1273. function command_update_pane($pid) {
  1274. if (is_object($pid)) {
  1275. $pane = $pid;
  1276. }
  1277. else {
  1278. $pane = $this->display->content[$pid];
  1279. }
  1280. $this->commands[] = ajax_command_replace("#panel-pane-$pane->pid", $this->render_pane($pane));
  1281. $this->commands[] = ajax_command_changed("#panel-pane-$pane->pid", "div.grab-title span.text");
  1282. }
  1283. /**
  1284. * Create a command array to add a new pane.
  1285. */
  1286. function command_add_pane($pid) {
  1287. if (is_object($pid)) {
  1288. $pane = $pid;
  1289. }
  1290. else {
  1291. $pane = $this->display->content[$pid];
  1292. }
  1293. $this->commands[] = ajax_command_append("#panel-region-$pane->panel", $this->render_pane($pane));
  1294. $this->commands[] = ajax_command_changed("#panel-pane-$pane->pid", "div.grab-title span.text");
  1295. }
  1296. /**
  1297. * Create a command to update the links on a display after a change was made.
  1298. */
  1299. function command_update_display_links() {
  1300. $this->commands[] = ajax_command_replace('.panels-display-links', $this->get_display_links());
  1301. }
  1302. /**
  1303. * Create a command to update the links on a region after a change was made.
  1304. */
  1305. function command_update_region_links($id) {
  1306. $this->commands[] = ajax_command_replace('.panels-region-links-' . $id, $this->get_region_links($id));
  1307. }
  1308. }
  1309. /**
  1310. * Handle the 'next' click on the add/edit pane form wizard.
  1311. *
  1312. * All we need to do is store the updated pane in the cache.
  1313. */
  1314. function panels_ajax_edit_pane_next(&$form_state) {
  1315. $form_state['display cache']->new_pane = $form_state['pane'];
  1316. panels_edit_cache_set($form_state['display cache']);
  1317. }
  1318. /**
  1319. * Handle the 'finish' click on the add/edit pane form wizard.
  1320. *
  1321. * All we need to do is set a flag so the return can handle adding
  1322. * the pane.
  1323. */
  1324. function panels_ajax_edit_pane_finish(&$form_state) {
  1325. $form_state['complete'] = TRUE;
  1326. return;
  1327. }
  1328. /**
  1329. * Handle the 'cancel' click on the add/edit pane form wizard.
  1330. */
  1331. function panels_ajax_edit_pane_cancel(&$form_state) {
  1332. $form_state['cancel'] = TRUE;
  1333. return;
  1334. }
  1335. // --------------------------------------------------------------------------
  1336. // Forms for the editor object.
  1337. /**
  1338. * Choose cache method form.
  1339. */
  1340. function panels_edit_cache_method_form($form, &$form_state) {
  1341. ctools_form_include($form_state, 'plugins', 'panels');
  1342. form_load_include($form_state, 'php', 'panels', '/plugins/display_renderers/panels_renderer_editor.class');
  1343. $display = &$form_state['display'];
  1344. $conf = &$form_state['conf'];
  1345. // Set to 0 to ensure we get a selected radio.
  1346. if (!isset($conf['method'])) {
  1347. $conf['method'] = 0;
  1348. }
  1349. $caches = panels_get_caches();
  1350. if (empty($caches)) {
  1351. $form['markup'] = array('#value' => t('No caching options are available at this time. Please enable a panels caching module in order to use caching options.'));
  1352. return $form;
  1353. }
  1354. $options[0] = t('No caching');
  1355. foreach ($caches as $cache => $info) {
  1356. $options[$cache] = check_plain($info['title']);
  1357. }
  1358. $form['method'] = array(
  1359. '#prefix' => '<div class="no-float">',
  1360. '#suffix' => '</div>',
  1361. '#type' => 'radios',
  1362. '#title' => t('Method'),
  1363. '#options' => $options,
  1364. '#default_value' => $conf['method'],
  1365. );
  1366. $form['submit'] = array(
  1367. '#type' => 'submit',
  1368. '#value' => t('Next'),
  1369. );
  1370. return $form;
  1371. }
  1372. /**
  1373. * Submit callback for panels_edit_cache_method_form.
  1374. *
  1375. * All this needs to do is return the method.
  1376. */
  1377. function panels_edit_cache_method_form_submit($form, &$form_state) {
  1378. $form_state['method'] = $form_state['values']['method'];
  1379. }
  1380. /**
  1381. * Cache settings form.
  1382. */
  1383. function panels_edit_cache_settings_form($form, &$form_state) {
  1384. ctools_form_include($form_state, 'plugins', 'panels');
  1385. form_load_include($form_state, 'php', 'panels', '/plugins/display_renderers/panels_renderer_editor.class');
  1386. $display = &$form_state['display'];
  1387. $conf = &$form_state['conf'];
  1388. $pid = $form_state['pid'];
  1389. $info = panels_get_cache($conf['method']);
  1390. $form['#action'] = $form_state['url'];
  1391. $form['description'] = array(
  1392. '#prefix' => '<div class="description">',
  1393. '#suffix' => '</div>',
  1394. '#value' => check_plain($info['description']),
  1395. );
  1396. $function = panels_plugin_get_function('cache', $conf['method'], 'settings form');
  1397. $form['settings'] = $function($conf['settings'], $display, $pid);
  1398. $form['settings']['#tree'] = TRUE;
  1399. $form['display'] = array(
  1400. '#type' => 'value',
  1401. '#value' => $display,
  1402. );
  1403. $form['pid'] = array(
  1404. '#type' => 'value',
  1405. '#value' => $pid,
  1406. );
  1407. $form['submit'] = array(
  1408. '#type' => 'submit',
  1409. '#value' => t('Save'),
  1410. );
  1411. return $form;
  1412. }
  1413. /**
  1414. * Validate cache settings.
  1415. */
  1416. function panels_edit_cache_settings_form_validate($form, &$form_state) {
  1417. if ($function = panels_plugin_get_function('cache', $form_state['conf']['method'], 'settings form validate')) {
  1418. $function($form, $form_state['values']['settings']);
  1419. }
  1420. }
  1421. /**
  1422. * Allows panel styles to validate their style settings.
  1423. */
  1424. function panels_edit_cache_settings_form_submit($form, &$form_state) {
  1425. if ($function = panels_plugin_get_function('cache', $form_state['conf']['method'], 'settings form submit')) {
  1426. $function($form_state['values']['settings']);
  1427. }
  1428. $form_state['conf']['settings'] = $form_state['values']['settings'];
  1429. }
  1430. /**
  1431. * Choose style form.
  1432. */
  1433. function panels_edit_style_type_form($form, &$form_state) {
  1434. ctools_form_include($form_state, 'plugins', 'panels');
  1435. form_load_include($form_state, 'php', 'panels', '/plugins/display_renderers/panels_renderer_editor.class');
  1436. $display = &$form_state['display'];
  1437. $style = $form_state['style'];
  1438. $type = $form_state['type'];
  1439. $styles = panels_get_styles();
  1440. $function = ($type == 'pane' ? 'render pane' : 'render region');
  1441. $options = array();
  1442. if ($type == 'region') {
  1443. $options[-1] = t('Use display default style');
  1444. }
  1445. uasort($styles, 'ctools_plugin_sort');
  1446. foreach ($styles as $id => $info) {
  1447. if (empty($info['hidden']) && (!empty($info[$function]) || $id == 'default')) {
  1448. $options[$id] = check_plain($info['title']);
  1449. }
  1450. }
  1451. $form['style'] = array(
  1452. '#prefix' => '<div class="no-float">',
  1453. '#suffix' => '</div>',
  1454. '#type' => 'radios',
  1455. '#title' => t('Style'),
  1456. '#options' => $options,
  1457. '#default_value' => $style,
  1458. );
  1459. $form['submit'] = array(
  1460. '#type' => 'submit',
  1461. '#value' => t('Next'),
  1462. );
  1463. return $form;
  1464. }
  1465. /**
  1466. * Submit callback for panels_edit_style_type_form.
  1467. *
  1468. * All this needs to do is return the method.
  1469. */
  1470. function panels_edit_style_type_form_submit($form, &$form_state) {
  1471. $form_state['old_style'] = $form_state['style'];
  1472. $form_state['style'] = $form_state['values']['style'];
  1473. }
  1474. /**
  1475. * Style settings form.
  1476. */
  1477. function panels_edit_style_settings_form($form, &$form_state) {
  1478. ctools_form_include($form_state, 'plugins', 'panels');
  1479. form_load_include($form_state, 'php', 'panels', '/plugins/display_renderers/panels_renderer_editor.class');
  1480. $display = &$form_state['display'];
  1481. $conf = &$form_state['conf'];
  1482. $pid = $form_state['pid'];
  1483. $style = $form_state['style'];
  1484. $type = $form_state['type'];
  1485. $form['#action'] = $form_state['url'];
  1486. $form['description'] = array(
  1487. '#prefix' => '<div class="description">',
  1488. '#suffix' => '</div>',
  1489. '#value' => check_plain($style['description']),
  1490. );
  1491. $function = panels_plugin_get_function('styles', $style, ($type == 'pane') ? 'pane settings form' : 'settings form');
  1492. $form['settings'] = $function($conf, $display, $pid, $type, $form_state);
  1493. $form['settings']['#tree'] = TRUE;
  1494. $form['submit'] = array(
  1495. '#type' => 'submit',
  1496. '#value' => t('Save'),
  1497. );
  1498. // Need a cancel button since the style cache can persist and impact the wrong
  1499. // pane (or region, or display).
  1500. $form['cancel_style'] = array(
  1501. '#type' => 'submit',
  1502. '#value' => t('Cancel'),
  1503. '#submit' => array('panels_edit_style_settings_form_cancel'),
  1504. );
  1505. return $form;
  1506. }
  1507. /**
  1508. * Cancel style settings form.
  1509. *
  1510. * Clears the editing cache to prevent styles being applied to incorrect regions
  1511. * or panes.
  1512. */
  1513. function panels_edit_style_settings_form_cancel($form, &$form_state) {
  1514. $form_state['cancel'] = TRUE;
  1515. }
  1516. /**
  1517. * Validate style settings.
  1518. */
  1519. function panels_edit_style_settings_form_validate($form, &$form_state) {
  1520. $name = $form_state['type'] == 'pane' ? 'pane settings form validate' : 'settings form validate';
  1521. if ($function = panels_plugin_get_function('styles', $form_state['style'], $name)) {
  1522. $function($form, $form_state['values']['settings'], $form_state);
  1523. }
  1524. }
  1525. /**
  1526. * Allows panel styles to validate their style settings.
  1527. */
  1528. function panels_edit_style_settings_form_submit($form, &$form_state) {
  1529. $name = $form_state['type'] == 'pane' ? 'pane settings form submit' : 'settings form submit';
  1530. if ($function = panels_plugin_get_function('styles', $form_state['style'], $name)) {
  1531. $function($form, $form_state['values']['settings'], $form_state);
  1532. }
  1533. $form_state['conf'] = $form_state['values']['settings'];
  1534. }
  1535. /**
  1536. * Configure CSS on a pane form.
  1537. */
  1538. function panels_edit_configure_pane_css_form($form, &$form_state) {
  1539. ctools_form_include($form_state, 'plugins', 'panels');
  1540. form_load_include($form_state, 'php', 'panels', '/plugins/display_renderers/panels_renderer_editor.class');
  1541. $display = &$form_state['display'];
  1542. $pane = &$form_state['pane'];
  1543. $form['css_id'] = array(
  1544. '#type' => 'textfield',
  1545. '#default_value' => isset($pane->css['css_id']) ? $pane->css['css_id'] : '',
  1546. '#title' => t('CSS ID'),
  1547. '#description' => t('CSS ID to apply to this pane. This may be blank. Keywords from context are allowed.'),
  1548. );
  1549. $form['css_class'] = array(
  1550. '#type' => 'textfield',
  1551. '#default_value' => isset($pane->css['css_class']) ? $pane->css['css_class'] : '',
  1552. '#title' => t('CSS class'),
  1553. '#description' => t('CSS class to apply to this pane. This may be blank. Keywords from context are allowed.'),
  1554. );
  1555. $form['next'] = array(
  1556. '#type' => 'submit',
  1557. '#value' => t('Save'),
  1558. );
  1559. return $form;
  1560. }
  1561. /**
  1562. * FAPI submission function for the CSS configure form.
  1563. *
  1564. * All this does is set up $pane properly. The caller is responsible for
  1565. * actually storing this somewhere.
  1566. */
  1567. function panels_edit_configure_pane_css_form_submit($form, &$form_state) {
  1568. $pane = &$form_state['pane'];
  1569. $display = $form_state['display'];
  1570. $pane->css['css_id'] = $form_state['values']['css_id'];
  1571. $pane->css['css_class'] = $form_state['values']['css_class'];
  1572. }
  1573. /**
  1574. * Configure lock on a pane form.
  1575. */
  1576. function panels_edit_configure_pane_lock_form($form, &$form_state) {
  1577. ctools_form_include($form_state, 'plugins', 'panels');
  1578. form_load_include($form_state, 'php', 'panels', '/plugins/display_renderers/panels_renderer_editor.class');
  1579. $display = &$form_state['display'];
  1580. $pane = &$form_state['pane'];
  1581. if (empty($pane->locks)) {
  1582. $pane->locks = array('type' => 'none', 'regions' => array());
  1583. }
  1584. $form['type'] = array(
  1585. '#type' => 'radios',
  1586. '#title' => t('Lock type'),
  1587. '#options' => array(
  1588. 'none' => t('No lock'),
  1589. 'immovable' => t('Immovable'),
  1590. 'regions' => t('Regions'),
  1591. ),
  1592. '#default_value' => $pane->locks['type'],
  1593. );
  1594. $layout = panels_get_layout($display->layout);
  1595. $regions = panels_get_regions($layout, $display);
  1596. $form['regions'] = array(
  1597. '#type' => 'checkboxes',
  1598. '#title' => t('Regions'),
  1599. '#options' => $regions,
  1600. '#description' => t('Select which regions this pane can be moved to.'),
  1601. '#dependency' => array(
  1602. 'radio:type' => array('regions'),
  1603. ),
  1604. '#default_value' => $pane->locks['regions'],
  1605. );
  1606. $form['#after_build'][] = 'panels_edit_configure_pane_lock_form_after_build';
  1607. $form['next'] = array(
  1608. '#type' => 'submit',
  1609. '#value' => t('Save'),
  1610. );
  1611. return $form;
  1612. }
  1613. function panels_edit_configure_pane_lock_form_after_build($element, $form_state) {
  1614. $region = $form_state['pane']->panel;
  1615. $element['regions'][$region]['#required'] = TRUE;
  1616. $element['regions'][$region]['#disabled'] = TRUE;
  1617. $element['regions'][$region]['#value'] = TRUE;
  1618. $element['regions'][$region]['#checked'] = TRUE;
  1619. $element['regions'][$region]['#attributes']['disabled'] = TRUE;
  1620. return $element;
  1621. }
  1622. /**
  1623. * FAPI submission function for the lock configure form.
  1624. *
  1625. * All this does is set up $pane properly. The caller is responsible for
  1626. * actually storing this somewhere.
  1627. */
  1628. function panels_edit_configure_pane_lock_form_submit($form, &$form_state) {
  1629. $pane = &$form_state['pane'];
  1630. $display = $form_state['display'];
  1631. // We set this to true but forms do not submit disabled checkboxes
  1632. // and fapi is ignoring the #value directive probably because it
  1633. // is checkboxes:
  1634. $region = $form_state['pane']->panel;
  1635. $form_state['values']['regions'][$region] = $region;
  1636. $pane->locks['type'] = $form_state['values']['type'];
  1637. $pane->locks['regions'] = array_filter($form_state['values']['regions']);
  1638. }
  1639. /**
  1640. * Form to control basic visibility settings.
  1641. */
  1642. function panels_edit_configure_access_settings_form($form, &$form_state) {
  1643. ctools_form_include($form_state, 'plugins', 'panels');
  1644. form_load_include($form_state, 'php', 'panels', '/plugins/display_renderers/panels_renderer_editor.class');
  1645. $display = &$form_state['display'];
  1646. $pane = &$form_state['pane'];
  1647. $form['logic'] = array(
  1648. '#type' => 'radios',
  1649. '#options' => array(
  1650. 'and' => t('All criteria must pass.'),
  1651. 'or' => t('Only one criterion must pass.'),
  1652. ),
  1653. '#default_value' => isset($pane->access['logic']) ? $pane->access['logic'] : 'and',
  1654. );
  1655. $form['next'] = array(
  1656. '#type' => 'submit',
  1657. '#value' => t('Save'),
  1658. );
  1659. return $form;
  1660. }
  1661. /**
  1662. * FAPI submission function for the edit access settings form.
  1663. *
  1664. * All this does is set up $pane properly. The caller is responsible for
  1665. * actually storing this somewhere.
  1666. */
  1667. function panels_edit_configure_access_settings_form_submit($form, &$form_state) {
  1668. $pane = &$form_state['pane'];
  1669. $display = $form_state['display'];
  1670. $pane->access['logic'] = $form_state['values']['logic'];
  1671. }
  1672. /**
  1673. * Form to add a visibility rule.
  1674. */
  1675. function panels_edit_add_access_test_form($form, &$form_state) {
  1676. ctools_form_include($form_state, 'plugins', 'panels');
  1677. form_load_include($form_state, 'php', 'panels', '/plugins/display_renderers/panels_renderer_editor.class');
  1678. $display = &$form_state['display'];
  1679. $pane = &$form_state['pane'];
  1680. $plugins = ctools_get_relevant_access_plugins($display->context);
  1681. $options = array();
  1682. foreach ($plugins as $id => $plugin) {
  1683. $options[$id] = $plugin['title'];
  1684. }
  1685. asort($options);
  1686. $form['type'] = array(
  1687. // This ensures that the form item is added to the URL.
  1688. '#type' => 'radios',
  1689. '#options' => $options,
  1690. );
  1691. $form['next'] = array(
  1692. '#type' => 'submit',
  1693. '#value' => t('Next'),
  1694. );
  1695. return $form;
  1696. }
  1697. /**
  1698. * Form to configure a visibility rule.
  1699. */
  1700. function panels_edit_configure_access_test_form($form, &$form_state) {
  1701. ctools_form_include($form_state, 'plugins', 'panels');
  1702. form_load_include($form_state, 'php', 'panels', '/plugins/display_renderers/panels_renderer_editor.class');
  1703. $display = &$form_state['display'];
  1704. $test = &$form_state['test'];
  1705. $plugin = &$form_state['plugin'];
  1706. $form['#action'] = $form_state['url'];
  1707. $contexts = $display->context;
  1708. if (!isset($contexts['logged-in-user'])) {
  1709. $contexts['logged-in-user'] = ctools_access_get_loggedin_context();
  1710. }
  1711. if (isset($plugin['required context'])) {
  1712. $form['context'] = ctools_context_selector($contexts, $plugin['required context'], $test['context']);
  1713. }
  1714. $form['settings'] = array('#tree' => TRUE);
  1715. if ($function = ctools_plugin_get_function($plugin, 'settings form')) {
  1716. $form = $function($form, $form_state, $test['settings']);
  1717. }
  1718. $form['not'] = array(
  1719. '#type' => 'checkbox',
  1720. '#title' => t('Reverse (NOT)'),
  1721. '#default_value' => !empty($test['not']),
  1722. );
  1723. $form['save'] = array(
  1724. '#type' => 'submit',
  1725. '#value' => t('Save'),
  1726. );
  1727. $form['remove'] = array(
  1728. '#type' => 'submit',
  1729. '#value' => t('Remove'),
  1730. '#remove' => TRUE,
  1731. );
  1732. return $form;
  1733. }
  1734. /**
  1735. * Validate handler for visibility rule settings.
  1736. */
  1737. function panels_edit_configure_access_test_form_validate(&$form, &$form_state) {
  1738. if (!empty($form_state['clicked_button']['#remove'])) {
  1739. return;
  1740. }
  1741. if ($function = ctools_plugin_get_function($form_state['plugin'], 'settings form validate')) {
  1742. $function($form, $form_state);
  1743. }
  1744. }
  1745. /**
  1746. * Submit handler for visibility rule settings.
  1747. */
  1748. function panels_edit_configure_access_test_form_submit(&$form, &$form_state) {
  1749. if (!empty($form_state['clicked_button']['#remove'])) {
  1750. $form_state['remove'] = TRUE;
  1751. return;
  1752. }
  1753. if ($function = ctools_plugin_get_function($form_state['plugin'], 'settings form submit')) {
  1754. $function($form, $form_state);
  1755. }
  1756. $form_state['test']['settings'] = $form_state['values']['settings'];
  1757. if (isset($form_state['values']['context'])) {
  1758. $form_state['test']['context'] = $form_state['values']['context'];
  1759. }
  1760. $form_state['test']['not'] = !empty($form_state['values']['not']);
  1761. }