page_manager.admin.inc 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916
  1. <?php
  2. /**
  3. * @file
  4. * Administrative functions for the page manager.
  5. *
  6. * This provides the UI to list, create, edit and delete pages, though much
  7. * of this is delegated through to individual tasks.
  8. */
  9. /**
  10. * Output a list of pages that are managed.
  11. */
  12. function page_manager_list_page($js = NULL) {
  13. // Prevent this page from showing up when random other links fail.
  14. if ($js && $js != 'ajax' && $js != 'nojs') {
  15. return MENU_NOT_FOUND;
  16. }
  17. // TRUE if 'ajax', FALSE if otherwise.
  18. $js = $js == 'ajax';
  19. // If we do any form rendering, it's to completely replace a form on the
  20. // page, so don't let it force our ids to change.
  21. if ($js && isset($_POST['ajax_html_ids'])) {
  22. unset($_POST['ajax_html_ids']);
  23. }
  24. if (module_exists('advanced_help') && !$js) {
  25. drupal_set_message(theme('advanced_help_topic', array(
  26. 'module' => 'page_manager',
  27. 'topic' => 'getting-started',
  28. 'type' => t('See the getting started guide for more information.'),
  29. )));
  30. }
  31. $tasks = page_manager_get_tasks_by_type('page');
  32. $pages = array('operations' => array(), 'tasks' => array());
  33. page_manager_get_pages($tasks, $pages);
  34. // Add lock icon to all locked tasks.
  35. global $user;
  36. ctools_include('object-cache');
  37. $locks = ctools_object_cache_test_objects('page_manager_page', $pages['tasks']);
  38. foreach ($locks as $task_name => $lock) {
  39. if ($lock->uid == $user->uid) {
  40. $pages['rows'][$task_name]['class'][] = ' page-manager-locked';
  41. $pages['rows'][$task_name]['title'] = t('This page is currently locked for editing by you. Nobody else may edit this page until these changes are saved or canceled.');
  42. }
  43. else {
  44. $pages['rows'][$task_name]['class'][] = ' page-manager-locked-other';
  45. $pages['rows'][$task_name]['title'] = t('This page is currently locked for editing by another user. You may not edit this page without breaking the lock.');
  46. }
  47. }
  48. $input = $_POST;
  49. // Respond to a reset command by clearing session and doing a drupal goto
  50. // back to the base URL.
  51. if (isset($input['op']) && $input['op'] == t('Reset')) {
  52. unset($_SESSION['page_manager']['#admin']);
  53. if (!$js) {
  54. drupal_goto($_GET['q']);
  55. }
  56. // clear everything but form id, form build id and form token:
  57. $keys = array_keys($input);
  58. foreach ($keys as $id) {
  59. if ($id != 'form_id' && $id != 'form_build_id' && $id != 'form_token') {
  60. unset($input[$id]);
  61. }
  62. }
  63. $replace_form = TRUE;
  64. }
  65. if (count($input) <= 1) {
  66. if (isset($_SESSION['page_manager']['#admin']) && is_array($_SESSION['page_manager']['#admin'])) {
  67. $input = $_SESSION['page_manager']['#admin'];
  68. }
  69. }
  70. else {
  71. $_SESSION['page_manager']['#admin'] = $input;
  72. unset($_SESSION['page_manager']['#admin']['q']);
  73. }
  74. $form_state = array(
  75. 'pages' => &$pages,
  76. 'input' => $input,
  77. 'rerender' => TRUE,
  78. 'no_redirect' => TRUE,
  79. );
  80. // This form will sort and filter the pages.
  81. $form = drupal_build_form('page_manager_list_pages_form', $form_state);
  82. $header = array(
  83. array('data' => t('Type'), 'class' => array('page-manager-page-type')),
  84. array('data' => t('Module'), 'class' => array('page-manager-page-module')),
  85. array('data' => t('Name'), 'class' => array('page-manager-page-name')),
  86. array('data' => t('Title'), 'class' => array('page-manager-page-title')),
  87. array('data' => t('Path'), 'class' => array('page-manager-page-path')),
  88. array('data' => t('Storage'), 'class' => array('page-manager-page-storage')),
  89. );
  90. $header[] = array('data' => t('Operations'), 'class' => array('page-manager-page-operations'));
  91. $table = theme('table', array('header' => $header, 'rows' => $pages['rows'], 'attributes' => array('id' => 'page-manager-list-pages')));
  92. $operations = '<div id="page-manager-links" class="links">' . theme('links', array('links' => $pages['operations'])) . '</div>';
  93. drupal_add_css(drupal_get_path('module', 'page_manager') . '/css/page-manager.css');
  94. if (!$js) {
  95. return array('#markup' => drupal_render($form) . $table . $operations);
  96. }
  97. ctools_include('ajax');
  98. $commands = array();
  99. $commands[] = ajax_command_replace('#page-manager-list-pages', $table);
  100. if (!empty($replace_form)) {
  101. $commands[] = ajax_command_replace('#page-manager-list-pages-form', drupal_render($form));
  102. }
  103. print ajax_render($commands);
  104. ajax_footer();
  105. }
  106. /**
  107. * Sort tasks into buckets based upon whether or not they have subtasks.
  108. */
  109. function page_manager_get_pages($tasks, &$pages, $task_id = NULL) {
  110. foreach ($tasks as $id => $task) {
  111. if (empty($task_id) && !empty($task['page operations'])) {
  112. $pages['operations'] = array_merge($pages['operations'], $task['page operations']);
  113. }
  114. // If a type has subtasks, add its subtasks in its own table.
  115. if (!empty($task['subtasks'])) {
  116. page_manager_get_pages(page_manager_get_task_subtasks($task), $pages, $task['name']);
  117. continue;
  118. }
  119. if (isset($task_id)) {
  120. $task_name = page_manager_make_task_name($task_id, $task['name']);
  121. }
  122. else {
  123. $task_name = $task['name'];
  124. }
  125. $class = array('page-task-' . $id);
  126. if (isset($task['row class'])) {
  127. $class[] = $task['row class'];
  128. }
  129. if (!empty($task['disabled'])) {
  130. $class[] = 'page-manager-disabled';
  131. }
  132. $path = array();
  133. $visible_path = '';
  134. if (!empty($task['admin path'])) {
  135. foreach (explode('/', $task['admin path']) as $bit) {
  136. if (isset($bit[0]) && $bit[0] != '!') {
  137. $path[] = $bit;
  138. }
  139. }
  140. $path = implode('/', $path);
  141. if (empty($task['disabled']) && strpos($path, '%') === FALSE) {
  142. $visible_path = l('/' . $task['admin path'], $path);
  143. }
  144. else {
  145. $visible_path = '/' . $task['admin path'];
  146. }
  147. }
  148. $row = array('data' => array(), 'class' => $class, 'title' => strip_tags($task['admin description']));
  149. $type = isset($task['admin type']) ? $task['admin type'] : t('System');
  150. if (isset($task['module'])) {
  151. $module = $task['module'];
  152. }
  153. elseif (isset($task['subtask']->export_module)) {
  154. $module = $task['subtask']->export_module;
  155. }
  156. else {
  157. $module = '';
  158. }
  159. $pages['types'][$type] = $type;
  160. $row['data']['type'] = array('data' => $type, 'class' => array('page-manager-page-type'));
  161. $row['data']['module'] = array('data' => $module, 'class' => array('page-manager-page-module'));
  162. $row['data']['name'] = array('data' => $task_name, 'class' => array('page-manager-page-name'));
  163. $row['data']['title'] = array('data' => $task['admin title'], 'class' => array('page-manager-page-title'));
  164. $row['data']['path'] = array('data' => $visible_path, 'class' => array('page-manager-page-path'));
  165. $storage = isset($task['storage']) ? $task['storage'] : t('In code');
  166. $pages['storages'][$storage] = $storage;
  167. $row['data']['storage'] = array('data' => $storage, 'class' => array('page-manager-page-storage'));
  168. /*
  169. if (empty($task['disabled'])) {
  170. $item = menu_get_item($path);
  171. if (empty($item)) {
  172. dsm($path);
  173. }
  174. else {
  175. dsm($item);
  176. }
  177. }
  178. */
  179. $operations = array(
  180. array(
  181. 'title' => t('Edit'),
  182. 'href' => page_manager_edit_url($task_name),
  183. ),
  184. );
  185. if (!empty($task['enable callback'])) {
  186. if (!empty($task['disabled'])) {
  187. array_unshift($operations, array(
  188. 'title' => t('Enable'),
  189. 'href' => 'admin/structure/pages/nojs/enable/' . $task_name,
  190. 'query' => array('token' => drupal_get_token($task_name)),
  191. ));
  192. }
  193. else {
  194. $operations[] = array(
  195. 'title' => t('Disable'),
  196. 'href' => 'admin/structure/pages/nojs/disable/' . $task_name,
  197. 'query' => array('token' => drupal_get_token($task_name)),
  198. );
  199. }
  200. }
  201. $ops = theme('links__ctools_dropbutton', array('links' => $operations, 'attributes' => array('class' => array('links', 'inline'))));
  202. $row['data']['operations'] = array('data' => $ops, 'class' => array('page-manager-page-operations'));
  203. $pages['disabled'][$task_name] = !empty($task['disabled']);
  204. $pages['tasks'][] = $task_name;
  205. $pages['rows'][$task_name] = $row;
  206. }
  207. }
  208. /**
  209. * Provide a form for sorting and filtering the list of pages.
  210. */
  211. function page_manager_list_pages_form($form, &$form_state) {
  212. // This forces the form to *always* treat as submitted which is
  213. // necessary to make it work.
  214. if (empty($_POST)) {
  215. $form["#programmed"] = TRUE;
  216. }
  217. $form['#action'] = url('admin/structure/pages/nojs/', array('absolute' => TRUE));
  218. if (!variable_get('clean_url', FALSE)) {
  219. $form['q'] = array(
  220. '#type' => 'hidden',
  221. '#value' => $_GET['q'],
  222. );
  223. }
  224. $all = array('all' => t('<All>'));
  225. $form['type'] = array(
  226. '#type' => 'select',
  227. '#title' => t('Type'),
  228. '#options' => $all + $form_state['pages']['types'],
  229. '#default_value' => 'all',
  230. );
  231. $form['storage'] = array(
  232. '#type' => 'select',
  233. '#title' => t('Storage'),
  234. '#options' => $all + $form_state['pages']['storages'],
  235. '#default_value' => 'all',
  236. );
  237. $form['disabled'] = array(
  238. '#type' => 'select',
  239. '#title' => t('Enabled'),
  240. '#options' => $all + array('0' => t('Enabled'), '1' => t('Disabled')),
  241. '#default_value' => 'all',
  242. );
  243. $form['search'] = array(
  244. '#type' => 'textfield',
  245. '#title' => t('Search'),
  246. );
  247. $form['order'] = array(
  248. '#type' => 'select',
  249. '#title' => t('Sort by'),
  250. '#options' => array(
  251. 'disabled' => t('Enabled, title'),
  252. 'title' => t('Title'),
  253. 'name' => t('Name'),
  254. 'path' => t('Path'),
  255. 'type' => t('Type'),
  256. 'storage' => t('Storage'),
  257. ),
  258. '#default_value' => 'disabled',
  259. );
  260. $form['sort'] = array(
  261. '#type' => 'select',
  262. '#title' => t('Order'),
  263. '#options' => array(
  264. 'asc' => t('Up'),
  265. 'desc' => t('Down'),
  266. ),
  267. '#default_value' => 'asc',
  268. );
  269. $form['submit'] = array(
  270. '#name' => '', // so it won't in the $_GET args
  271. '#type' => 'submit',
  272. '#id' => 'edit-pages-apply',
  273. '#value' => t('Apply'),
  274. '#attributes' => array('class' => array('use-ajax-submit ctools-auto-submit-click')),
  275. );
  276. $form['reset'] = array(
  277. '#type' => 'submit',
  278. '#id' => 'edit-pages-reset',
  279. '#value' => t('Reset'),
  280. '#attributes' => array('class' => array('use-ajax-submit')),
  281. );
  282. $form['#attached']['js'] = array(ctools_attach_js('auto-submit'), ctools_attach_js('page-list', 'page_manager'));
  283. $form['#attached']['library'][] = array('system', 'drupal.ajax');
  284. $form['#attached']['library'][] = array('system', 'jquery.form');
  285. $form['#prefix'] = '<div class="clearfix">';
  286. $form['#suffix'] = '</div>';
  287. $form['#attributes'] = array('class' => array('ctools-auto-submit-full-form'));
  288. return $form;
  289. }
  290. /**
  291. * Accept submission from the page manager sort/filter form and apply it
  292. * to the list of pages.
  293. */
  294. function page_manager_list_pages_form_submit(&$form, &$form_state) {
  295. // Filter and re-sort the pages.
  296. // This is a copy.
  297. $rows = $form_state['pages']['rows'];
  298. $sorts = array();
  299. foreach ($rows as $name => $data) {
  300. // Filter
  301. if ($form_state['values']['type'] != 'all' && $form_state['values']['type'] != $data['data']['type']['data']) {
  302. continue;
  303. }
  304. if ($form_state['values']['storage'] != 'all' && $form_state['values']['storage'] != $data['data']['storage']['data']) {
  305. continue;
  306. }
  307. if ($form_state['values']['disabled'] != 'all' && $form_state['values']['disabled'] != $form_state['pages']['disabled'][$name]) {
  308. continue;
  309. }
  310. if ($form_state['values']['search'] &&
  311. strpos($data['data']['name']['data'], $form_state['values']['search']) === FALSE &&
  312. strpos($data['data']['path']['data'], $form_state['values']['search']) === FALSE &&
  313. strpos($data['data']['title']['data'], $form_state['values']['search']) === FALSE) {
  314. continue;
  315. }
  316. // Set up sorting
  317. switch ($form_state['values']['order']) {
  318. case 'disabled':
  319. $sorts[$name] = !$form_state['pages']['disabled'][$name] . $data['data']['title']['data'];
  320. break;
  321. case 'title':
  322. $sorts[$name] = $data['data']['title']['data'];
  323. break;
  324. case 'name':
  325. $sorts[$name] = $data['data']['name']['data'];
  326. break;
  327. case 'path':
  328. $sorts[$name] = $data['data']['path']['data'];
  329. break;
  330. case 'type':
  331. $sorts[$name] = $data['data']['type']['data'];
  332. break;
  333. case 'storage':
  334. $sorts[$name] = $data['data']['storage']['data'];
  335. break;
  336. }
  337. }
  338. // Now actually sort
  339. if ($form_state['values']['sort'] == 'desc') {
  340. arsort($sorts);
  341. }
  342. else {
  343. asort($sorts);
  344. }
  345. // Nuke the original.
  346. $form_state['pages']['rows'] = array();
  347. // And restore.
  348. foreach ($sorts as $name => $title) {
  349. $form_state['pages']['rows'][$name] = $rows[$name];
  350. }
  351. }
  352. /**
  353. * Render the edit page for a a page, custom or system.
  354. */
  355. function page_manager_edit_page($page) {
  356. drupal_set_title($page->subtask['admin title'], PASS_THROUGH);
  357. // Provide and process the save page form before anything else.
  358. $form_state = array('page' => &$page);
  359. $built_form = drupal_build_form('page_manager_save_page_form', $form_state);
  360. $form = drupal_render($built_form);
  361. $operations = page_manager_get_operations($page);
  362. $args = array('summary');
  363. $rendered_operations = page_manager_render_operations($page, $operations, $args, array('class' => array('operations-main')), 'nav');
  364. $content = page_manager_get_operation_content(FALSE, $page, $args, $operations);
  365. $output = theme('page_manager_edit_page', array('page' => $page, 'save' => $form, 'operations' => $rendered_operations, 'content' => $content));
  366. return array('#markup' => $output);
  367. }
  368. /**
  369. * Entry point to edit a single operation for a page.
  370. *
  371. * @param $js
  372. * Whether or not the page was called via javascript.
  373. * @param $page
  374. * The cached page that is being edited.
  375. * @param ...
  376. * A number of items used to drill down into the actual operation called.
  377. */
  378. function page_manager_edit_page_operation() {
  379. $args = func_get_args();
  380. $js = array_shift($args);
  381. $page = array_shift($args);
  382. $operations = page_manager_get_operations($page);
  383. $content = page_manager_get_operation_content($js, $page, $args, $operations);
  384. // If the operation requested we go somewhere else afterward, oblige it.
  385. if (isset($content['new trail'])) {
  386. $args = $content['new trail'];
  387. // Get operations again, for the operation may have changed their availability.
  388. $operations = page_manager_get_operations($page);
  389. $content = page_manager_get_operation_content($js, $page, $args, $operations);
  390. }
  391. // Rendering the content may have been a form submission that changed the
  392. // operations, such as renaming or adding a handler. Thus we get a new set
  393. // of operations.
  394. $operations = page_manager_get_operations($page);
  395. $rendered_operations = page_manager_render_operations($page, $operations, $args, array('class' => array('operations-main')), 'nav');
  396. // Since this form should never be submitted to this page, process it late so
  397. // that we can be sure it notices changes.
  398. $form_state = array('page' => &$page);
  399. $built_form = drupal_build_form('page_manager_save_page_form', $form_state);
  400. $form = drupal_render($built_form);
  401. $output = theme('page_manager_edit_page', array('page' => $page, 'save' => $form, 'operations' => $rendered_operations, 'content' => $content));
  402. if ($js) {
  403. $commands = array();
  404. $commands[] = ajax_command_replace('#page-manager-edit', $output);
  405. print ajax_render($commands);
  406. ajax_footer();
  407. return;
  408. }
  409. drupal_set_title($page->subtask['admin title'], PASS_THROUGH);
  410. return $output;
  411. }
  412. /**
  413. * Take the operations array from a task and expand it.
  414. *
  415. * This allows some of the operations to be dynamic, based upon settings
  416. * on the task or the task's handlers. Each operation should have a type. In
  417. * addition to all the types allowed in page_manager_render_operations, these
  418. * types will be dynamically replaced with something else:
  419. * - 'handlers': An automatically created group that contains all the task's
  420. * handlers and appropriate links.
  421. * - 'function': A callback (which will be placed in the 'function' parameter
  422. * that should return an array of operations. This can be used to provide
  423. * additional, dynamic links if needed.
  424. */
  425. function page_manager_get_operations($page, $operations = NULL) {
  426. if (!isset($operations)) {
  427. // All tasks have at least these 2 ops:
  428. $operations = array(
  429. 'summary' => array(
  430. 'title' => t('Summary'),
  431. 'description' => t('Get a summary of the information about this page.'),
  432. 'path' => 'admin/structure/pages/edit',
  433. 'ajax' => FALSE,
  434. 'no operations' => TRUE,
  435. 'form info' => array(
  436. 'no buttons' => TRUE,
  437. ),
  438. 'form' => 'page_manager_page_summary',
  439. ),
  440. 'actions' => array(
  441. 'type' => 'group',
  442. 'title' => '',
  443. 'class' => array('operations-actions'),
  444. 'location' => 'primary',
  445. 'children' => array(),
  446. ),
  447. );
  448. if (isset($page->subtask['operations'])) {
  449. $operations += $page->subtask['operations'];
  450. // add actions separately.
  451. if (!empty($page->subtask['operations']['actions'])) {
  452. $operations['actions']['children'] += $page->subtask['operations']['actions']['children'];
  453. }
  454. }
  455. $operations['handlers'] = array('type' => 'handlers');
  456. }
  457. $result = array();
  458. foreach ($operations as $id => $operation) {
  459. if (empty($operation['type'])) {
  460. $operation['type'] = 'operation';
  461. }
  462. switch ($operation['type']) {
  463. case 'handlers':
  464. $result[$id] = page_manager_get_handler_operations($page);
  465. break;
  466. case 'function':
  467. if (function_exists($operation['function'])) {
  468. $retval = $function($page, $operation);
  469. if (is_array($retval)) {
  470. $result[$id] = $retval;
  471. }
  472. }
  473. break;
  474. default:
  475. $result[$id] = $operation;
  476. }
  477. }
  478. if (!empty($page->subtask['enable callback']) && !empty($page->subtask['disabled']) && empty($result['actions']['children']['enable'])) {
  479. $result['actions']['children']['enable'] = array(
  480. 'title' => t('Enable'),
  481. 'description' => t('Activate this page so that it will be in use in your system.'),
  482. 'form' => 'page_manager_enable_form',
  483. 'ajax' => FALSE,
  484. 'silent' => TRUE,
  485. 'no update and save' => TRUE,
  486. 'form info' => array(
  487. 'finish text' => t('Enable'),
  488. ),
  489. );
  490. }
  491. if (!empty($page->subtask['enable callback']) && empty($page->subtask['disabled']) && empty($result['actions']['children']['disable'])) {
  492. $result['actions']['children']['disable'] = array(
  493. 'title' => t('Disable'),
  494. 'description' => t('De-activate this page. The data will remain but the page will not be in use on your system.'),
  495. 'form' => 'page_manager_disable_form',
  496. 'ajax' => FALSE,
  497. 'silent' => TRUE,
  498. 'no update and save' => TRUE,
  499. 'form info' => array(
  500. 'finish text' => t('Disable'),
  501. ),
  502. );
  503. }
  504. $result['actions']['children']['add'] = array(
  505. 'title' => t('Add variant'),
  506. 'description' => t('Add a new variant to this page.'),
  507. 'form' => 'page_manager_handler_add',
  508. 'ajax' => FALSE,
  509. 'silent' => TRUE, // prevents a message about updating and prevents this item from showing as changed.
  510. 'no update and save' => TRUE, // get rid of update and save button which is bad here.
  511. 'form info' => array(
  512. 'finish text' => t('Create variant'),
  513. ),
  514. );
  515. // Restrict variant import due to security implications.
  516. if (user_access('use ctools import')) {
  517. $result['actions']['children']['import'] = array(
  518. 'title' => t('Import variant'),
  519. 'description' => t('Add a new variant to this page from code exported from another page.'),
  520. 'form' => 'page_manager_handler_import',
  521. );
  522. }
  523. if (count($page->handlers) > 1) {
  524. $result['actions']['children']['rearrange'] = array(
  525. 'title' => t('Reorder variants'),
  526. 'ajax' => FALSE,
  527. 'description' => t('Change the priority of the variants to ensure that the right one gets selected.'),
  528. 'form' => 'page_manager_handler_rearrange',
  529. );
  530. }
  531. // This is a special operation used to configure a new task handler before
  532. // it is added.
  533. if (isset($page->new_handler)) {
  534. $plugin = page_manager_get_task_handler($page->new_handler->handler);
  535. $result['actions']['children']['configure'] = array(
  536. 'title' => t('Configure'),
  537. 'description' => t('Configure a newly created variant prior to actually adding it to the page.'),
  538. 'ajax' => FALSE,
  539. 'no update and save' => TRUE, // get rid of update and save button which is bad here.
  540. 'form info' => array(
  541. // We use our own cancel and finish callback to handle the fun stuff.
  542. 'finish callback' => 'page_manager_handler_add_finish',
  543. 'cancel callback' => 'page_manager_handler_add_cancel',
  544. 'show trail' => TRUE,
  545. 'show back' => TRUE,
  546. 'finish text' => t('Create variant'),
  547. ),
  548. 'form' => array(
  549. 'forms' => $plugin['forms'],
  550. ),
  551. );
  552. foreach ($page->forms as $id) {
  553. if (isset($plugin['add features'][$id])) {
  554. $result['actions']['children']['configure']['form']['order'][$id] = $plugin['add features'][$id];
  555. }
  556. else if (isset($plugin['required forms'][$id])) {
  557. $result['actions']['children']['configure']['form']['order'][$id] = $plugin['required forms'][$id];
  558. }
  559. }
  560. }
  561. if ($page->locked) {
  562. $result['actions']['children']['break-lock'] = array(
  563. 'title' => t('Break lock'),
  564. 'description' => t('Break the lock on this page so that you can edit it.'),
  565. 'form' => 'page_manager_break_lock',
  566. 'ajax' => FALSE,
  567. 'no update and save' => TRUE, // get rid of update and save button which is bad here.
  568. 'form info' => array(
  569. 'finish text' => t('Break lock'),
  570. ),
  571. 'even locked' => TRUE, // show button even if locked
  572. 'silent' => TRUE,
  573. );
  574. }
  575. drupal_alter('page_manager_operations', $result, $page);
  576. return $result;
  577. }
  578. /**
  579. * Collect all the operations related to task handlers (variants) and
  580. * build a menu.
  581. */
  582. function page_manager_get_handler_operations(&$page) {
  583. ctools_include('export');
  584. $group = array(
  585. 'type' => 'group',
  586. 'class' => array('operations-handlers'),
  587. 'title' => t('Variants'),
  588. );
  589. $operations = array();
  590. // If there is only one variant, let's not have it collapsible.
  591. $collapsible = count($page->handler_info) != 1;
  592. foreach ($page->handler_info as $id => $info) {
  593. if ($info['changed'] & PAGE_MANAGER_CHANGED_DELETED) {
  594. continue;
  595. }
  596. $handler = $page->handlers[$id];
  597. $plugin = page_manager_get_task_handler($handler->handler);
  598. $operations[$id] = array(
  599. 'type' => 'group',
  600. 'class' => array('operations-handlers-' . $id),
  601. 'title' => page_manager_get_handler_title($plugin, $handler, $page->task, $page->subtask_id),
  602. 'collapsible' => $collapsible,
  603. 'children' => array(),
  604. );
  605. $operations[$id]['children']['actions'] = array(
  606. 'type' => 'group',
  607. 'class' => array('operations-handlers-actions-' . $id),
  608. 'title' => t('Variant operations'),
  609. 'children' => array(),
  610. 'location' => $id,
  611. );
  612. // There needs to be a 'summary' item here for variants.
  613. $operations[$id]['children']['summary'] = array(
  614. 'title' => t('Summary'),
  615. 'description' => t('Get a summary of the information about this variant.'),
  616. 'form info' => array(
  617. 'no buttons' => TRUE,
  618. ),
  619. 'form' => 'page_manager_handler_summary',
  620. );
  621. if ($plugin && isset($plugin['operations'])) {
  622. $operations[$id]['children'] += $plugin['operations'];
  623. }
  624. $actions = &$operations[$id]['children']['actions']['children'];
  625. $actions['clone'] = array(
  626. 'title' => t('Clone'),
  627. 'description' => t('Make an exact copy of this variant.'),
  628. 'form' => 'page_manager_handler_clone',
  629. );
  630. $actions['export'] = array(
  631. 'title' => t('Export'),
  632. 'description' => t('Export this variant into code to import into another page.'),
  633. 'form' => 'page_manager_handler_export',
  634. );
  635. if ($handler->export_type == (EXPORT_IN_CODE | EXPORT_IN_DATABASE)) {
  636. $actions['delete'] = array(
  637. 'title' => t('Revert'),
  638. 'description' => t('Remove all changes to this variant and revert to the version in code.'),
  639. 'form' => 'page_manager_handler_delete',
  640. 'no update and save' => TRUE,
  641. 'form info' => array(
  642. 'finish text' => t('Revert'),
  643. ),
  644. );
  645. }
  646. else if ($handler->export_type != EXPORT_IN_CODE) {
  647. $actions['delete'] = array(
  648. 'title' => t('Delete'),
  649. 'description' => t('Remove this variant from the page completely.'),
  650. 'form' => 'page_manager_handler_delete',
  651. 'form info' => array(
  652. 'finish text' => t('Delete'),
  653. 'save text' => t('Delete and save'),
  654. ),
  655. );
  656. }
  657. if (!empty($handler->disabled)) {
  658. $actions['enable'] = array(
  659. 'title' => t('Enable'),
  660. 'description' => t('Activate this variant so that it will be in use in your system.'),
  661. 'form' => 'page_manager_handler_enable',
  662. 'silent' => TRUE,
  663. 'form info' => array(
  664. 'finish text' => t('Enable'),
  665. 'save text' => t('Enable and save'),
  666. ),
  667. );
  668. }
  669. else {
  670. $actions['disable'] = array(
  671. 'title' => t('Disable'),
  672. 'description' => t('De-activate this variant. The data will remain but the variant will not be in use on your system.'),
  673. 'form' => 'page_manager_handler_disable',
  674. 'silent' => TRUE,
  675. 'form info' => array(
  676. 'finish text' => t('Disable'),
  677. 'save text' => t('Disable and save'),
  678. ),
  679. );
  680. }
  681. drupal_alter('page_manager_variant_operations', $operations[$id], $handler);
  682. }
  683. if (empty($operations)) {
  684. $operations['empty'] = array(
  685. 'type' => 'text',
  686. 'title' => t('No variants'),
  687. );
  688. }
  689. $group['children'] = $operations;
  690. return $group;
  691. }
  692. /**
  693. * Get an operation from a trail.
  694. *
  695. * @return array($operation, $active, $args)
  696. */
  697. function page_manager_get_operation($operations, $trail) {
  698. $args = $trail;
  699. $stop = FALSE;
  700. $active = array();
  701. $titles = array();
  702. // Drill down into operations array:
  703. while (!$stop) {
  704. $check = reset($args);
  705. $stop = TRUE;
  706. if (is_array($operations)) {
  707. if (isset($operations[$check])) {
  708. $active[] = $check;
  709. $operation = array_shift($args);
  710. // check to see if this operation has children. If so, we continue.
  711. if (!isset($operations[$check]['children'])) {
  712. $operations = $operations[$check];
  713. }
  714. else {
  715. $titles[] = $operations[$check]['title'];
  716. $operations = $operations[$check]['children'];
  717. // continue only if the operation hs children.
  718. $stop = FALSE;
  719. }
  720. }
  721. }
  722. }
  723. return array($operations, $active, $args, $titles);
  724. }
  725. /**
  726. * Fetch the content for an operation.
  727. *
  728. * First, this drills down through the arguments to find the operation, and
  729. * turns whatever it finds into the active trail which is then used to
  730. * hilite where we are when rendering the operation list.
  731. *
  732. * The arguments are discovered from the URL, and are an exact match for where
  733. * the operation is in the hierarchy. For example, handlers/foo/settings will
  734. * be the operation to edit the settings for the handler named foo. This comes
  735. * in as an array ('handlers', 'foo', 'settings') and is used to find where the
  736. * data for that operation is in the array.
  737. */
  738. function page_manager_get_operation_content($js, &$page, $trail, $operations) {
  739. list($operation, $active, $args, $titles) = page_manager_get_operation($operations, $trail);
  740. // Once we've found the operation, send it off to render.
  741. if ($operation) {
  742. $content = _page_manager_get_operation_content($js, $page, $active, $operation, $titles, $args);
  743. }
  744. if (empty($content)) {
  745. $content = _page_manager_get_operation_content($js, $page, array('summary'), $operations['summary']);
  746. }
  747. return $content;
  748. }
  749. /**
  750. * Fetch the content for an operation, after it's been discovered from arguments.
  751. *
  752. * This system runs through the CTools form wizard. Each operation specifies a form
  753. * or set of forms that it may use. Operations may also specify wrappers and can
  754. * set their own next/finish handlers so that they can make additional things happen
  755. * at the end.
  756. */
  757. function _page_manager_get_operation_content($js, &$page, $active, $operation, $titles = array(), $args = array()) {
  758. if (isset($operation['form'])) {
  759. $form_info = array(
  760. 'id' => 'page_manager_page',
  761. 'finish text' => t('Update'),
  762. 'show trail' => FALSE,
  763. 'show back' => FALSE,
  764. 'show return' => FALSE,
  765. 'show cancel' => FALSE,
  766. 'next callback' => 'page_manager_edit_page_next',
  767. 'finish callback' => 'page_manager_edit_page_finish',
  768. // Items specific to the 'edit' routines that will get moved over:
  769. 'path' => page_manager_edit_url($page->task_name, $active) . "/%step",
  770. // wrapper function to add an extra finish button.
  771. 'wrapper' => 'page_manager_operation_wrapper',
  772. );
  773. // If $operation['form'] is simply a string, then it is the function
  774. // name of the form.
  775. if (!is_array($operation['form'])) {
  776. $form_info['order'] = array(
  777. 'form' => $operation['title'],
  778. );
  779. $form_info['forms'] = array(
  780. 'form' => array('form id' => $operation['form']),
  781. );
  782. if (isset($operation['wrapper'])) {
  783. $form_info['forms']['form']['wrapper'] = $operation['wrapper'];
  784. }
  785. }
  786. // Otherwise it's the order and forms arrays directly.
  787. else {
  788. $form_info['order'] = $operation['form']['order'];
  789. $form_info['forms'] = $operation['form']['forms'];
  790. }
  791. // Allow the operation to override any form info settings:
  792. if (isset($operation['form info'])) {
  793. foreach ($operation['form info'] as $key => $setting) {
  794. $form_info[$key] = $setting;
  795. }
  796. }
  797. if (!empty($page->subtask['operations include'])) {
  798. // Quickly load any files necessary to display the forms.
  799. $page->subtask['operations include']['function'] = 'nop';
  800. ctools_plugin_get_function($page->subtask, 'operations include');
  801. }
  802. $step = array_shift($args);
  803. // If step is unset, go with the basic step.
  804. if (!isset($step)) {
  805. $step = current(array_keys($form_info['order']));
  806. }
  807. // If it is locked, hide the buttonzzz!
  808. if ($page->locked && empty($operation['even locked'])) {
  809. $form_info['no buttons'] = TRUE;
  810. }
  811. ctools_include('wizard');
  812. $form_state = array(
  813. 'page' => $page,
  814. 'type' => 'edit',
  815. 'ajax' => $js && (!isset($operation['ajax']) || !empty($operation['ajax'])),
  816. 'rerender' => TRUE,
  817. 'trail' => $active,
  818. 'task_name' => $page->task_name,
  819. 'task_id' => $page->task_id,
  820. 'task' => $page->task,
  821. 'subtask_id' => $page->subtask_id,
  822. 'subtask' => $page->subtask,
  823. 'operation' => $operation,
  824. );
  825. if ($active && $active[0] == 'handlers' && isset($form_state['page']->handlers[$form_state['trail'][1]])) {
  826. $form_state['handler_id'] = $form_state['trail'][1];
  827. $form_state['handler'] = &$form_state['page']->handlers[$form_state['handler_id']];
  828. }
  829. if ($active && $active[0] == 'actions' && $active[1] == 'configure' && isset($form_state['page']->new_handler)) {
  830. $form_state['handler_id'] = $form_state['page']->new_handler->name;
  831. $form_state['handler'] = &$form_state['page']->new_handler;
  832. }
  833. $built_form = ctools_wizard_multistep_form($form_info, $step, $form_state);
  834. $output = drupal_render($built_form);
  835. $title = empty($form_state['title']) ? $operation['title'] : $form_state['title'];
  836. $titles[] = $title;
  837. $title = implode(' &raquo; ', array_filter($titles));
  838. // If there are messages for the form, render them.
  839. if ($messages = theme('status_messages')) {
  840. $output = $messages . $output;
  841. }
  842. $description = isset($operation['admin description']) ? $operation['admin description'] : (isset($operation['description']) ? $operation['description'] : '');
  843. $return = array(
  844. 'title' => $title,
  845. 'content' => $output,
  846. 'description' => $description,
  847. );
  848. // Append any extra content, used for the preview which is submitted then
  849. // rendered.
  850. if (isset($form_state['content'])) {
  851. $return['content'] .= $form_state['content'];
  852. }
  853. // If the form wanted us to go somewhere else next, pass that along.
  854. if (isset($form_state['new trail'])) {
  855. $return['new trail'] = $form_state['new trail'];
  856. }
  857. }
  858. else {
  859. $return = array(
  860. 'title' => t('Error'),
  861. 'content' => t('This operation trail does not exist.'),
  862. );
  863. }
  864. $return['active'] = $active;
  865. return $return;
  866. }
  867. function page_manager_operation_wrapper($form, &$form_state) {
  868. if (empty($form_state['operation']['no update and save']) && !empty($form['buttons']['return']['#wizard type']) && $form['buttons']['return']['#wizard type']) {
  869. $form['buttons']['save'] = array(
  870. '#type' => 'submit',
  871. '#value' => !empty($form_state['form_info']['save text']) ? $form_state['form_info']['save text'] : t('Update and save'),
  872. '#wizard type' => 'finish',
  873. '#attributes' => $form['buttons']['return']['#attributes'],
  874. '#save' => TRUE,
  875. );
  876. }
  877. return $form;
  878. }
  879. /**
  880. * Callback generated when the an operation edit finished.
  881. */
  882. function page_manager_edit_page_finish(&$form_state) {
  883. if (empty($form_state['operation']['silent'])) {
  884. if (empty($form_state['clicked_button']['#save'])) {
  885. drupal_set_message(t('The page has been updated. Changes will not be permanent until you save.'));
  886. }
  887. else {
  888. drupal_set_message(t('The page has been updated and saved.'));
  889. }
  890. $path = array();
  891. foreach ($form_state['trail'] as $operation) {
  892. $path[] = $operation;
  893. $form_state['page']->changes[implode('/', $path)] = TRUE;
  894. }
  895. }
  896. // If a handler was modified, set it to changed so we know to overwrite it.
  897. if (isset($form_state['handler_id'])) {
  898. $form_state['page']->handler_info[$form_state['handler_id']]['changed'] |= PAGE_MANAGER_CHANGED_CACHED;
  899. }
  900. // While we make buttons go away on locked pages, it is still possible to
  901. // have a lock a appear while you were editing, and have your changes
  902. // disappear. This at least warns the user that this has happened.
  903. if (!empty($page->locked)) {
  904. drupal_set_message(t('Unable to update changes due to lock.'));
  905. }
  906. // If the 'Update and Save' button was selected, write our cache out.
  907. if (!empty($form_state['clicked_button']['#save'])) {
  908. page_manager_save_page_cache($form_state['page']);
  909. page_manager_clear_page_cache($form_state['page']->task_name);
  910. $form_state['page'] = page_manager_get_page_cache($form_state['page']->task_name);
  911. }
  912. else {
  913. if (empty($form_state['do not cache'])) {
  914. page_manager_set_page_cache($form_state['page']);
  915. }
  916. }
  917. // We basically always want to force a rerender when the forms
  918. // are finished, so make sure there is a new trail.
  919. if (empty($form_state['new trail'])) {
  920. // force a rerender to get rid of old form items that may have changed
  921. // during save.
  922. $form_state['new trail'] = $form_state['trail'];
  923. }
  924. if (isset($form_state['new trail']) && empty($form_state['ajax'])) {
  925. $form_state['redirect'] = page_manager_edit_url($form_state['page']->task_name, $form_state['new trail']);
  926. }
  927. $form_state['complete'] = TRUE;
  928. }
  929. /**
  930. * Callback generated when the 'next' button is clicked.
  931. *
  932. * All we do here is store the cache.
  933. */
  934. function page_manager_edit_page_next(&$form_state) {
  935. page_manager_set_page_cache($form_state['page']);
  936. }
  937. /**
  938. * Callback generated when the 'cancel' button is clicked.
  939. *
  940. * All we do here is clear the cache.
  941. */
  942. function page_manager_edit_page_cancel(&$form_state) {
  943. $page = $form_state['page'];
  944. }
  945. /**
  946. * Render an operations array.
  947. *
  948. * This renders an array of operations into a series of nested UL statements,
  949. * with ajax automatically on unless specified otherwise. Operations will
  950. * automatically have the URLs generated nested.
  951. *
  952. * Each operation should have a 'type', which tells the renderer how to deal
  953. * with it:
  954. * - 'operation': An AJAX link to render. This is the default and is
  955. * assumed if a type is not specified. Other fields for the operation:
  956. * - - 'title': The text to display. Can be an image. Must be pre-sanitized.
  957. * - - 'description': Text to place in the hover box over the link using the
  958. * title attribute.
  959. * - - 'arguments': Anything optional to put at the end of the URL.
  960. * - - 'path': If set, overrides the default path.
  961. * - - 'no operations': If set, the path will not have operations appended.
  962. * - - 'no task': If set, the path will not have the task id.
  963. * - - 'no link': If set, this item will just be text, not a link.
  964. * - - 'ajax': If set to TRUE, ajax will be used. The default is TRUE.
  965. * - - 'class': An optional class to specify for the link.
  966. * - - 'form': The form to display for this operation, if using a single form.
  967. * - - 'forms': An array of forms that must be paired with 'order' of this
  968. * operation uses multiple forms. See wizard tool for details.
  969. * - - 'order': The form order to use for multiple forms. See wizard tool for
  970. * details.
  971. * - - 'form info': Form info overrides for the wizard. See the wizard tool
  972. * for available settings
  973. * - 'group':
  974. * - - 'title': The title of the link. May be HTML.
  975. * - - 'title class': A class to apply to the title.
  976. * - - 'children': An array of more operations that this group represents.
  977. * All operations within this group will have this group's ID as part
  978. * of the AJAX url to make it easier to find.
  979. * - - 'class': A class to apply to the UL of the children.
  980. * - - 'collapsible': If TRUE the collapsible tool will be used.
  981. */
  982. function page_manager_render_operations(&$page, $operations, $active_trail, $attributes, $location, $parents = array()) {
  983. drupal_add_library('system', 'drupal.ajax');
  984. if (!isset($output[$location])) {
  985. $output[$location] = '';
  986. }
  987. $keys = array_keys($operations);
  988. $first = array_shift($keys);
  989. $last = array_pop($keys);
  990. // Make sure the 'first' and 'last' operations are part of THIS nav tree:
  991. while ($keys && isset($operations[$first]['location']) && $operations[$first]['location'] != $location) {
  992. $first = array_shift($keys);
  993. }
  994. while ($keys && isset($operations[$last]['location']) && $operations[$last]['location'] != $location) {
  995. $last = array_pop($keys);
  996. }
  997. $active = reset($active_trail);
  998. foreach ($operations as $id => $operation) {
  999. $current_path = '';
  1000. if ($parents) {
  1001. $current_path .= implode('/', $parents) . '/';
  1002. }
  1003. $current_path .= $id;
  1004. if (empty($operation['type'])) {
  1005. $operation['type'] = 'operation';
  1006. }
  1007. // We only render an li for things in the same nav tree.
  1008. if (empty($operation['location']) || $operation['location'] == $location) {
  1009. if (!is_array($attributes['class'])) {
  1010. $attributes['class'] = array($attributes['class']);
  1011. }
  1012. $class = empty($attributes['class']) || !is_array($attributes['class']) ? array() : $attributes['class'];
  1013. if ($id == $first) {
  1014. $class[] = 'operation-first';
  1015. }
  1016. else if ($id == $last) {
  1017. $class[] = 'operation-last';
  1018. }
  1019. if (empty($operation['silent']) && !empty($page->changes[$current_path])) {
  1020. $class[] = $operation['type'] == 'group' ? 'changed-group' : 'changed';
  1021. }
  1022. else {
  1023. $class[] = 'not-changed';
  1024. }
  1025. if ($active == $id) {
  1026. $class[] = $operation['type'] == 'group' ? 'active-group' : 'active';
  1027. }
  1028. else {
  1029. $class[] = 'not-active';
  1030. }
  1031. $output[$location] .= '<li class="' . implode(' ', $class) . '">';
  1032. }
  1033. switch ($operation['type']) {
  1034. case 'text':
  1035. $output[$location] .= $operation['title'];
  1036. break;
  1037. case 'operation':
  1038. $path = isset($operation['path']) ? $operation['path'] : 'admin/structure/pages/nojs/operation';
  1039. if (!isset($operation['no task'])) {
  1040. $path .= '/' . $page->task_name;
  1041. }
  1042. if (!isset($operation['no operations'])) {
  1043. $path .= '/' . $current_path;
  1044. if (isset($operation['arguments'])) {
  1045. $path .= '/' . $arguments;
  1046. }
  1047. }
  1048. $class = array('page-manager-operation');
  1049. if (!isset($operation['ajax']) || !empty($operation['ajax'])) {
  1050. $class[] = 'use-ajax';
  1051. }
  1052. if (!empty($operation['class'])) {
  1053. $class[] = $operation['class'];
  1054. }
  1055. $description = isset($operation['description']) ? $operation['description'] : '';
  1056. if (empty($operation['silent']) && !empty($page->changes[$current_path])) {
  1057. $description .= ' ' . t('This setting contains unsaved changes.');
  1058. }
  1059. $output[$location] .= l($operation['title'], $path, array('attributes' => array('id' => 'page-manager-operation-' . $id, 'class' => $class, 'title' => $description), 'html' => TRUE));
  1060. break;
  1061. case 'group':
  1062. if ($active == $id) {
  1063. $trail = $active_trail;
  1064. array_shift($trail);
  1065. }
  1066. else {
  1067. $trail = array();
  1068. }
  1069. $group_location = isset($operation['location']) ? $operation['location'] : $location;
  1070. $temp = page_manager_render_operations($page, $operation['children'], $trail, $operation, $group_location, array_merge($parents, array($id)));
  1071. if ($temp) {
  1072. foreach ($temp as $id => $text) {
  1073. if (empty($output[$id])) {
  1074. $output[$id] = '';
  1075. }
  1076. $output[$id] .= $text;
  1077. }
  1078. }
  1079. break;
  1080. }
  1081. if (empty($operation['location']) || $operation['location'] == $location) {
  1082. $output[$location] .= '</li>';
  1083. }
  1084. }
  1085. if ($output[$location]) {
  1086. $classes = isset($attributes['class']) && is_array($attributes['class']) ? $attributes['class'] : array();
  1087. $classes[] = 'page-manager-operations';
  1088. $output[$location] = '<ul class="' . implode(' ', $classes) . '">' . $output[$location] . '</ul>';
  1089. if (!empty($attributes['title'])) {
  1090. $class = '';
  1091. if (isset($attributes['title class'])) {
  1092. $class = $attributes['title class'];
  1093. }
  1094. $title = '<div class="page-manager-group-title' . $class . '">' . $attributes['title'] . '</div>';
  1095. if (!empty($attributes['collapsible'])) {
  1096. $output[$location] = theme('ctools_collapsible', array('handle' => $title, 'content' => $output[$location], 'collapsed' => empty($active_trail)));
  1097. }
  1098. else {
  1099. $output[$location] = $title . $output[$location];
  1100. }
  1101. }
  1102. return $output;
  1103. }
  1104. }
  1105. /**
  1106. * Provide a simple form for saving the page manager info out of the cache.
  1107. */
  1108. function page_manager_save_page_form($form, &$form_state) {
  1109. if (!empty($form_state['page']->changed)) {
  1110. $form['markup'] = array(
  1111. '#markup' => '<div class="changed-notification">' . t('You have unsaved changes to this page. You must select Save to write them to the database, or Cancel to discard these changes. Please note that if you have changed any form, you must submit that form before saving.') . '</div>',
  1112. );
  1113. // Always make sure we submit back to the proper page.
  1114. $form['#action'] = url('admin/structure/pages/edit/' . $form_state['page']->task_name);
  1115. $form['save'] = array(
  1116. '#type' => 'submit',
  1117. '#value' => t('Save'),
  1118. '#submit' => array('page_manager_save_page_form_submit'),
  1119. );
  1120. $form['cancel'] = array(
  1121. '#type' => 'submit',
  1122. '#value' => t('Cancel'),
  1123. '#submit' => array('page_manager_save_page_form_cancel'),
  1124. );
  1125. return $form;
  1126. }
  1127. }
  1128. /**
  1129. * Save the page.
  1130. */
  1131. function page_manager_save_page_form_submit(&$form, &$form_state) {
  1132. page_manager_save_page_cache($form_state['page']);
  1133. }
  1134. /**
  1135. * Discard changes to the page.
  1136. */
  1137. function page_manager_save_page_form_cancel($form, &$form_state) {
  1138. drupal_set_message(t('All pending changes have been discarded, and the page is now unlocked.'));
  1139. page_manager_clear_page_cache($form_state['page']->task_name);
  1140. if (!empty($form_state['page']->new)) {
  1141. $form_state['redirect'] = 'admin/structure/pages';
  1142. }
  1143. }
  1144. // --------------------------------------------------------------------------
  1145. // Handler (variant) related forms.
  1146. /**
  1147. * Add a new task handler.
  1148. */
  1149. function page_manager_handler_add($form, &$form_state) {
  1150. // Get a list of possible task handlers for this task.
  1151. return page_manager_handler_add_form($form, $form_state);
  1152. }
  1153. /**
  1154. * Handler related forms.
  1155. */
  1156. function page_manager_handler_add_submit(&$form, &$form_state) {
  1157. $cache = $form_state['page'];
  1158. $plugin = page_manager_get_task_handler($form_state['values']['handler']);
  1159. // Create a new handler.
  1160. $handler = page_manager_new_task_handler($plugin);
  1161. if (!empty($form_state['values']['title'])) {
  1162. $handler->conf['title'] = $form_state['values']['title'];
  1163. }
  1164. else {
  1165. $handler->conf['title'] = $plugin['title'];
  1166. }
  1167. $handler->conf['name'] = $form_state['values']['name'];
  1168. $cache->new_handler = $handler;
  1169. // Figure out which forms to present them with
  1170. $cache->forms = array();
  1171. $features = $form_state['values']['features'];
  1172. if (isset($features[$form_state['values']['handler']])) {
  1173. $cache->forms = array_merge($cache->forms, array_keys(array_filter($features[$form_state['values']['handler']])));
  1174. }
  1175. if (isset($plugin['required forms'])) {
  1176. $cache->forms = array_merge($cache->forms, array_keys($plugin['required forms']));
  1177. }
  1178. $form_state['no_rerender'] = TRUE;
  1179. if (!empty($cache->forms)) {
  1180. // Tell the form to go to the config page.
  1181. drupal_set_message(t('Before this variant can be added, it must be configured. When you are finished, click "Create variant" at the end of this wizard to add this to your page.'));
  1182. $form_state['new trail'] = array('actions', 'configure');
  1183. }
  1184. else {
  1185. // It has no forms at all. Add the variant and go to its first operation.
  1186. page_manager_handler_add_finish($form_state);
  1187. }
  1188. }
  1189. /**
  1190. * Finish the add process and make the new handler official.
  1191. */
  1192. function page_manager_handler_add_finish(&$form_state) {
  1193. $page = &$form_state['page'];
  1194. $handler = $page->new_handler;
  1195. page_manager_handler_add_to_page($page, $handler);
  1196. // Remove the temporary page.
  1197. unset($page->new_handler);
  1198. unset($page->forms);
  1199. // Set the new destination
  1200. $plugin = page_manager_get_task_handler($handler->handler);
  1201. if (!empty($plugin['add finish'])) {
  1202. $location = $plugin['add finish'];
  1203. }
  1204. else {
  1205. $keys = array_keys($plugin['operations']);
  1206. $location = reset($keys);
  1207. }
  1208. $form_state['new trail'] = array('handlers', $handler->name, $location);
  1209. // Pass through.
  1210. page_manager_edit_page_finish($form_state);
  1211. }
  1212. /**
  1213. * Throw away a new handler and return to the add form
  1214. */
  1215. function page_manager_handler_add_cancel(&$form_state) {
  1216. $form_state['new trail'] = array('handlers', 'add');
  1217. // Remove the temporary page.
  1218. unset($page->new_handler);
  1219. unset($page->forms);
  1220. }
  1221. /**
  1222. * Provide a consistent UI for adding handlers.
  1223. */
  1224. function page_manager_handler_add_form($form, $form_state, $features = array()) {
  1225. $task = $form_state['task'];
  1226. $task_handler_plugins = page_manager_get_task_handler_plugins($task);
  1227. if (empty($task_handler_plugins)) {
  1228. drupal_set_message(t('There are currently no variants available and a page may not be added. Perhaps you need to install the Panels module to get a variant?'), 'error');
  1229. $form['buttons']['return']['#disabled'] = TRUE;
  1230. return;
  1231. }
  1232. foreach ($task_handler_plugins as $id => $plugin) {
  1233. $options[$id] = $plugin['title'];
  1234. if (isset($plugin['add features'])) {
  1235. $features[$id] = $plugin['add features'];
  1236. }
  1237. }
  1238. if (!isset($form_state['type']) || $form_state['type'] != 'add') {
  1239. $form['title'] = array(
  1240. '#type' => 'textfield',
  1241. '#title' => t('Title'),
  1242. '#description' => t('Administrative title of this variant. If you leave blank it will be automatically assigned.'),
  1243. );
  1244. $form['name'] = array(
  1245. '#type' => 'machine_name',
  1246. '#title' => t('Machine name'),
  1247. '#required' => FALSE,
  1248. '#description' => t("A unique machine-readable name for this variant. It must only contain lowercase letters, numbers, and underscores. This name will be used when exporting the variant. If left empty the variant's name will be used instead."),
  1249. '#size' => 32,
  1250. '#maxlength' => 32,
  1251. '#machine_name' => array(
  1252. 'exists' => 'page_manager_handler_check_machine_name',
  1253. 'source' => array('title'),
  1254. ),
  1255. '#field_prefix' => '<span dir="ltr">' . $form_state['task_name'] . '__',
  1256. '#field_suffix' => '</span>&lrm;',
  1257. );
  1258. }
  1259. $form['handler'] = array(
  1260. '#title' => t('Variant type'),
  1261. '#type' => 'select',
  1262. '#options' => $options,
  1263. );
  1264. // This set of checkboxes is not dangerous at all.
  1265. $form['features'] = array(
  1266. '#type' => 'item',
  1267. '#title' => t('Optional features'),
  1268. '#description' => t('Check any optional features you need to be presented with forms for configuring them. If you do not check them here you will still be able to utilize these features once the new page is created. If you are not sure, leave these unchecked.'),
  1269. '#tree' => TRUE,
  1270. );
  1271. ctools_include('dependent');
  1272. foreach ($features as $plugin => $feature_list) {
  1273. foreach ($feature_list as $feature_id => $feature) {
  1274. $form['features'][$plugin][$feature_id] = array(
  1275. '#type' => 'checkbox',
  1276. '#title' => $feature,
  1277. );
  1278. if (!empty($form_state['page']->forms) && in_array($feature_id, $form_state['page']->forms)) {
  1279. $form['features'][$plugin][$feature_id]['#default_value'] = TRUE;
  1280. }
  1281. if ($plugin != 'default') {
  1282. $form['features'][$plugin][$feature_id] += array(
  1283. '#dependency' => array('edit-handler' => array($plugin)),
  1284. );
  1285. }
  1286. }
  1287. }
  1288. return $form;
  1289. }
  1290. /*
  1291. * Check if handler's machine-name is unique
  1292. */
  1293. function page_manager_handler_check_machine_name($name, $element, $form_state) {
  1294. $name = $form_state['task_name'] . '__' . $name;
  1295. return count(ctools_export_load_object('page_manager_handlers', 'names', array($name)));
  1296. }
  1297. /**
  1298. * Rearrange the order of variants.
  1299. */
  1300. function page_manager_handler_import($form, &$form_state) {
  1301. $form['title'] = array(
  1302. '#type' => 'textfield',
  1303. '#title' => t('Variant name'),
  1304. '#description' => t('Enter the name of the new variant.'),
  1305. );
  1306. if (user_access('use ctools import')) {
  1307. $form['object'] = array(
  1308. '#type' => 'textarea',
  1309. '#title' => t('Paste variant code here'),
  1310. '#rows' => 15,
  1311. );
  1312. }
  1313. // Users ordinarily can't get here without the 'import' permission, due to
  1314. // security implications. In case they somehow do, though, disable the form
  1315. // widget for extra safety.
  1316. else {
  1317. $form['shoveoff'] = array(
  1318. '#markup' => '<div>' . t('You do not have sufficient permissions to perform this action.') . '</div>',
  1319. );
  1320. }
  1321. return $form;
  1322. }
  1323. /**
  1324. * Make sure that an import actually provides a handler.
  1325. */
  1326. function page_manager_handler_import_validate($form, &$form_state) {
  1327. if (!user_access('use ctools import')) {
  1328. form_error($form['shoveoff'], t('You account permissions do not permit you to import.'));
  1329. return;
  1330. }
  1331. ob_start();
  1332. eval($form_state['values']['object']);
  1333. ob_end_clean();
  1334. if (empty($handler)) {
  1335. $errors = ob_get_contents();
  1336. if (empty($errors)) {
  1337. $errors = t('No variant found.');
  1338. }
  1339. form_error($form['object'], t('Unable to get a variant from the import. Errors reported: @errors', array('@errors' => $errors)));
  1340. }
  1341. $form_state['handler'] = $handler;
  1342. }
  1343. /**
  1344. * Clone an existing task handler into a new handler.
  1345. */
  1346. function page_manager_handler_import_submit(&$form, &$form_state) {
  1347. $handler = $form_state['handler'];
  1348. page_manager_handler_add_to_page($form_state['page'], $handler, $form_state['values']['title']);
  1349. $plugin = page_manager_get_task_handler($handler->handler);
  1350. // It has no forms at all. Add the variant and go to its first operation.
  1351. $keys = array_keys($plugin['operations']);
  1352. $form_state['new trail'] = array('handlers', $handler->name, reset($keys));
  1353. }
  1354. /**
  1355. * Rearrange the order of variants.
  1356. */
  1357. function page_manager_handler_rearrange($form, &$form_state) {
  1358. ctools_include('context-task-handler');
  1359. $page = $form_state['page'];
  1360. $form['handlers'] = array('#tree' => TRUE);
  1361. foreach ($page->handler_info as $id => $info) {
  1362. if ($info['changed'] & PAGE_MANAGER_CHANGED_DELETED) {
  1363. continue;
  1364. }
  1365. $handler = $page->handlers[$id];
  1366. $plugin = page_manager_get_task_handler($handler->handler);
  1367. $object = ctools_context_handler_get_task_object($page->task, $page->subtask, $handler);
  1368. $display = new stdClass();
  1369. $display->context = ctools_context_load_contexts($object, TRUE);
  1370. $content = page_manager_get_handler_title($plugin, $handler, $page->task, $page->subtask_id);
  1371. $access = ctools_access_group_summary(!empty($handler->conf['access']) ? $handler->conf['access'] : array(), $display->context);
  1372. if ($access) {
  1373. $access = t('This panel will be selected if @conditions.', array('@conditions' => $access));
  1374. }
  1375. else {
  1376. $access = t('This panel will always be selected.');
  1377. }
  1378. $content .= '<div>' . $access . '</div>';
  1379. $form['handlers'][$id]['title'] = array(
  1380. '#markup' => $content,
  1381. );
  1382. $form['handlers'][$id]['weight'] = array(
  1383. '#type' => 'weight',
  1384. '#default_value' => $info['weight'],
  1385. '#delta' => 30,
  1386. );
  1387. }
  1388. return $form;
  1389. }
  1390. function page_manager_handler_rearrange_submit(&$form, &$form_state) {
  1391. $handler_info = &$form_state['page']->handler_info;
  1392. foreach ($form_state['values']['handlers'] as $id => $info) {
  1393. if ($handler_info[$id]['weight'] = $info['weight']) {
  1394. $handler_info[$id]['weight'] = $info['weight'];
  1395. $handler_info[$id]['changed'] |= PAGE_MANAGER_CHANGED_MOVED;
  1396. }
  1397. }
  1398. // Sort the new cache.
  1399. uasort($handler_info, '_page_manager_handler_sort');
  1400. }
  1401. /**
  1402. * Used as a callback to uasort to sort the task cache by weight.
  1403. *
  1404. * The 'name' field is used as a backup when weights are the same, which
  1405. * can happen when multiple modules put items out there at the same
  1406. * weight.
  1407. */
  1408. function _page_manager_handler_sort($a, $b) {
  1409. if ($a['weight'] < $b['weight']) {
  1410. return -1;
  1411. }
  1412. elseif ($a['weight'] > $b['weight']) {
  1413. return 1;
  1414. }
  1415. elseif ($a['name'] < $b['name']) {
  1416. return -1;
  1417. }
  1418. elseif ($a['name'] > $b['name']) {
  1419. return 1;
  1420. }
  1421. }
  1422. /**
  1423. * Rearrange the order of variants.
  1424. */
  1425. function page_manager_handler_delete($form, &$form_state) {
  1426. if ($form_state['handler']->type == t('Overridden')) {
  1427. $text = t('Reverting the variant will delete the variant that is in the database, reverting it to the original default variant. This deletion will not be made permanent until you click Save.');
  1428. }
  1429. else {
  1430. $text = t('Are you sure you want to delete this variant? This deletion will not be made permanent until you click Save.');
  1431. }
  1432. $form['markup'] = array(
  1433. '#markup' => '<p>' . $text . '</p>',
  1434. );
  1435. return $form;
  1436. }
  1437. /**
  1438. * Submit handler to delete a view.
  1439. */
  1440. function page_manager_handler_delete_submit(&$form, &$form_state) {
  1441. $form_state['page']->handler_info[$form_state['handler_id']]['changed'] |= PAGE_MANAGER_CHANGED_DELETED;
  1442. $form_state['new trail'] = array('summary');
  1443. }
  1444. /**
  1445. * Entry point to export a page.
  1446. */
  1447. function page_manager_handler_export($form, &$form_state) {
  1448. $export = page_manager_export_task_handler($form_state['handler']);
  1449. $lines = substr_count($export, "\n");
  1450. $form['code'] = array(
  1451. '#type' => 'textarea',
  1452. '#default_value' => $export,
  1453. '#rows' => $lines,
  1454. );
  1455. unset($form['buttons']);
  1456. return $form;
  1457. }
  1458. /**
  1459. * Rearrange the order of variants.
  1460. */
  1461. function page_manager_handler_clone($form, &$form_state) {
  1462. // This provides its own button because it does something totally different.
  1463. $form['title'] = array(
  1464. '#type' => 'textfield',
  1465. '#title' => t('Variant name'),
  1466. '#description' => t('Enter the name of the new variant.'),
  1467. );
  1468. return $form;
  1469. }
  1470. /**
  1471. * Clone an existing task handler into a new handler.
  1472. */
  1473. function page_manager_handler_clone_submit(&$form, &$form_state) {
  1474. $export = page_manager_export_task_handler($form_state['handler']);
  1475. ob_start();
  1476. eval($export);
  1477. ob_end_clean();
  1478. page_manager_handler_add_to_page($form_state['page'], $handler, $form_state['values']['title']);
  1479. $plugin = page_manager_get_task_handler($handler->handler);
  1480. // It has no forms at all. Add the variant and go to its first operation.
  1481. $keys = array_keys($plugin['operations']);
  1482. $form_state['new trail'] = array('handlers', $handler->name, reset($keys));
  1483. }
  1484. /**
  1485. * Form to enable a handler.
  1486. */
  1487. function page_manager_handler_enable($form, &$form_state) {
  1488. $form['markup'] = array(
  1489. '#markup' => t('This variant is currently disabled. Enabling it will make it available in your system. This will not take effect until you save this page.'),
  1490. );
  1491. return $form;
  1492. }
  1493. /**
  1494. * Enable the page after it has been confirmed.
  1495. */
  1496. function page_manager_handler_enable_submit(&$form, &$form_state) {
  1497. $form_state['handler']->disabled = FALSE;
  1498. $form_state['page']->handler_info[$form_state['handler_id']]['disabled'] = FALSE;
  1499. $form_state['page']->handler_info[$form_state['handler_id']]['changed'] |= PAGE_MANAGER_CHANGED_STATUS;
  1500. $form_state['new trail'] = array('handlers', $form_state['handler_id'], 'actions', 'disable');
  1501. }
  1502. /**
  1503. * Form to disable a page.
  1504. */
  1505. function page_manager_handler_disable($form, &$form_state) {
  1506. $form['markup'] = array(
  1507. '#markup' => t('This variant is currently enabled. Disabling it will make it unavailable in your system, and it will not be used. This will not take effect until you save this page.'),
  1508. );
  1509. return $form;
  1510. }
  1511. /**
  1512. * Form to disable a page.
  1513. */
  1514. function page_manager_handler_summary($form, &$form_state) {
  1515. $handler = $form_state['handler'];
  1516. $page = $form_state['page'];
  1517. $plugin = page_manager_get_task_handler($handler->handler);
  1518. $form['markup'] = array(
  1519. '#markup' => page_manager_get_handler_summary($plugin, $handler, $page, FALSE),
  1520. );
  1521. return $form;
  1522. }
  1523. /**
  1524. * Disable the page after it has been confirmed.
  1525. */
  1526. function page_manager_handler_disable_submit(&$form, &$form_state) {
  1527. $form_state['handler']->disabled = TRUE;
  1528. $form_state['page']->handler_info[$form_state['handler_id']]['disabled'] = TRUE;
  1529. $form_state['page']->handler_info[$form_state['handler_id']]['changed'] |= PAGE_MANAGER_CHANGED_STATUS;
  1530. $form_state['new trail'] = array('handlers', $form_state['handler_id'], 'actions', 'enable');
  1531. }
  1532. /**
  1533. * Break the lock on a page so that it can be edited.
  1534. */
  1535. function page_manager_break_lock($form, &$form_state) {
  1536. $form['markup'] = array(
  1537. '#markup' => t('Breaking the lock on this page will <strong>discard</strong> any pending changes made by the locking user. Are you REALLY sure you want to do this?')
  1538. );
  1539. return $form;
  1540. }
  1541. /**
  1542. * Submit to break the lock on a page.
  1543. */
  1544. function page_manager_break_lock_submit(&$form, &$form_state) {
  1545. $page = &$form_state['page'];
  1546. $form_state['page']->locked = FALSE;
  1547. ctools_object_cache_clear_all('page_manager_page', $page->task_name);
  1548. $form_state['do not cache'] = TRUE;
  1549. drupal_set_message(t('The lock has been cleared and all changes discarded. You may now make changes to this page.'));
  1550. $form_state['new trail'] = array('summary');
  1551. }
  1552. /**
  1553. * Form to enable a page.
  1554. */
  1555. function page_manager_enable_form($form, &$form_state) {
  1556. $form['markup'] = array(
  1557. '#markup' => t('Enabling this page will immediately make it available in your system (there is no need to wait for a save.)'),
  1558. );
  1559. return $form;
  1560. }
  1561. /**
  1562. * Enable the page after it has been confirmed.
  1563. */
  1564. function page_manager_enable_form_submit(&$form, &$form_state) {
  1565. $page = &$form_state['page'];
  1566. if ($function = ctools_plugin_get_function($page->subtask, 'enable callback')) {
  1567. $result = $function($page, FALSE);
  1568. menu_rebuild();
  1569. }
  1570. $form_state['new trail'] = array('actions', 'disable');
  1571. // We don't want to cause this to cache if it wasn't already. If it was
  1572. // cached, however, we want to update the enabled state.
  1573. if (empty($form_state['page']->changed)) {
  1574. $form_state['do not cache'] = TRUE;
  1575. }
  1576. }
  1577. /**
  1578. * Form to disable a page.
  1579. */
  1580. function page_manager_disable_form($form, &$form_state) {
  1581. $form['markup'] = array(
  1582. '#markup' => t('Disabling this page will immediately make it unavailable in your system (there is no need to wait for a save.)'),
  1583. );
  1584. return $form;
  1585. }
  1586. /**
  1587. * Disable the page after it has been confirmed.
  1588. */
  1589. function page_manager_disable_form_submit(&$form, &$form_state) {
  1590. $page = &$form_state['page'];
  1591. if ($function = ctools_plugin_get_function($page->subtask, 'enable callback')) {
  1592. $result = $function($page, TRUE);
  1593. menu_rebuild();
  1594. $form_state['new trail'] = array('actions', 'enable');
  1595. // We don't want to cause this to cache if it wasn't already. If it was
  1596. // cached, however, we want to update the enabled state.
  1597. if (empty($form_state['page']->changed)) {
  1598. $form_state['do not cache'] = TRUE;
  1599. }
  1600. }
  1601. }
  1602. /**
  1603. * Print the summary information for a page.
  1604. */
  1605. function page_manager_page_summary($form, &$form_state) {
  1606. $page = $form_state['page'];
  1607. $output = '';
  1608. /*
  1609. if (isset($form_state['subtask']['admin title'])) {
  1610. $form_state['title'] = $form_state['subtask']['admin title'];
  1611. }
  1612. */
  1613. if (isset($form_state['subtask']['admin description'])) {
  1614. $output .= '<div class="description">' . $form_state['subtask']['admin description'] . '</div>';
  1615. }
  1616. $output .= page_manager_get_page_summary($page->task, $page->subtask);
  1617. if (!empty($page->handlers)) {
  1618. foreach ($page->handler_info as $id => $info) {
  1619. if ($info['changed'] & PAGE_MANAGER_CHANGED_DELETED) {
  1620. continue;
  1621. }
  1622. $handler = $page->handlers[$id];
  1623. $plugin = page_manager_get_task_handler($handler->handler);
  1624. $output .= '<div class="handler-summary">';
  1625. $output .= page_manager_get_handler_summary($plugin, $handler, $page);
  1626. $output .= '</div>';
  1627. }
  1628. }
  1629. else {
  1630. $output .= '<p>' . t('This page has no variants and thus no output of its own.') . '</p>';
  1631. }
  1632. $links = array(
  1633. array(
  1634. 'title' => ' &raquo; ' . t('Add a new variant'),
  1635. 'href' => page_manager_edit_url($page->task_name, array('actions', 'add')),
  1636. 'html' => TRUE,
  1637. ),
  1638. );
  1639. $output .= '<div class="links">' . theme('links', array('links' => $links)) . '</div>';
  1640. $form['markup'] = array(
  1641. '#markup' => $output,
  1642. );
  1643. return $form;
  1644. }
  1645. /**
  1646. * Menu callback to enable or disable a page
  1647. */
  1648. function page_manager_enable_page($disable, $js, $page) {
  1649. if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], $page->task_name)) {
  1650. return MENU_ACCESS_DENIED;
  1651. }
  1652. if ($page->locked) {
  1653. if ($disable) {
  1654. drupal_set_message(t('Unable to disable due to lock.'));
  1655. }
  1656. else {
  1657. drupal_set_message(t('Unable to enable due to lock.'));
  1658. }
  1659. }
  1660. else {
  1661. if ($function = ctools_plugin_get_function($page->subtask, 'enable callback')) {
  1662. $result = $function($page, $disable);
  1663. menu_rebuild();
  1664. // We want to re-cache this if it's changed so that status is properly
  1665. // updated on the changed form.
  1666. if (!empty($page->changed)) {
  1667. page_manager_set_page_cache($page);
  1668. }
  1669. }
  1670. }
  1671. // For now $js is not actually in use on this.
  1672. drupal_goto('admin/structure/pages');
  1673. }