block.admin.inc

  1. drupal
    1. 6 drupal/modules/block/block.admin.inc
    2. 7 drupal/modules/block/block.admin.inc
    3. 8 drupal/modules/block/block.admin.inc

Admin page callbacks for the block module.

Functions & methods

NameDescription
block_add_block_formForm builder for the add block form.
block_add_block_form_submitForm submission handler for the add block form.
block_add_block_form_validateForm validation handler for the add block form.
block_admin_configureForm builder for the block configuration form.
block_admin_configure_submitForm submission handler for the block configuration form.
block_admin_configure_validateForm validation handler for the block configuration form.
block_admin_demoMenu callback for admin/structure/block/demo.
block_admin_displayMenu callback for admin/structure/block.
block_admin_display_formForm builder for the main blocks administration form.
block_admin_display_form_submitForm submission handler for the main blocks administration form.
block_admin_display_prepare_blocksPrepares a list of blocks for display on the blocks administration page.
block_custom_block_deleteForm builder for the custom block deletion form.
block_custom_block_delete_submitForm submission handler for the custom block deletion form.
template_preprocess_block_admin_display_formProcesses variables for block-admin-display-form.tpl.php.
_block_compareHelper function for sorting blocks on admin/structure/block.

File

View source
  1. <?php
  2. /**
  3. * @file
  4. * Admin page callbacks for the block module.
  5. */
  6. /**
  7. * Menu callback for admin/structure/block/demo.
  8. */
  9. function block_admin_demo($theme = NULL) {
  10. drupal_add_css(drupal_get_path('module', 'block') . '/block.css');
  11. return '';
  12. }
  13. /**
  14. * Menu callback for admin/structure/block.
  15. *
  16. * @param $theme
  17. * The theme to display the administration page for. If not provided, defaults
  18. * to the currently used theme.
  19. */
  20. function block_admin_display($theme = NULL) {
  21. global $theme_key;
  22. drupal_theme_initialize();
  23. if (!isset($theme)) {
  24. // If theme is not specifically set, rehash for the current theme.
  25. $theme = $theme_key;
  26. }
  27. // Fetch and sort blocks.
  28. $blocks = block_admin_display_prepare_blocks($theme);
  29. return drupal_get_form('block_admin_display_form', $blocks, $theme);
  30. }
  31. /**
  32. * Prepares a list of blocks for display on the blocks administration page.
  33. *
  34. * @param $theme
  35. * The machine-readable name of the theme whose blocks should be returned.
  36. *
  37. * @return
  38. * An array of blocks, as returned by _block_rehash(), sorted by region in
  39. * preparation for display on the blocks administration page.
  40. *
  41. * @see block_admin_display_form()
  42. */
  43. function block_admin_display_prepare_blocks($theme) {
  44. $blocks = _block_rehash($theme);
  45. $compare_theme = &drupal_static('_block_compare:theme');
  46. $compare_theme = $theme;
  47. usort($blocks, '_block_compare');
  48. return $blocks;
  49. }
  50. /**
  51. * Form builder for the main blocks administration form.
  52. *
  53. * @param $blocks
  54. * An array of blocks, as returned by block_admin_display_prepare_blocks().
  55. * @param $theme
  56. * A string representing the name of the theme to edit blocks for.
  57. * @param $block_regions
  58. * (optional) An array of regions in which the blocks will be allowed to be
  59. * placed. Defaults to all visible regions for the theme whose blocks are
  60. * being configured. In all cases, a dummy region for disabled blocks will
  61. * also be displayed.
  62. *
  63. * @return
  64. * An array representing the form definition.
  65. *
  66. * @ingroup forms
  67. * @see block_admin_display_form_submit()
  68. */
  69. function block_admin_display_form($form, &$form_state, $blocks, $theme, $block_regions = NULL) {
  70. drupal_add_css(drupal_get_path('module', 'block') . '/block.css');
  71. // Get a list of block regions if one was not provided.
  72. if (!isset($block_regions)) {
  73. $block_regions = system_region_list($theme, REGIONS_VISIBLE);
  74. }
  75. // Weights range from -delta to +delta, so delta should be at least half
  76. // of the amount of blocks present. This makes sure all blocks in the same
  77. // region get an unique weight.
  78. $weight_delta = round(count($blocks) / 2);
  79. // Build the form tree.
  80. $form['edited_theme'] = array(
  81. '#type' => 'value',
  82. '#value' => $theme,
  83. );
  84. $form['block_regions'] = array(
  85. '#type' => 'value',
  86. // Add a last region for disabled blocks.
  87. '#value' => $block_regions + array(BLOCK_REGION_NONE => BLOCK_REGION_NONE),
  88. );
  89. $form['blocks'] = array();
  90. $form['#tree'] = TRUE;
  91. foreach ($blocks as $i => $block) {
  92. $key = $block['module'] . '_' . $block['delta'];
  93. $form['blocks'][$key]['module'] = array(
  94. '#type' => 'value',
  95. '#value' => $block['module'],
  96. );
  97. $form['blocks'][$key]['delta'] = array(
  98. '#type' => 'value',
  99. '#value' => $block['delta'],
  100. );
  101. $form['blocks'][$key]['info'] = array(
  102. '#markup' => check_plain($block['info']),
  103. );
  104. $form['blocks'][$key]['theme'] = array(
  105. '#type' => 'hidden',
  106. '#value' => $theme,
  107. );
  108. $form['blocks'][$key]['weight'] = array(
  109. '#type' => 'weight',
  110. '#default_value' => $block['weight'],
  111. '#delta' => $weight_delta,
  112. '#title_display' => 'invisible',
  113. '#title' => t('Weight for @block block', array('@block' => $block['info'])),
  114. );
  115. $form['blocks'][$key]['region'] = array(
  116. '#type' => 'select',
  117. '#default_value' => $block['region'] != BLOCK_REGION_NONE ? $block['region'] : NULL,
  118. '#empty_value' => BLOCK_REGION_NONE,
  119. '#title_display' => 'invisible',
  120. '#title' => t('Region for @block block', array('@block' => $block['info'])),
  121. '#options' => $block_regions,
  122. );
  123. $form['blocks'][$key]['configure'] = array(
  124. '#type' => 'link',
  125. '#title' => t('configure'),
  126. '#href' => 'admin/structure/block/manage/' . $block['module'] . '/' . $block['delta'] . '/configure',
  127. );
  128. if ($block['module'] == 'block') {
  129. $form['blocks'][$key]['delete'] = array(
  130. '#type' => 'link',
  131. '#title' => t('delete'),
  132. '#href' => 'admin/structure/block/manage/' . $block['module'] . '/' . $block['delta'] . '/delete',
  133. );
  134. }
  135. }
  136. // Do not allow disabling the main system content block when it is present.
  137. if (isset($form['blocks']['system_main']['region'])) {
  138. $form['blocks']['system_main']['region']['#required'] = TRUE;
  139. }
  140. $form['actions'] = array(
  141. '#tree' => FALSE,
  142. '#type' => 'actions',
  143. );
  144. $form['actions']['submit'] = array(
  145. '#type' => 'submit',
  146. '#value' => t('Save blocks'),
  147. );
  148. return $form;
  149. }
  150. /**
  151. * Form submission handler for the main blocks administration form.
  152. *
  153. * @see block_admin_display_form()
  154. */
  155. function block_admin_display_form_submit($form, &$form_state) {
  156. $transaction = db_transaction();
  157. try {
  158. foreach ($form_state['values']['blocks'] as $block) {
  159. $block['status'] = (int) ($block['region'] != BLOCK_REGION_NONE);
  160. $block['region'] = $block['status'] ? $block['region'] : '';
  161. db_update('block')
  162. ->fields(array(
  163. 'status' => $block['status'],
  164. 'weight' => $block['weight'],
  165. 'region' => $block['region'],
  166. ))
  167. ->condition('module', $block['module'])
  168. ->condition('delta', $block['delta'])
  169. ->condition('theme', $block['theme'])
  170. ->execute();
  171. }
  172. }
  173. catch (Exception $e) {
  174. $transaction->rollback();
  175. watchdog_exception('block', $e);
  176. throw $e;
  177. }
  178. drupal_set_message(t('The block settings have been updated.'));
  179. cache_clear_all();
  180. }
  181. /**
  182. * Helper function for sorting blocks on admin/structure/block.
  183. *
  184. * Active blocks are sorted by region, then by weight.
  185. * Disabled blocks are sorted by name.
  186. */
  187. function _block_compare($a, $b) {
  188. global $theme_key;
  189. // Theme should be set before calling this function, or the current theme
  190. // is being used.
  191. $theme = &drupal_static(__FUNCTION__ . ':theme');
  192. if (!isset($theme)) {
  193. $theme = $theme_key;
  194. }
  195. $regions = &drupal_static(__FUNCTION__ . ':regions');
  196. // We need the region list to correctly order by region.
  197. if (!isset($regions)) {
  198. $regions = array_flip(array_keys(system_region_list($theme)));
  199. $regions[BLOCK_REGION_NONE] = count($regions);
  200. }
  201. // Separate enabled from disabled.
  202. $status = $b['status'] - $a['status'];
  203. if ($status) {
  204. return $status;
  205. }
  206. // Sort by region (in the order defined by theme .info file).
  207. if ((!empty($a['region']) && !empty($b['region'])) && ($place = ($regions[$a['region']] - $regions[$b['region']]))) {
  208. return $place;
  209. }
  210. // Sort by weight, unless disabled.
  211. if ($a['region'] != BLOCK_REGION_NONE) {
  212. $weight = $a['weight'] - $b['weight'];
  213. if ($weight) {
  214. return $weight;
  215. }
  216. }
  217. // Sort by title.
  218. return strcmp($a['info'], $b['info']);
  219. }
  220. /**
  221. * Form builder for the block configuration form.
  222. *
  223. * Also used by block_add_block_form() for adding a new custom block.
  224. *
  225. * @param $module
  226. * Name of the module that implements the block to be configured.
  227. * @param $delta
  228. * Unique ID of the block within the context of $module.
  229. *
  230. * @see block_admin_configure_validate()
  231. * @see block_admin_configure_submit()
  232. * @ingroup forms
  233. */
  234. function block_admin_configure($form, &$form_state, $module, $delta) {
  235. $block = block_load($module, $delta);
  236. $form['module'] = array(
  237. '#type' => 'value',
  238. '#value' => $block->module,
  239. );
  240. $form['delta'] = array(
  241. '#type' => 'value',
  242. '#value' => $block->delta,
  243. );
  244. // Get the block subject for the page title.
  245. $info = module_invoke($block->module, 'block_info');
  246. if (isset($info[$block->delta])) {
  247. drupal_set_title(t("'%name' block", array('%name' => $info[$block->delta]['info'])), PASS_THROUGH);
  248. }
  249. $form['settings']['title'] = array(
  250. '#type' => 'textfield',
  251. '#title' => t('Block title'),
  252. '#maxlength' => 64,
  253. '#description' => $block->module == 'block' ? t('The title of the block as shown to the user.') : t('Override the default title for the block. Use <em>!placeholder</em> to display no title, or leave blank to use the default block title.', array('!placeholder' => '&lt;none&gt;')),
  254. '#default_value' => isset($block->title) ? $block->title : '',
  255. '#weight' => -18,
  256. );
  257. // Module-specific block configuration.
  258. if ($settings = module_invoke($block->module, 'block_configure', $block->delta)) {
  259. foreach ($settings as $k => $v) {
  260. $form['settings'][$k] = $v;
  261. }
  262. }
  263. // Region settings.
  264. $form['regions'] = array(
  265. '#type' => 'fieldset',
  266. '#title' => t('Region settings'),
  267. '#collapsible' => FALSE,
  268. '#description' => t('Specify in which themes and regions this block is displayed.'),
  269. '#tree' => TRUE,
  270. );
  271. $theme_default = variable_get('theme_default', 'bartik');
  272. $admin_theme = variable_get('admin_theme');
  273. foreach (list_themes() as $key => $theme) {
  274. // Only display enabled themes
  275. if ($theme->status) {
  276. $region = db_query("SELECT region FROM {block} WHERE module = :module AND delta = :delta AND theme = :theme", array(
  277. ':module' => $block->module,
  278. ':delta' => $block->delta,
  279. ':theme' => $key,
  280. ))->fetchField();
  281. // Use a meaningful title for the main site theme and administrative
  282. // theme.
  283. $theme_title = $theme->info['name'];
  284. if ($key == $theme_default) {
  285. $theme_title = t('!theme (default theme)', array('!theme' => $theme_title));
  286. }
  287. elseif ($admin_theme && $key == $admin_theme) {
  288. $theme_title = t('!theme (administration theme)', array('!theme' => $theme_title));
  289. }
  290. $form['regions'][$key] = array(
  291. '#type' => 'select',
  292. '#title' => $theme_title,
  293. '#default_value' => !empty($region) && $region != -1 ? $region : NULL,
  294. '#empty_value' => BLOCK_REGION_NONE,
  295. '#options' => system_region_list($key, REGIONS_VISIBLE),
  296. '#weight' => ($key == $theme_default ? 9 : 10),
  297. );
  298. }
  299. }
  300. // Visibility settings.
  301. $form['visibility_title'] = array(
  302. '#type' => 'item',
  303. '#title' => t('Visibility settings'),
  304. );
  305. $form['visibility'] = array(
  306. '#type' => 'vertical_tabs',
  307. '#attached' => array(
  308. 'js' => array(drupal_get_path('module', 'block') . '/block.js'),
  309. ),
  310. );
  311. // Per-path visibility.
  312. $form['visibility']['path'] = array(
  313. '#type' => 'fieldset',
  314. '#title' => t('Pages'),
  315. '#collapsible' => TRUE,
  316. '#collapsed' => TRUE,
  317. '#group' => 'visibility',
  318. '#weight' => 0,
  319. );
  320. $access = user_access('use PHP for settings');
  321. if (isset($block->visibility) && $block->visibility == BLOCK_VISIBILITY_PHP && !$access) {
  322. $form['visibility']['path']['visibility'] = array(
  323. '#type' => 'value',
  324. '#value' => BLOCK_VISIBILITY_PHP,
  325. );
  326. $form['visibility']['path']['pages'] = array(
  327. '#type' => 'value',
  328. '#value' => isset($block->pages) ? $block->pages : '',
  329. );
  330. }
  331. else {
  332. $options = array(
  333. BLOCK_VISIBILITY_NOTLISTED => t('All pages except those listed'),
  334. BLOCK_VISIBILITY_LISTED => t('Only the listed pages'),
  335. );
  336. $description = t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>'));
  337. if (module_exists('php') && $access) {
  338. $options += array(BLOCK_VISIBILITY_PHP => t('Pages on which this PHP code returns <code>TRUE</code> (experts only)'));
  339. $title = t('Pages or PHP code');
  340. $description .= ' ' . t('If the PHP option is chosen, enter PHP code between %php. Note that executing incorrect PHP code can break your Drupal site.', array('%php' => '<?php ?>'));
  341. }
  342. else {
  343. $title = t('Pages');
  344. }
  345. $form['visibility']['path']['visibility'] = array(
  346. '#type' => 'radios',
  347. '#title' => t('Show block on specific pages'),
  348. '#options' => $options,
  349. '#default_value' => isset($block->visibility) ? $block->visibility : BLOCK_VISIBILITY_NOTLISTED,
  350. );
  351. $form['visibility']['path']['pages'] = array(
  352. '#type' => 'textarea',
  353. '#title' => '<span class="element-invisible">' . $title . '</span>',
  354. '#default_value' => isset($block->pages) ? $block->pages : '',
  355. '#description' => $description,
  356. );
  357. }
  358. // Per-role visibility.
  359. $default_role_options = db_query("SELECT rid FROM {block_role} WHERE module = :module AND delta = :delta", array(
  360. ':module' => $block->module,
  361. ':delta' => $block->delta,
  362. ))->fetchCol();
  363. $role_options = array_map('check_plain', user_roles());
  364. $form['visibility']['role'] = array(
  365. '#type' => 'fieldset',
  366. '#title' => t('Roles'),
  367. '#collapsible' => TRUE,
  368. '#collapsed' => TRUE,
  369. '#group' => 'visibility',
  370. '#weight' => 10,
  371. );
  372. $form['visibility']['role']['roles'] = array(
  373. '#type' => 'checkboxes',
  374. '#title' => t('Show block for specific roles'),
  375. '#default_value' => $default_role_options,
  376. '#options' => $role_options,
  377. '#description' => t('Show this block only for the selected role(s). If you select no roles, the block will be visible to all users.'),
  378. );
  379. // Per-user visibility.
  380. $form['visibility']['user'] = array(
  381. '#type' => 'fieldset',
  382. '#title' => t('Users'),
  383. '#collapsible' => TRUE,
  384. '#collapsed' => TRUE,
  385. '#group' => 'visibility',
  386. '#weight' => 20,
  387. );
  388. $form['visibility']['user']['custom'] = array(
  389. '#type' => 'radios',
  390. '#title' => t('Customizable per user'),
  391. '#options' => array(
  392. BLOCK_CUSTOM_FIXED => t('Not customizable'),
  393. BLOCK_CUSTOM_ENABLED => t('Customizable, visible by default'),
  394. BLOCK_CUSTOM_DISABLED => t('Customizable, hidden by default'),
  395. ),
  396. '#description' => t('Allow individual users to customize the visibility of this block in their account settings.'),
  397. '#default_value' => isset($block->custom) ? $block->custom : BLOCK_CUSTOM_FIXED,
  398. );
  399. $form['actions'] = array('#type' => 'actions');
  400. $form['actions']['submit'] = array(
  401. '#type' => 'submit',
  402. '#value' => t('Save block'),
  403. );
  404. return $form;
  405. }
  406. /**
  407. * Form validation handler for the block configuration form.
  408. *
  409. * @see block_admin_configure()
  410. * @see block_admin_configure_submit()
  411. */
  412. function block_admin_configure_validate($form, &$form_state) {
  413. if ($form_state['values']['module'] == 'block') {
  414. $custom_block_exists = (bool) db_query_range('SELECT 1 FROM {block_custom} WHERE bid <> :bid AND info = :info', 0, 1, array(
  415. ':bid' => $form_state['values']['delta'],
  416. ':info' => $form_state['values']['info'],
  417. ))->fetchField();
  418. if (empty($form_state['values']['info']) || $custom_block_exists) {
  419. form_set_error('info', t('Ensure that each block description is unique.'));
  420. }
  421. }
  422. }
  423. /**
  424. * Form submission handler for the block configuration form.
  425. *
  426. * @see block_admin_configure()
  427. * @see block_admin_configure_validate()
  428. */
  429. function block_admin_configure_submit($form, &$form_state) {
  430. if (!form_get_errors()) {
  431. $transaction = db_transaction();
  432. try {
  433. db_update('block')
  434. ->fields(array(
  435. 'visibility' => (int) $form_state['values']['visibility'],
  436. 'pages' => trim($form_state['values']['pages']),
  437. 'custom' => (int) $form_state['values']['custom'],
  438. 'title' => $form_state['values']['title'],
  439. ))
  440. ->condition('module', $form_state['values']['module'])
  441. ->condition('delta', $form_state['values']['delta'])
  442. ->execute();
  443. db_delete('block_role')
  444. ->condition('module', $form_state['values']['module'])
  445. ->condition('delta', $form_state['values']['delta'])
  446. ->execute();
  447. $query = db_insert('block_role')->fields(array('rid', 'module', 'delta'));
  448. foreach (array_filter($form_state['values']['roles']) as $rid) {
  449. $query->values(array(
  450. 'rid' => $rid,
  451. 'module' => $form_state['values']['module'],
  452. 'delta' => $form_state['values']['delta'],
  453. ));
  454. }
  455. $query->execute();
  456. // Store regions per theme for this block
  457. foreach ($form_state['values']['regions'] as $theme => $region) {
  458. db_merge('block')
  459. ->key(array('theme' => $theme, 'delta' => $form_state['values']['delta'], 'module' => $form_state['values']['module']))
  460. ->fields(array(
  461. 'region' => ($region == BLOCK_REGION_NONE ? '' : $region),
  462. 'pages' => trim($form_state['values']['pages']),
  463. 'status' => (int) ($region != BLOCK_REGION_NONE),
  464. ))
  465. ->execute();
  466. }
  467. module_invoke($form_state['values']['module'], 'block_save', $form_state['values']['delta'], $form_state['values']);
  468. }
  469. catch (Exception $e) {
  470. $transaction->rollback();
  471. watchdog_exception('block', $e);
  472. throw $e;
  473. }
  474. drupal_set_message(t('The block configuration has been saved.'));
  475. cache_clear_all();
  476. $form_state['redirect'] = 'admin/structure/block';
  477. }
  478. }
  479. /**
  480. * Form builder for the add block form.
  481. *
  482. * @see block_add_block_form_validate()
  483. * @see block_add_block_form_submit()
  484. * @ingroup forms
  485. */
  486. function block_add_block_form($form, &$form_state) {
  487. return block_admin_configure($form, $form_state, 'block', NULL);
  488. }
  489. /**
  490. * Form validation handler for the add block form.
  491. *
  492. * @see block_add_block_form()
  493. * @see block_add_block_form_submit()
  494. */
  495. function block_add_block_form_validate($form, &$form_state) {
  496. $custom_block_exists = (bool) db_query_range('SELECT 1 FROM {block_custom} WHERE info = :info', 0, 1, array(':info' => $form_state['values']['info']))->fetchField();
  497. if (empty($form_state['values']['info']) || $custom_block_exists) {
  498. form_set_error('info', t('Ensure that each block description is unique.'));
  499. }
  500. }
  501. /**
  502. * Form submission handler for the add block form.
  503. *
  504. * Saves the new custom block.
  505. *
  506. * @see block_add_block_form()
  507. * @see block_add_block_form_validate()
  508. */
  509. function block_add_block_form_submit($form, &$form_state) {
  510. $delta = db_insert('block_custom')
  511. ->fields(array(
  512. 'body' => $form_state['values']['body']['value'],
  513. 'info' => $form_state['values']['info'],
  514. 'format' => $form_state['values']['body']['format'],
  515. ))
  516. ->execute();
  517. // Store block delta to allow other modules to work with new block.
  518. $form_state['values']['delta'] = $delta;
  519. $query = db_insert('block')->fields(array('visibility', 'pages', 'custom', 'title', 'module', 'theme', 'status', 'weight', 'delta', 'cache'));
  520. foreach (list_themes() as $key => $theme) {
  521. if ($theme->status) {
  522. $query->values(array(
  523. 'visibility' => (int) $form_state['values']['visibility'],
  524. 'pages' => trim($form_state['values']['pages']),
  525. 'custom' => (int) $form_state['values']['custom'],
  526. 'title' => $form_state['values']['title'],
  527. 'module' => $form_state['values']['module'],
  528. 'theme' => $theme->name,
  529. 'status' => 0,
  530. 'weight' => 0,
  531. 'delta' => $delta,
  532. 'cache' => DRUPAL_NO_CACHE,
  533. ));
  534. }
  535. }
  536. $query->execute();
  537. $query = db_insert('block_role')->fields(array('rid', 'module', 'delta'));
  538. foreach (array_filter($form_state['values']['roles']) as $rid) {
  539. $query->values(array(
  540. 'rid' => $rid,
  541. 'module' => $form_state['values']['module'],
  542. 'delta' => $delta,
  543. ));
  544. }
  545. $query->execute();
  546. // Store regions per theme for this block
  547. foreach ($form_state['values']['regions'] as $theme => $region) {
  548. db_merge('block')
  549. ->key(array('theme' => $theme, 'delta' => $delta, 'module' => $form_state['values']['module']))
  550. ->fields(array(
  551. 'region' => ($region == BLOCK_REGION_NONE ? '' : $region),
  552. 'pages' => trim($form_state['values']['pages']),
  553. 'status' => (int) ($region != BLOCK_REGION_NONE),
  554. ))
  555. ->execute();
  556. }
  557. drupal_set_message(t('The block has been created.'));
  558. cache_clear_all();
  559. $form_state['redirect'] = 'admin/structure/block';
  560. }
  561. /**
  562. * Form builder for the custom block deletion form.
  563. *
  564. * @param $module
  565. * The name of the module that implements the block to be deleted. This should
  566. * always equal 'block' since it only allows custom blocks to be deleted.
  567. * @param $delta
  568. * The unique ID of the block within the context of $module.
  569. *
  570. * @see block_custom_block_delete_submit()
  571. */
  572. function block_custom_block_delete($form, &$form_state, $module, $delta) {
  573. $block = block_load($module, $delta);
  574. $custom_block = block_custom_block_get($block->delta);
  575. $form['info'] = array('#type' => 'hidden', '#value' => $custom_block['info'] ? $custom_block['info'] : $custom_block['title']);
  576. $form['bid'] = array('#type' => 'hidden', '#value' => $block->delta);
  577. return confirm_form($form, t('Are you sure you want to delete the block %name?', array('%name' => $custom_block['info'])), 'admin/structure/block', '', t('Delete'), t('Cancel'));
  578. }
  579. /**
  580. * Form submission handler for the custom block deletion form.
  581. *
  582. * @see block_custom_block_delete()
  583. */
  584. function block_custom_block_delete_submit($form, &$form_state) {
  585. db_delete('block_custom')
  586. ->condition('bid', $form_state['values']['bid'])
  587. ->execute();
  588. db_delete('block')
  589. ->condition('module', 'block')
  590. ->condition('delta', $form_state['values']['bid'])
  591. ->execute();
  592. db_delete('block_role')
  593. ->condition('module', 'block')
  594. ->condition('delta', $form_state['values']['bid'])
  595. ->execute();
  596. drupal_set_message(t('The block %name has been removed.', array('%name' => $form_state['values']['info'])));
  597. cache_clear_all();
  598. $form_state['redirect'] = 'admin/structure/block';
  599. return;
  600. }
  601. /**
  602. * Processes variables for block-admin-display-form.tpl.php.
  603. *
  604. * The $variables array contains the following arguments:
  605. * - $form
  606. *
  607. * @see block-admin-display.tpl.php
  608. * @see theme_block_admin_display()
  609. */
  610. function template_preprocess_block_admin_display_form(&$variables) {
  611. $variables['block_regions'] = $variables['form']['block_regions']['#value'];
  612. if (isset($variables['block_regions'][BLOCK_REGION_NONE])) {
  613. $variables['block_regions'][BLOCK_REGION_NONE] = t('Disabled');
  614. }
  615. foreach ($variables['block_regions'] as $key => $value) {
  616. // Initialize an empty array for the region.
  617. $variables['block_listing'][$key] = array();
  618. }
  619. // Initialize disabled blocks array.
  620. $variables['block_listing'][BLOCK_REGION_NONE] = array();
  621. // Add each block in the form to the appropriate place in the block listing.
  622. foreach (element_children($variables['form']['blocks']) as $i) {
  623. $block = &$variables['form']['blocks'][$i];
  624. // Fetch the region for the current block.
  625. $region = (isset($block['region']['#default_value']) ? $block['region']['#default_value'] : BLOCK_REGION_NONE);
  626. // Set special classes needed for table drag and drop.
  627. $block['region']['#attributes']['class'] = array('block-region-select', 'block-region-' . $region);
  628. $block['weight']['#attributes']['class'] = array('block-weight', 'block-weight-' . $region);
  629. $variables['block_listing'][$region][$i] = new stdClass();
  630. $variables['block_listing'][$region][$i]->row_class = !empty($block['#attributes']['class']) ? implode(' ', $block['#attributes']['class']) : '';
  631. $variables['block_listing'][$region][$i]->block_modified = !empty($block['#attributes']['class']) && in_array('block-modified', $block['#attributes']['class']);
  632. $variables['block_listing'][$region][$i]->block_title = drupal_render($block['info']);
  633. $variables['block_listing'][$region][$i]->region_select = drupal_render($block['region']) . drupal_render($block['theme']);
  634. $variables['block_listing'][$region][$i]->weight_select = drupal_render($block['weight']);
  635. $variables['block_listing'][$region][$i]->configure_link = drupal_render($block['configure']);
  636. $variables['block_listing'][$region][$i]->delete_link = !empty($block['delete']) ? drupal_render($block['delete']) : '';
  637. $variables['block_listing'][$region][$i]->printed = FALSE;
  638. }
  639. $variables['form_submit'] = drupal_render_children($variables['form']);
  640. }