commit e9da7ee6d63850d25dab8e6d96cd98259cccc9c5 Author: Lee Rowlands Date: Thu Feb 14 16:59:01 2013 +1000 Patch 91 diff --git a/core/modules/block/custom_block/custom_block.module b/core/modules/block/custom_block/custom_block.module index 3ee9574..741fbfd 100644 --- a/core/modules/block/custom_block/custom_block.module +++ b/core/modules/block/custom_block/custom_block.module @@ -8,7 +8,7 @@ use Drupal\custom_block\Plugin\Core\Entity\CustomBlockType; use Drupal\custom_block\Plugin\Core\Entity\CustomBlock; use Symfony\Component\HttpFoundation\RedirectResponse; -use Drupal\custom_block\Plugin\block\block\CustomBlock as CustomBlockPlugin; +use Drupal\custom_block\Plugin\block\block\CustomBlockBlock; use Drupal\block\Plugin\Core\Entity\Block; /** @@ -260,7 +260,10 @@ function custom_block_add_body_field($block_type_id, $label = 'Block body') { */ function custom_block_form_block_plugin_ui_alter(&$form, $form_state) { foreach ($form['left']['plugin_library']['#rows'] as $plugin_id => &$row) { - @list($base, $derivative) = explode(':', $plugin_id); + if (strpos($plugin_id, ':') === FALSE) { + continue; + } + list($base, $derivative) = explode(':', $plugin_id); if ($base !== 'custom_block') { continue; } @@ -302,7 +305,7 @@ function custom_block_add_block_redirect($theme) { */ function custom_block_block_view_alter(array &$build, Block $block) { // Add contextual links for custom blocks. - if ($block->getPlugin() instanceof CustomBlockPlugin) { + if ($block->getPlugin() instanceof CustomBlockBlock) { // Move contextual links from inner content to outer wrapper. $build['#contextual_links']['custom_block'] = $build['content']['#contextual_links']['custom_block']; unset($build['content']['#contextual_links']['custom_block']); diff --git a/core/modules/block/custom_block/custom_block.pages.inc b/core/modules/block/custom_block/custom_block.pages.inc index 2af5a70..cae286e 100644 --- a/core/modules/block/custom_block/custom_block.pages.inc +++ b/core/modules/block/custom_block/custom_block.pages.inc @@ -1,4 +1,5 @@ get('request'); + if (($theme = $request->attributes->get('theme')) && in_array($theme, array_keys(list_themes()))) { // We have navigated to this page from the block library and will keep track // of the theme for redirecting the user to the configuration page for the // newly created block in the given theme. $options = array( - 'query' => array('theme' => $_GET['theme']) + 'query' => array('theme' => $theme) ); } $types = entity_load_multiple('custom_block_type'); - if (count($types) == 1) { + if ($types && count($types) == 1) { $type = reset($types); $url = url('block/add/' . $type->id(), $options); return new RedirectResponse($url); @@ -87,11 +89,12 @@ function custom_block_add(CustomBlockType $block_type) { 'type' => $block_type->id() )); $options = array(); - if (isset($_GET['theme']) && in_array($_GET['theme'], array_keys(list_themes()))) { + $request = drupal_container()->get('request'); + if (($theme = $request->attributes->get('theme')) && in_array($theme, array_keys(list_themes()))) { // We have navigated to this page from the block library and will keep track // of the theme for redirecting the user to the configuration page for the // newly created block in the given theme. - $block->setTheme($_GET['theme']); + $block->setTheme($theme); } return entity_get_form($block); } diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php index 2865baf..bec8b59 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php @@ -17,12 +17,12 @@ class CustomBlockFormController extends EntityFormControllerNG { /** + * Overrides \Drupal\Core\Entity\EntityFormController::prepareEntity(). + * * Prepares the custom block object. * * Fills in a few default values, and then invokes hook_custom_block_prepare() * on all modules. - * - * Overrides Drupal\Core\Entity\EntityFormController::prepareEntity(). */ protected function prepareEntity(EntityInterface $block) { // Set up default values, if required. @@ -38,10 +38,9 @@ protected function prepareEntity(EntityInterface $block) { } /** - * Overrides Drupal\Core\Entity\EntityFormController::form(). + * Overrides \Drupal\Core\Entity\EntityFormController::form(). */ public function form(array $form, array &$form_state, EntityInterface $block) { - // Override the default CSS class name, since the user-defined custom block // type name in 'TYPE-block-form' potentially clashes with third-party class // names. @@ -127,7 +126,7 @@ public function form(array $form, array &$form_state, EntityInterface $block) { '#type' => 'textarea', '#title' => t('Revision log message'), '#rows' => 4, - '#default_value' => !empty($block->log->value) ? $block->log->value : '', + '#default_value' => $block->log->value, '#description' => t('Briefly describe the changes you have made.'), ); @@ -135,13 +134,13 @@ public function form(array $form, array &$form_state, EntityInterface $block) { } /** + * Overrides \Drupal\Core\Entity\EntityFormController::submit(). + * * Updates the custom block object by processing the submitted values. * * This function can be called by a "Next" button of a wizard to update the * form state's entity with the current step's values before proceeding to the * next step. - * - * Overrides Drupal\Core\Entity\EntityFormController::submit(). */ public function submit(array $form, array &$form_state) { // Build the block object from the submitted values. @@ -152,16 +151,11 @@ public function submit(array $form, array &$form_state) { $block->setNewRevision(); } - foreach (module_implements('custom_block_submit') as $module) { - $function = $module . '_custom_block_submit'; - $function($block, $form, $form_state); - } - return $block; } /** - * Overrides Drupal\Core\Entity\EntityFormController::save(). + * Overrides \Drupal\Core\Entity\EntityFormController::save(). */ public function save(array $form, array &$form_state) { $block = $this->getEntity($form_state); @@ -207,7 +201,7 @@ public function save(array $form, array &$form_state) { } /** - * Overrides Drupal\Core\Entity\EntityFormController::delete(). + * Overrides \Drupal\Core\Entity\EntityFormController::delete(). */ public function delete(array $form, array &$form_state) { $destination = array(); diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockRenderController.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockRenderController.php index 60c2b7e..00fa8ec 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockRenderController.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockRenderController.php @@ -17,7 +17,7 @@ class CustomBlockRenderController extends EntityRenderController { /** - * Overrides Drupal\Core\Entity\EntityRenderController::alterBuild(). + * Overrides \Drupal\Core\Entity\EntityRenderController::alterBuild(). */ protected function alterBuild(array &$build, EntityInterface $entity, EntityDisplay $display, $view_mode, $langcode = NULL) { parent::alterBuild($build, $entity, $display, $view_mode, $langcode); diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockStorageController.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockStorageController.php index 71bb787..87ff2d5 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockStorageController.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockStorageController.php @@ -19,7 +19,7 @@ class CustomBlockStorageController extends DatabaseStorageControllerNG { /** - * Overrides Drupal\Core\Entity\DatabaseStorageController::preSaveRevision(). + * Overrides \Drupal\Core\Entity\DatabaseStorageController::preSaveRevision(). */ protected function preSaveRevision(\stdClass $record, EntityInterface $entity) { if ($entity->isNewRevision()) { @@ -44,11 +44,10 @@ protected function preSaveRevision(\stdClass $record, EntityInterface $entity) { // existing log entry with an empty one. unset($record->log); } - } /** - * Overrides Drupal\Core\Entity\DatabaseStorageController::attachLoad(). + * Overrides \Drupal\Core\Entity\DatabaseStorageController::attachLoad(). */ protected function attachLoad(&$blocks, $load_revision = FALSE) { // Create an array of block types for passing as a load argument. @@ -66,7 +65,7 @@ protected function attachLoad(&$blocks, $load_revision = FALSE) { } /** - * Overrides Drupal\Core\Entity\DatabaseStorageController::postSave(). + * Overrides \Drupal\Core\Entity\DatabaseStorageController::postSave(). */ protected function postSave(EntityInterface $block, $update) { // Invalidate the block cache to update custom block-based derivatives. @@ -105,12 +104,12 @@ public function baseFieldDefinitions() { ); $properties['type'] = array( 'label' => t('Block type'), - 'description' => t("The block type."), + 'description' => t('The block type.'), 'type' => 'string_field', ); $properties['log'] = array( 'label' => t('Revision log message'), - 'description' => t("The revision log message."), + 'description' => t('The revision log message.'), 'type' => 'string_field', ); return $properties; diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeFormController.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeFormController.php index ad9d406..77664e9 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeFormController.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeFormController.php @@ -16,7 +16,7 @@ class CustomBlockTypeFormController extends EntityFormController { /** - * Overrides Drupal\Core\Entity\EntityFormController::form(). + * Overrides \Drupal\Core\Entity\EntityFormController::form(). */ public function form(array $form, array &$form_state, EntityInterface $block_type) { $form = parent::form($form, $form_state, $block_type); @@ -84,7 +84,7 @@ public function form(array $form, array &$form_state, EntityInterface $block_typ } /** - * Overrides Drupal\Core\Entity\EntityFormController::save(). + * Overrides \Drupal\Core\Entity\EntityFormController::save(). */ public function save(array $form, array &$form_state) { $block_type = $this->getEntity($form_state); @@ -104,7 +104,7 @@ public function save(array $form, array &$form_state) { } /** - * Overrides Drupal\Core\Entity\EntityFormController::delete(). + * Overrides \Drupal\Core\Entity\EntityFormController::delete(). */ public function delete(array $form, array &$form_state) { $block_type = $this->getEntity($form_state); diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListController.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListController.php index caa93bb..8ef270c 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListController.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListController.php @@ -1,4 +1,5 @@ t('Manage fields'), 'href' => $uri['path'] . '/fields', 'options' => $uri['options'], - 'weight' => 11, + 'weight' => 15, ); $operations['manage-display'] = array( 'title' => t('Manage display'), 'href' => $uri['path'] . '/display', 'options' => $uri['options'], - 'weight' => 12, + 'weight' => 20, ); } return $operations; } /** - * Overrides Drupal\Core\Entity\EntityListController::buildHeader(). + * Overrides \Drupal\Core\Entity\EntityListController::buildHeader(). */ public function buildHeader() { $row['type'] = t('Block type'); @@ -48,7 +49,7 @@ public function buildHeader() { } /** - * Overrides Drupal\Core\Entity\EntityListController::buildRow(). + * Overrides \Drupal\Core\Entity\EntityListController::buildRow(). */ public function buildRow(EntityInterface $entity) { parent::buildRow($entity); diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlock.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlock.php index 11b5a6f..c73d76d 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlock.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlock.php @@ -131,7 +131,7 @@ public function bundle() { } /** - * Overrides Drupal\Core\Entity\Entity::createDuplicate(). + * Overrides \Drupal\Core\Entity\Entity::createDuplicate(). */ public function createDuplicate() { $duplicate = parent::createDuplicate(); @@ -141,7 +141,7 @@ public function createDuplicate() { } /** - * Overrides Drupal\Core\Entity\Entity::getRevisionId(). + * Overrides \Drupal\Core\Entity\Entity::getRevisionId(). */ public function getRevisionId() { return $this->revision_id->value; @@ -180,7 +180,9 @@ public function getTheme() { */ protected function init() { parent::init(); - // We unset all defined properties, so magic getters apply. + // We unset all defined properties except theme, so magic getters apply. + // $this->theme is a special use-case that is only used in the lifecycle of + // adding a new block using the block library. unset($this->id); unset($this->info); unset($this->revision_id); @@ -191,12 +193,15 @@ protected function init() { } /** - * Entity uri callback. + * Overrides \Drupal\Core\Entity\Entity::getRevisionId(). */ public function uri() { return array( 'path' => 'block/' . $this->id(), - 'options' => array() + 'options' => array( + 'entity_type' => $this->entityType, + 'entity' => $this, + ) ); } } diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlockType.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlockType.php index f2843f7..0ad0c32 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlockType.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlockType.php @@ -69,12 +69,15 @@ class CustomBlockType extends ConfigEntityBase { public $description; /** - * Entity uri callback. + * Overrides \Drupal\Core\Entity\Entity::getRevisionId(). */ public function uri() { return array( 'path' => 'admin/structure/custom-blocks/manage/' . $this->id(), - 'options' => array() + 'options' => array( + 'entity_type' => $this->entityType, + 'entity' => $this, + ) ); } } diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Derivative/CustomBlock.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Derivative/CustomBlock.php index bcdd305..a94fbe3 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Derivative/CustomBlock.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Derivative/CustomBlock.php @@ -40,7 +40,7 @@ public function getDerivativeDefinition($derivative_id, array $base_plugin_defin * Retrieves custom block definitions from storage. */ public function getDerivativeDefinitions(array $base_plugin_definition) { - $custom_blocks = entity_load_multiple('custom_block', entity_query('custom_block')->execute()); + $custom_blocks = entity_load_multiple('custom_block'); foreach ($custom_blocks as $custom_block) { $this->derivatives[$custom_block->uuid->value] = $base_plugin_definition; $this->derivatives[$custom_block->uuid->value]['settings'] = array( diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/block/block/CustomBlock.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/block/block/CustomBlockBlock.php similarity index 95% rename from core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/block/block/CustomBlock.php rename to core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/block/block/CustomBlockBlock.php index 3b88c43..af6d7dc 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/block/block/CustomBlock.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/block/block/CustomBlockBlock.php @@ -1,7 +1,8 @@ drupalLogin($this->adminUser); } @@ -75,7 +75,7 @@ public function testFailedBlockCreation() { $this->createCustomBlock('fail_creation'); $this->fail('Expected exception has not been thrown.'); } - catch (Exception $e) { + catch (\Exception $e) { $this->pass('Expected exception has been thrown.'); } diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockRevisionsTest.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockRevisionsTest.php index ac995ea..1ff17f4 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockRevisionsTest.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockRevisionsTest.php @@ -11,7 +11,17 @@ * Tests the block revision functionality. */ class CustomBlockRevisionsTest extends CustomBlockTestBase { + + /** + * Stores blocks created during the test. + * @var array + */ protected $blocks; + + /** + * Stores log messages used during the test. + * @var array + */ protected $logs; /** @@ -28,7 +38,7 @@ public static function getInfo() { /** * Sets the test up. */ - public function setUp() { + protected function setUp() { parent::setUp(); // Create initial block. @@ -89,4 +99,5 @@ public function testRevisions() { $default_revision = entity_load('custom_block', $loaded->id->value); $this->assertTrue($loaded->revision_id->value > $default_revision->revision_id->value, 'Revision id is greater than default revision id.'); } + } diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockSaveTest.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockSaveTest.php index 06afda0..26fe185 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockSaveTest.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockSaveTest.php @@ -33,8 +33,9 @@ public static function getInfo() { /** * Sets the test up. */ - public function setUp() { + protected function setUp() { parent::setUp(); + $this->drupalLogin($this->adminUser); } @@ -106,4 +107,5 @@ public function testCustomBlockSaveOnInsert() { $block = $this->createCustomBlock('new'); $this->assertEqual($block->label(), 'CustomBlock ' . $block->id->value, 'Custom block saved on block insert.'); } + } diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockTestBase.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockTestBase.php index fc80298..55d6bb9 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockTestBase.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockTestBase.php @@ -45,7 +45,7 @@ /** * Sets the test up. */ - public function setUp() { + protected function setUp() { parent::setUp(); $this->adminUser = $this->drupalCreateUser($this->permissions); } diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/PageEditTest.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/PageEditTest.php index 516d1a0..3ba7b0b 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/PageEditTest.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/PageEditTest.php @@ -24,13 +24,6 @@ public static function getInfo() { } /** - * Sets the test up. - */ - public function setUp() { - parent::setUp(); - } - - /** * Checks block edit functionality. */ public function testPageEdit() { @@ -74,4 +67,5 @@ public function testPageEdit() { $revised_block = entity_load('custom_block', $block->id->value, TRUE); $this->assertNotIdentical($block->revision_id->value, $revised_block->revision_id->value, 'A new revision has been created.'); } + } diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php index 33de0fd..27dbfa1 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php @@ -154,7 +154,7 @@ public function testCustomBlockFormat() { $values = array( 'info' => $info, "block_body[$langcode][0][value]" => '

Full HTML

', - "block_body[$langcode][0][format]" => 'full_html' + "block_body[$langcode][0][format]" => 'full_html', ); $this->drupalPost('block/add/basic', $values, t('Save')); // Load the block up from the database. diff --git a/core/themes/seven/template.php b/core/themes/seven/template.php index a2c85ee..ee866c6 100644 --- a/core/themes/seven/template.php +++ b/core/themes/seven/template.php @@ -63,6 +63,8 @@ function seven_node_add_list($variables) { } /** + * Overrides theme_custom_block_add_list(). + * * Displays the list of available custom block types for creation. */ function seven_custom_block_add_list($variables) { commit 318d3e822d8c68684b321a7abfc4c3d143731fc3 Author: Lee Rowlands Date: Thu Feb 14 17:41:36 2013 +1000 Added some to-dos diff --git a/core/modules/block/custom_block/custom_block.module b/core/modules/block/custom_block/custom_block.module index 741fbfd..48528ef 100644 --- a/core/modules/block/custom_block/custom_block.module +++ b/core/modules/block/custom_block/custom_block.module @@ -260,6 +260,7 @@ function custom_block_add_body_field($block_type_id, $label = 'Block body') { */ function custom_block_form_block_plugin_ui_alter(&$form, $form_state) { foreach ($form['left']['plugin_library']['#rows'] as $plugin_id => &$row) { + // @todo Clean up when http://drupal.org/node/1874498 lands. if (strpos($plugin_id, ':') === FALSE) { continue; } diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/block/block/CustomBlockBlock.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/block/block/CustomBlockBlock.php index af6d7dc..ce89a58 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/block/block/CustomBlockBlock.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/block/block/CustomBlockBlock.php @@ -76,6 +76,7 @@ public function blockSubmit($form, &$form_state) { * Implements \Drupal\block\BlockBase::build(). */ public function build() { + // @todo Clean up when http://drupal.org/node/1874498 lands. list(, $uuid) = explode(':', $this->getPluginId()); if ($block = entity_load_by_uuid('custom_block', $uuid)) { return entity_view($block, $this->configuration['view_mode']);