diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Block/CustomBlockBlock.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Block/CustomBlockBlock.php index 3731471a9cc9..7980f2d30a4f 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Block/CustomBlockBlock.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Block/CustomBlockBlock.php @@ -113,6 +113,7 @@ class CustomBlockBlock extends BlockBase implements ContainerFactoryPluginInterf public function blockSubmit($form, &$form_state) { // Invalidate the block cache to update custom block-based derivatives. if ($this->moduleHandler->moduleExists('block')) { + $this->configuration['view_mode'] = $form_state['values']['custom_block']['view_mode']; $this->blockManager->clearCachedDefinitions(); } } diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockCreationTest.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockCreationTest.php index e94e22151002..cae2d0efa4b1 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockCreationTest.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockCreationTest.php @@ -46,9 +46,21 @@ class CustomBlockCreationTest extends CustomBlockTestBase { * Creates a "Basic page" block and verifies its consistency in the database. */ public function testCustomBlockCreation() { + // Add a new view mode and verify if it is selected as expected. + $this->drupalLogin($this->drupalCreateUser(array('administer display modes'))); + $this->drupalGet('admin/structure/display-modes/view/add/custom_block'); + $edit = array( + 'id' => 'test_view_mode', + 'label' => 'Test View Mode', + ); + $this->drupalPostForm(NULL, $edit, t('Save')); + $this->assertRaw(t('Saved the %label view mode.', array('%label' => $edit['label']))); + + $this->drupalLogin($this->adminUser); + // Create a block. $edit = array(); - $edit['info'] = $this->randomName(8); + $edit['info'] = 'Test Block'; $edit['body[0][value]'] = $this->randomName(16); $this->drupalPostForm('block/add/basic', $edit, t('Save')); @@ -58,6 +70,14 @@ class CustomBlockCreationTest extends CustomBlockTestBase { '%name' => $edit["info"] )), 'Basic block created.'); + // Change the view mode. + $view_mode['settings[custom_block][view_mode]'] = 'test_view_mode'; + $this->drupalPostForm(NULL, $view_mode, t('Save block')); + + // Go to the configure page and verify that the new view mode is correct. + $this->drupalGet('admin/structure/block/manage/testblock'); + $this->assertFieldByXPath('//select[@name="settings[custom_block][view_mode]"]/option[@selected="selected"]/@value', 'test_view_mode', 'View mode changed to Test View Mode'); + // Check that the block exists in the database. $blocks = entity_load_multiple_by_properties('custom_block', array('info' => $edit['info'])); $block = reset($blocks);