diff --git a/core/modules/block/block.admin.inc b/core/modules/block/block.admin.inc index 0808ff1..26b34ba 100644 --- a/core/modules/block/block.admin.inc +++ b/core/modules/block/block.admin.inc @@ -116,8 +116,8 @@ function block_admin_display_form($form, &$form_state, $blocks, $theme, $block_r $form['blocks'] = array(); $form['#tree'] = TRUE; - foreach ($blocks as $key => $instance) { - $info = $instance->getPlugin()->getDefinition(); + foreach ($blocks as $key => $block) { + $info = $block->getPlugin()->getDefinition(); $form['blocks'][$key]['info'] = array( '#markup' => check_plain($info['subject']), ); @@ -127,14 +127,14 @@ function block_admin_display_form($form, &$form_state, $blocks, $theme, $block_r ); $form['blocks'][$key]['weight'] = array( '#type' => 'weight', - '#default_value' => $instance->get('weight'), + '#default_value' => $block->get('weight'), '#delta' => $weight_delta, '#title_display' => 'invisible', '#title' => t('Weight for @block block', array('@block' => $info['subject'])), ); $form['blocks'][$key]['region'] = array( '#type' => 'select', - '#default_value' => $instance->get('region') != BLOCK_REGION_NONE ? $instance->get('region') : NULL, + '#default_value' => $block->get('region') != BLOCK_REGION_NONE ? $block->get('region') : NULL, '#empty_value' => BLOCK_REGION_NONE, '#title_display' => 'invisible', '#title' => t('Region for @block block', array('@block' => $info['subject'])), @@ -227,10 +227,8 @@ function _block_compare(Block $a, Block $b) { return $weight; } } - // Sort by title. - $ainfo = $a->getPlugin()->getDefinition(); - $binfo = $b->getPlugin()->getDefinition(); - return strcmp($ainfo['subject'], $binfo['subject']); + // Sort by label. + return strcmp($a->label(), $b->label()); } /** @@ -256,15 +254,13 @@ function block_admin_add($plugin_id, $theme = NULL) { /** * Page callback: Build the block instance edit form. * - * @param string $entity_id - * The entity ID for the block instance. + * @param \Drupal\block\Plugin\Core\Entity\Block $entity + * The block instance. * * @return array * The block instance edit form. */ -function block_admin_edit($entity_id) { - $entity = entity_load('block', $entity_id); - +function block_admin_edit($entity) { // Get the theme for the page title. $admin_theme = config('system.theme')->get('admin'); $themes = list_themes(); @@ -288,21 +284,16 @@ function block_admin_edit($entity_id) { /** * Form constructor for the block instance deletion form. * - * @param string $plugin_id - * The plugin ID for the block instance. + * @param \Drupal\block\Plugin\Core\Entity\Block $entity + * The block instance. * * @see block_menu() * @see block_admin_block_delete_submit() */ -function block_admin_block_delete($form, &$form_state, $plugin_id) { - $block = entity_load('block', $plugin_id); - $subject = $block->label(); - list($theme) = explode('.', $plugin_id); - $form['id'] = array('#type' => 'value', '#value' => $plugin_id); - $form['theme'] = array('#type' => 'value', '#value' => $theme); - $form['subject'] = array('#type' => 'value', '#value' => $subject); - - return confirm_form($form, t('Are you sure you want to delete the block %name?', array('%name' => $subject)), 'admin/structure/block', '', t('Delete'), t('Cancel')); +function block_admin_block_delete($form, &$form_state, $entity) { + $form['id'] = array('#type' => 'value', '#value' => $entity->id()); + + return confirm_form($form, t('Are you sure you want to delete the block %name?', array('%name' => $entity->label())), 'admin/structure/block', '', t('Delete'), t('Cancel')); } /** @@ -311,10 +302,10 @@ function block_admin_block_delete($form, &$form_state, $plugin_id) { * @see block_admin_block_delete() */ function block_admin_block_delete_submit($form, &$form_state) { - $block = entity_load('block', $form_state['values']['id']); - $block->delete(); - drupal_set_message(t('The block %name has been removed.', array('%name' => $form_state['values']['subject']))); - $form_state['redirect'] = 'admin/structure/block/list/block_plugin_ui:' . $form_state['values']['theme']; + $entity = entity_load('block', $form_state['values']['id']); + drupal_set_message(t('The block %name has been removed.', array('%name' => $entity->label()))); + $form_state['redirect'] = 'admin/structure/block/list/block_plugin_ui:' . $entity->get('theme'); + $entity->delete(); } /** diff --git a/core/modules/block/block.module b/core/modules/block/block.module index 23e1533..b6a5381 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -128,19 +128,19 @@ function block_menu() { 'access arguments' => array('administer blocks'), 'file' => 'block.admin.inc', ); - $items['admin/structure/block/manage/%'] = array( + $items['admin/structure/block/manage/%block'] = array( 'title' => 'Configure block', 'page callback' => 'block_admin_edit', 'page arguments' => array(4), 'access arguments' => array('administer blocks'), 'file' => 'block.admin.inc', ); - $items['admin/structure/block/manage/%/configure'] = array( + $items['admin/structure/block/manage/%block/configure'] = array( 'title' => 'Configure block', 'type' => MENU_DEFAULT_LOCAL_TASK, 'context' => MENU_CONTEXT_INLINE, ); - $items['admin/structure/block/manage/%/delete'] = array( + $items['admin/structure/block/manage/%block/delete'] = array( 'title' => 'Delete block', 'page callback' => 'drupal_get_form', 'page arguments' => array('block_admin_block_delete', 4), @@ -461,6 +461,21 @@ function block_list($region) { } /** + * Loads a block instance. + * + * This should only be used when entity_load() cannot be used directly. + * + * @param string $entity_id + * The block ID. + * + * @return \Drupal\block\Plugin\Core\Entity\Block + * The loaded block object. + */ +function block_load($entity_id) { + return entity_load('block', $entity_id); +} + +/** * Builds the content and subject for a block. * * For cacheable blocks, this is called during #pre_render.