1 layout.admin.inc layout_block_remove_page(Layout $layout, Block $block, $renderer_name)

Menu callback; Remove a block from a layout.

File

core/modules/layout/layout.admin.inc, line 1927
Admin page callbacks for the Layout module.

Code

function layout_block_remove_page(Layout $layout, Block $block, $renderer_name) {
  if (backdrop_get_token('layout-' . $layout->name) !== $_GET['token']) {
    return MENU_ACCESS_DENIED;
  }

  $commands = array();
  $layout->removeBlock($block->uuid);
  layout_set_layout_tempstore($layout);

  if (backdrop_is_ajax()) {
    $commands[] = ajax_command_remove('#layout-editor-block-' . $block->uuid);
    // If neither a Title block nor a Combo block remains in the layout, add
    // the page title pseudo-region.
    if ($block->module == 'system' && $block->delta == 'page_components' && ($block->childDelta == 'title' || $block->childDelta == 'title_combo')) {
      $render_title_region = TRUE;
      $all_layout_blocks = $layout->content;
      foreach ($all_layout_blocks as $existing_block) {
        if ($existing_block->module == 'system' && $existing_block->delta == 'page_components' && ($existing_block->childDelta == 'title' || $existing_block->childDelta == 'title_combo') && ($existing_block->uuid != $block->uuid)) {
          $render_title_region = FALSE;
          break;
        }
      }
      if ($render_title_region) {
        $renderer = layout_create_renderer($renderer_name, $layout);
        $commands[] = ajax_command_replace('#layout-title-region-empty', $renderer->renderTitleRegion('title'));
      }
    }
    return array(
      '#type' => 'ajax',
      '#commands' => $commands,
    );
  }
  else {
    backdrop_set_message(t('Block "@title" removed.', array('@title' => $block->getAdminTitle())));
    backdrop_goto('admin/structure/layouts/manage/' . $layout->name);
  }
}