wysiwyg.admin.inc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. <?php
  2. /**
  3. * @file
  4. * Integrate Wysiwyg editors into Drupal.
  5. */
  6. /**
  7. * Form builder for Wysiwyg profile form.
  8. */
  9. function wysiwyg_profile_form($form, &$form_state, $profile) {
  10. // Merge in defaults.
  11. $profile = (array) $profile;
  12. $profile += array(
  13. 'format' => '',
  14. 'editor' => '',
  15. );
  16. if (empty($profile['settings'])) {
  17. $profile['settings'] = array();
  18. }
  19. $profile['settings'] += array(
  20. 'default' => TRUE,
  21. 'user_choose' => FALSE,
  22. 'show_toggle' => TRUE,
  23. 'theme' => 'advanced',
  24. 'language' => 'en',
  25. 'access' => 1,
  26. 'access_pages' => "node/*\nuser/*\ncomment/*",
  27. 'buttons' => array(),
  28. 'toolbar_loc' => 'top',
  29. 'toolbar_align' => 'left',
  30. 'path_loc' => 'bottom',
  31. 'resizing' => TRUE,
  32. // Also available, but buggy in TinyMCE 2.x: blockquote,code,dt,dd,samp.
  33. 'block_formats' => 'p,address,pre,h2,h3,h4,h5,h6,div',
  34. 'verify_html' => TRUE,
  35. 'preformatted' => FALSE,
  36. 'convert_fonts_to_spans' => TRUE,
  37. 'remove_linebreaks' => TRUE,
  38. 'apply_source_formatting' => FALSE,
  39. 'paste_auto_cleanup_on_paste' => FALSE,
  40. 'css_setting' => 'theme',
  41. 'css_path' => NULL,
  42. 'css_classes' => NULL,
  43. );
  44. $profile = (object) $profile;
  45. $formats = filter_formats();
  46. $editor = wysiwyg_get_editor($profile->editor);
  47. drupal_set_title(t('%editor profile for %format', array('%editor' => $editor['title'], '%format' => $formats[$profile->format]->name)), PASS_THROUGH);
  48. $form['format'] = array('#type' => 'value', '#value' => $profile->format);
  49. $form['input_format'] = array('#type' => 'value', '#value' => $formats[$profile->format]->name);
  50. $form['editor'] = array('#type' => 'value', '#value' => $profile->editor);
  51. $form['basic'] = array(
  52. '#type' => 'fieldset',
  53. '#title' => t('Basic setup'),
  54. '#collapsible' => TRUE,
  55. '#collapsed' => TRUE,
  56. );
  57. $form['basic']['default'] = array(
  58. '#type' => 'checkbox',
  59. '#title' => t('Enabled by default'),
  60. '#default_value' => $profile->settings['default'],
  61. '#return_value' => 1,
  62. '#description' => t('The default editor state for users having access to this profile. Users are able to override this state if the next option is enabled.'),
  63. );
  64. $form['basic']['user_choose'] = array(
  65. '#type' => 'checkbox',
  66. '#title' => t('Allow users to choose default'),
  67. '#default_value' => $profile->settings['user_choose'],
  68. '#return_value' => 1,
  69. '#description' => t('If allowed, users will be able to choose their own editor default state in their user account settings.'),
  70. );
  71. $form['basic']['show_toggle'] = array(
  72. '#type' => 'checkbox',
  73. '#title' => t('Show <em>enable/disable rich text</em> toggle link'),
  74. '#default_value' => $profile->settings['show_toggle'],
  75. '#return_value' => 1,
  76. '#description' => t('Whether or not to show the <em>enable/disable rich text</em> toggle link below a textarea. If disabled, the user setting or global default is used (see above).'),
  77. );
  78. $form['basic']['theme'] = array(
  79. '#type' => 'hidden',
  80. '#value' => $profile->settings['theme'],
  81. );
  82. $form['basic']['language'] = array(
  83. '#type' => 'select',
  84. '#title' => t('Interface language'),
  85. '#default_value' => $profile->settings['language'],
  86. );
  87. // @see _locale_prepare_predefined_list()
  88. require_once DRUPAL_ROOT . '/includes/iso.inc';
  89. $predefined = _locale_get_predefined_list();
  90. foreach ($predefined as $key => $value) {
  91. // Include native name in output, if possible
  92. if (count($value) > 1) {
  93. $tname = t($value[0]);
  94. $predefined[$key] = ($tname == $value[1]) ? $tname : "$tname ($value[1])";
  95. }
  96. else {
  97. $predefined[$key] = t($value[0]);
  98. }
  99. }
  100. asort($predefined);
  101. $form['basic']['language']['#options'] = $predefined;
  102. $form['buttons'] = array(
  103. '#type' => 'fieldset',
  104. '#title' => t('Buttons and plugins'),
  105. '#collapsible' => TRUE,
  106. '#collapsed' => TRUE,
  107. '#tree' => TRUE,
  108. '#theme' => 'wysiwyg_admin_button_table',
  109. );
  110. $plugins = wysiwyg_get_plugins($profile->editor);
  111. // Generate the button list.
  112. foreach ($plugins as $name => $meta) {
  113. if (isset($meta['buttons']) && is_array($meta['buttons'])) {
  114. foreach ($meta['buttons'] as $button => $title) {
  115. $icon = '';
  116. if (!empty($meta['path'])) {
  117. // @todo Button icon locations are different in editors, editor versions,
  118. // and contrib/custom plugins (like Image Assist, f.e.).
  119. $img_src = $meta['path'] . "/images/$name.gif";
  120. // Handle plugins that have more than one button.
  121. if (!file_exists($img_src)) {
  122. $img_src = $meta['path'] . "/images/$button.gif";
  123. }
  124. $icon = file_exists($img_src) ? '<img src="' . base_path() . $img_src . '" title="' . $button . '" style="border: 1px solid grey; vertical-align: middle;" />' : '';
  125. }
  126. $title = (!empty($icon) ? $icon . ' ' . check_plain($title) : check_plain($title));
  127. $form['buttons'][$name][$button] = array(
  128. '#type' => 'checkbox',
  129. '#title' => $title,
  130. '#default_value' => !empty($profile->settings['buttons'][$name][$button]) ? $profile->settings['buttons'][$name][$button] : FALSE,
  131. '#description' => isset($meta['url']) ? l($meta['url'], $meta['url']) : NULL,
  132. );
  133. }
  134. }
  135. elseif (isset($meta['extensions']) && is_array($meta['extensions'])) {
  136. foreach ($meta['extensions'] as $extension => $title) {
  137. $form['buttons'][$name][$extension] = array(
  138. '#type' => 'checkbox',
  139. '#title' => check_plain($title),
  140. '#default_value' => !empty($profile->settings['buttons'][$name][$extension]) ? $profile->settings['buttons'][$name][$extension] : FALSE,
  141. '#description' => isset($meta['url']) ? l($meta['url'], $meta['url']) : NULL,
  142. );
  143. }
  144. }
  145. }
  146. $form['appearance'] = array(
  147. '#type' => 'fieldset',
  148. '#title' => t('Editor appearance'),
  149. '#collapsible' => TRUE,
  150. '#collapsed' => TRUE,
  151. );
  152. $form['appearance']['toolbar_loc'] = array(
  153. '#type' => 'select',
  154. '#title' => t('Toolbar location'),
  155. '#default_value' => $profile->settings['toolbar_loc'],
  156. '#options' => array('bottom' => t('Bottom'), 'top' => t('Top')),
  157. '#description' => t('This option controls whether the editor toolbar is displayed above or below the editing area.'),
  158. );
  159. $form['appearance']['toolbar_align'] = array(
  160. '#type' => 'select',
  161. '#title' => t('Button alignment'),
  162. '#default_value' => $profile->settings['toolbar_align'],
  163. '#options' => array('center' => t('Center'), 'left' => t('Left'), 'right' => t('Right')),
  164. '#description' => t('This option controls the alignment of icons in the editor toolbar.'),
  165. );
  166. $form['appearance']['path_loc'] = array(
  167. '#type' => 'select',
  168. '#title' => t('Path location'),
  169. '#default_value' => $profile->settings['path_loc'],
  170. '#options' => array('none' => t('Hide'), 'top' => t('Top'), 'bottom' => t('Bottom')),
  171. '#description' => t('Where to display the path to HTML elements (i.e. <code>body > table > tr > td</code>).'),
  172. );
  173. $form['appearance']['resizing'] = array(
  174. '#type' => 'checkbox',
  175. '#title' => t('Enable resizing button'),
  176. '#default_value' => $profile->settings['resizing'],
  177. '#return_value' => 1,
  178. '#description' => t('This option gives you the ability to enable/disable the resizing button. If enabled, the Path location toolbar must be set to "Top" or "Bottom" in order to display the resize icon.'),
  179. );
  180. $form['output'] = array(
  181. '#type' => 'fieldset',
  182. '#title' => t('Cleanup and output'),
  183. '#collapsible' => TRUE,
  184. '#collapsed' => TRUE,
  185. );
  186. $form['output']['verify_html'] = array(
  187. '#type' => 'checkbox',
  188. '#title' => t('Verify HTML'),
  189. '#default_value' => $profile->settings['verify_html'],
  190. '#return_value' => 1,
  191. '#description' => t('If enabled, potentially malicious code like <code>&lt;HEAD&gt;</code> tags will be removed from HTML contents.'),
  192. );
  193. $form['output']['preformatted'] = array(
  194. '#type' => 'checkbox',
  195. '#title' => t('Preformatted'),
  196. '#default_value' => $profile->settings['preformatted'],
  197. '#return_value' => 1,
  198. '#description' => t('If enabled, the editor will insert TAB characters on tab and preserve other whitespace characters just like a PRE element in HTML does.'),
  199. );
  200. $form['output']['convert_fonts_to_spans'] = array(
  201. '#type' => 'checkbox',
  202. '#title' => t('Convert &lt;font&gt; tags to styles'),
  203. '#default_value' => $profile->settings['convert_fonts_to_spans'],
  204. '#return_value' => 1,
  205. '#description' => t('If enabled, HTML tags declaring the font size, font family, font color and font background color will be replaced by inline CSS styles.'),
  206. );
  207. $form['output']['remove_linebreaks'] = array(
  208. '#type' => 'checkbox',
  209. '#title' => t('Remove linebreaks'),
  210. '#default_value' => $profile->settings['remove_linebreaks'],
  211. '#return_value' => 1,
  212. '#description' => t('If enabled, the editor will remove most linebreaks from contents. Disabling this option could avoid conflicts with other input filters.'),
  213. );
  214. $form['output']['apply_source_formatting'] = array(
  215. '#type' => 'checkbox',
  216. '#title' => t('Apply source formatting'),
  217. '#default_value' => $profile->settings['apply_source_formatting'],
  218. '#return_value' => 1,
  219. '#description' => t('If enabled, the editor will re-format the HTML source code. Disabling this option could avoid conflicts with other input filters.'),
  220. );
  221. $form['output']['paste_auto_cleanup_on_paste'] = array(
  222. '#type' => 'checkbox',
  223. '#title' => t('Force cleanup on standard paste'),
  224. '#default_value' => $profile->settings['paste_auto_cleanup_on_paste'],
  225. '#return_value' => 1,
  226. '#description' => t('If enabled, the default paste function (CTRL-V or SHIFT-INS) behaves like the "paste from word" plugin function.'),
  227. );
  228. $form['css'] = array(
  229. '#type' => 'fieldset',
  230. '#title' => t('CSS'),
  231. '#collapsible' => TRUE,
  232. '#collapsed' => TRUE,
  233. );
  234. $form['css']['block_formats'] = array(
  235. '#type' => 'textfield',
  236. '#title' => t('Block formats'),
  237. '#default_value' => $profile->settings['block_formats'],
  238. '#size' => 40,
  239. '#maxlength' => 250,
  240. '#description' => t('Comma separated list of HTML block formats. Possible values: <code>@format-list</code>.', array('@format-list' => 'p,h1,h2,h3,h4,h5,h6,div,blockquote,address,pre,code,dt,dd')),
  241. );
  242. $form['css']['css_setting'] = array(
  243. '#type' => 'select',
  244. '#title' => t('Editor CSS'),
  245. '#default_value' => $profile->settings['css_setting'],
  246. '#options' => array('theme' => t('Use theme CSS'), 'self' => t('Define CSS'), 'none' => t('Editor default CSS')),
  247. '#description' => t('Defines the CSS to be used in the editor area.<br />Use theme CSS - loads stylesheets from current site theme.<br/>Define CSS - enter path for stylesheet files below.<br />Editor default CSS - uses default stylesheets from editor.'),
  248. );
  249. $form['css']['css_path'] = array(
  250. '#type' => 'textfield',
  251. '#title' => t('CSS path'),
  252. '#default_value' => $profile->settings['css_path'],
  253. '#size' => 40,
  254. '#maxlength' => 255,
  255. '#description' => t('If "Define CSS" was selected above, enter path to a CSS file or a list of CSS files separated by a comma.') . '<br />' . t('Available tokens: <code>%b</code> (base path, eg: <code>/</code>), <code>%t</code> (path to theme, eg: <code>themes/garland</code>)') . '<br />' . t('Example:') . ' css/editor.css,/themes/garland/style.css,%b%t/style.css,http://example.com/external.css',
  256. );
  257. $form['css']['css_classes'] = array(
  258. '#type' => 'textarea',
  259. '#title' => t('CSS classes'),
  260. '#default_value' => $profile->settings['css_classes'],
  261. '#description' => t('Optionally define CSS classes for the "Font style" dropdown list.<br />Enter one class on each line in the format: !format. Example: !example<br />If left blank, CSS classes are automatically imported from all loaded stylesheet(s).', array('!format' => '<code>[title]=[class]</code>', '!example' => 'My heading=header1')),
  262. );
  263. $form['submit'] = array(
  264. '#type' => 'submit',
  265. '#value' => t('Save'),
  266. '#weight' => 100,
  267. );
  268. $form['cancel'] = array(
  269. '#value' => l(t('Cancel'), 'admin/config/content/wysiwyg'),
  270. '#weight' => 110,
  271. );
  272. // Supply contextual information for other callbacks and handlers.
  273. // @todo Modernize this form for D7+ and declare these earlier.
  274. // $profile is the primary object of this form, and as an entity, usually
  275. // expected to live in $form_state[$entity_type].
  276. $form_state['wysiwyg_profile'] = $profile;
  277. $form_state['wysiwyg']['editor'] = $editor;
  278. $form_state['wysiwyg']['plugins'] = $plugins;
  279. // Allow editor library specific changes to be made to the form.
  280. if (isset($editor['settings form callback'])) {
  281. $editor['settings form callback']($form, $form_state);
  282. }
  283. return $form;
  284. }
  285. /**
  286. * Submit callback for Wysiwyg profile form.
  287. *
  288. * @see wysiwyg_profile_form()
  289. */
  290. function wysiwyg_profile_form_submit($form, &$form_state) {
  291. $values = $form_state['values'];
  292. if (isset($values['buttons'])) {
  293. // Store only enabled buttons for each plugin.
  294. foreach ($values['buttons'] as $plugin => $buttons) {
  295. $values['buttons'][$plugin] = array_filter($values['buttons'][$plugin]);
  296. }
  297. // Store only enabled plugins.
  298. $values['buttons'] = array_filter($values['buttons']);
  299. }
  300. // Remove any white-space from 'block_formats' setting, since editor
  301. // implementations rely on a comma-separated list to explode().
  302. $values['block_formats'] = preg_replace('@\s+@', '', $values['block_formats']);
  303. // Remove input format name.
  304. $format = $values['format'];
  305. $input_format = $values['input_format'];
  306. $editor = $values['editor'];
  307. unset($values['format'], $values['input_format'], $values['editor']);
  308. // Remove FAPI values.
  309. // @see system_settings_form_submit()
  310. unset($values['submit'], $values['form_id'], $values['op'], $values['form_token'], $values['form_build_id']);
  311. // Insert new profile data.
  312. db_merge('wysiwyg')
  313. ->key(array('format' => $format))
  314. ->fields(array(
  315. 'editor' => $editor,
  316. 'settings' => serialize($values),
  317. ))
  318. ->execute();
  319. wysiwyg_profile_cache_clear();
  320. drupal_set_message(t('Wysiwyg profile for %format has been saved.', array('%format' => $input_format)));
  321. $form_state['redirect'] = 'admin/config/content/wysiwyg';
  322. }
  323. /**
  324. * Layout for the buttons in the Wysiwyg Editor profile form.
  325. */
  326. function theme_wysiwyg_admin_button_table($variables) {
  327. $form = $variables['form'];
  328. $buttons = array();
  329. // Flatten forms array.
  330. foreach (element_children($form) as $name) {
  331. foreach (element_children($form[$name]) as $button) {
  332. $buttons[] = drupal_render($form[$name][$button]);
  333. }
  334. }
  335. // Split checkboxes into rows with 3 columns.
  336. $total = count($buttons);
  337. $rows = array();
  338. for ($i = 0; $i < $total; $i += 3) {
  339. $row = array();
  340. $row_buttons = array_slice($buttons, $i, 3) + array_fill(0, 3, array());
  341. foreach ($row_buttons as $row_button) {
  342. $row[] = array('data' => $row_button);
  343. }
  344. $rows[] = $row;
  345. }
  346. $output = theme('table', array('rows' => $rows, 'attributes' => array('width' => '100%')));
  347. return $output;
  348. }
  349. /**
  350. * Display overview of setup Wysiwyg Editor profiles; menu callback.
  351. */
  352. function wysiwyg_profile_overview($form, &$form_state) {
  353. include_once './includes/install.inc';
  354. // Check which wysiwyg editors are installed.
  355. $editors = wysiwyg_get_all_editors();
  356. $count = count($editors);
  357. $status = array();
  358. $options = array('' => t('No editor'));
  359. // D7's seven theme displays links in table headers as block elements.
  360. drupal_add_css('table.system-status-report th a {display: inline;}', 'inline');
  361. foreach ($editors as $name => $editor) {
  362. $status[$name] = array(
  363. 'severity' => (isset($editor['error']) ? REQUIREMENT_ERROR : ($editor['installed'] ? REQUIREMENT_OK : REQUIREMENT_INFO)),
  364. 'title' => t('<a href="!vendor-url">@editor</a> (<a href="!download-url">Download</a>)', array('!vendor-url' => $editor['vendor url'], '@editor' => $editor['title'], '!download-url' => $editor['download url'])),
  365. 'value' => (isset($editor['installed version']) ? $editor['installed version'] : t('Not installed.')),
  366. 'description' => (isset($editor['error']) ? $editor['error'] : ''),
  367. );
  368. if ($editor['installed']) {
  369. $options[$name] = $editor['title'] . (isset($editor['installed version']) ? ' ' . $editor['installed version'] : '');
  370. }
  371. else {
  372. // Build on-site installation instructions.
  373. // @todo Setup $library in wysiwyg_load_editor() already.
  374. $library = (isset($editor['library']) ? $editor['library'] : key($editor['libraries']));
  375. $targs = array(
  376. '@editor-path' => $editor['editor path'],
  377. '@library-filepath' => $editor['library path'] . '/' . (isset($editor['libraries'][$library]['files'][0]) ? $editor['libraries'][$library]['files'][0] : key($editor['libraries'][$library]['files'])),
  378. );
  379. $instructions = '<p>' . t('Extract the archive and copy its contents into a new folder in the following location:<br /><code>@editor-path</code>', $targs) . '</p>';
  380. $instructions .= '<p>' . t('So the actual library can be found at:<br /><code>@library-filepath</code>', $targs) . '</p>';
  381. // Add any install notes.
  382. if (!empty($editor['install note callback']) && function_exists($editor['install note callback'])) {
  383. $instructions .= '<div class="editor-install-note">' . $editor['install note callback']() . '</div>';
  384. }
  385. $status[$name]['description'] .= $instructions;
  386. $count--;
  387. }
  388. // In case there is an error, always show installation instructions.
  389. if (isset($editor['error'])) {
  390. $show_instructions = TRUE;
  391. }
  392. }
  393. if (!$count) {
  394. $show_instructions = TRUE;
  395. }
  396. $form['status'] = array(
  397. '#type' => 'fieldset',
  398. '#title' => t('Installation instructions'),
  399. '#collapsible' => TRUE,
  400. '#collapsed' => !isset($show_instructions),
  401. '#description' => (!$count ? t('There are no editor libraries installed currently. The following list contains a list of currently supported editors:') : ''),
  402. '#weight' => 10,
  403. );
  404. $form['status']['report'] = array('#markup' => theme('status_report', array('requirements' => $status)));
  405. if (!$count) {
  406. return $form;
  407. }
  408. $formats = filter_formats();
  409. $profiles = wysiwyg_profile_load_all();
  410. $form['formats'] = array(
  411. '#type' => 'item',
  412. '#description' => t('To assign a different editor to a text format, click "delete" to remove the existing first.'),
  413. '#tree' => TRUE,
  414. );
  415. $enable_save = FALSE;
  416. foreach ($formats as $id => $format) {
  417. $form['formats'][$id]['name'] = array(
  418. '#markup' => check_plain($format->name),
  419. );
  420. // Only display editor selection for associated input formats to avoid
  421. // confusion about disabled selection.
  422. if (isset($profiles[$id]) && !empty($profiles[$id]->editor)) {
  423. $editor_name = $profiles[$id]->editor;
  424. $installed = !empty($editors[$editor_name]['installed']);
  425. $form['formats'][$id]['editor'] = array(
  426. '#wysiwyg-editor-name' => $editor_name,
  427. );
  428. if ($installed) {
  429. $form['formats'][$id]['editor']['#markup'] = $options[$editor_name];
  430. }
  431. else {
  432. drupal_set_message(t('Missing %editor library for %format format. Re-install the %editor library or delete the editor profile.', array(
  433. '%editor' => $editors[$editor_name]['title'],
  434. '%format' => $format->name,
  435. )), 'warning');
  436. }
  437. }
  438. else {
  439. $form['formats'][$id]['editor'] = array(
  440. '#type' => 'select',
  441. '#default_value' => '',
  442. '#options' => $options,
  443. );
  444. $enable_save = TRUE;
  445. }
  446. if (isset($profiles[$id]) && !empty($profiles[$id]->editor)) {
  447. $form['formats'][$id]['edit'] = array(
  448. '#markup' => l(t('Edit'), "admin/config/content/wysiwyg/profile/$id/edit"),
  449. );
  450. $form['formats'][$id]['delete'] = array(
  451. '#markup' => l(t('Delete'), "admin/config/content/wysiwyg/profile/$id/delete"),
  452. );
  453. }
  454. }
  455. // Submitting the form when no editors can be selected causes errors.
  456. if ($enable_save) {
  457. $form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
  458. }
  459. return $form;
  460. }
  461. /**
  462. * Return HTML for the Wysiwyg profile overview form.
  463. */
  464. function theme_wysiwyg_profile_overview($variables) {
  465. $form = $variables['form'];
  466. if (!isset($form['formats'])) {
  467. return;
  468. }
  469. $editors = wysiwyg_get_all_editors();
  470. $output = '';
  471. $header = array(t('Text format'), t('Editor'), array('data' => t('Operations'), 'colspan' => 2));
  472. $rows = array();
  473. foreach (element_children($form['formats']) as $item) {
  474. $format = &$form['formats'][$item];
  475. $row = array(
  476. 'data' => array(
  477. drupal_render($format['name']),
  478. drupal_render($format['editor']),
  479. isset($format['edit']) ? drupal_render($format['edit']) : '',
  480. isset($format['delete']) ? drupal_render($format['delete']) : '',
  481. ),
  482. );
  483. if (empty($row['data'][1])) {
  484. $row['data'][1] = array(
  485. 'data' => t('Missing library: @library', array('@library' => $editors[$format['editor']['#wysiwyg-editor-name']]['title'])),
  486. 'class' => 'error',
  487. );
  488. $row['class'] = array('error');
  489. }
  490. $rows[] = $row;
  491. }
  492. $form['formats']['table']['#markup'] = theme('table', array('header' => $header, 'rows' => $rows));
  493. $output .= drupal_render_children($form);
  494. return $output;
  495. }
  496. /**
  497. * Submit callback for Wysiwyg profile overview form.
  498. */
  499. function wysiwyg_profile_overview_submit($form, &$form_state) {
  500. foreach ($form_state['values']['formats'] as $format => $values) {
  501. db_merge('wysiwyg')
  502. ->key(array('format' => $format))
  503. ->fields(array(
  504. 'editor' => $values['editor'],
  505. ))
  506. ->execute();
  507. }
  508. wysiwyg_profile_cache_clear();
  509. }
  510. /**
  511. * Delete editor profile confirmation form.
  512. */
  513. function wysiwyg_profile_delete_confirm($form, &$form_state, $profile) {
  514. $formats = filter_formats();
  515. $format = $formats[$profile->format];
  516. $form['format'] = array('#type' => 'value', '#value' => $format);
  517. return confirm_form(
  518. $form,
  519. t('Are you sure you want to remove the profile for %name?', array('%name' => $format->name)),
  520. 'admin/config/content/wysiwyg',
  521. t('This action cannot be undone.'), t('Remove'), t('Cancel')
  522. );
  523. }
  524. /**
  525. * Submit callback for Wysiwyg profile delete form.
  526. *
  527. * @see wysiwyg_profile_delete_confirm()
  528. */
  529. function wysiwyg_profile_delete_confirm_submit($form, &$form_state) {
  530. $format = $form_state['values']['format'];
  531. wysiwyg_profile_delete($format->format);
  532. wysiwyg_profile_cache_clear();
  533. drupal_set_message(t('Wysiwyg profile for %name has been deleted.', array('%name' => $format->name)));
  534. $form_state['redirect'] = 'admin/config/content/wysiwyg';
  535. }