Issue #3061266 by smustgrave, Grimreaper, ridhimaabrol24, nod_, pavnish, ithom, Hardik_Patel_12, Webbeh, alexpott: Prefix block machine name suggestions with the theme machine name

merge-requests/3534/head
Dave Long 2023-02-24 13:45:44 +00:00
parent e8554d6427
commit cfe5c87764
No known key found for this signature in database
GPG Key ID: ED52AE211E142771
7 changed files with 23 additions and 20 deletions

View File

@ -387,6 +387,9 @@ class BlockForm extends EntityForm {
*/ */
public function getUniqueMachineName(BlockInterface $block) { public function getUniqueMachineName(BlockInterface $block) {
$suggestion = $block->getPlugin()->getMachineNameSuggestion(); $suggestion = $block->getPlugin()->getMachineNameSuggestion();
if ($block->getTheme()) {
$suggestion = $block->getTheme() . '_' . $suggestion;
}
// Get all the blocks which starts with the suggested machine name. // Get all the blocks which starts with the suggested machine name.
$query = $this->storage->getQuery(); $query = $this->storage->getQuery();

View File

@ -252,7 +252,7 @@ class BlockUiTest extends BrowserTestBase {
$this->assertSession()->fieldNotExists('edit-settings-context-mapping-email'); $this->assertSession()->fieldNotExists('edit-settings-context-mapping-email');
// Test context mapping allows empty selection for optional contexts. // Test context mapping allows empty selection for optional contexts.
$this->drupalGet('admin/structure/block/manage/testcontextawareblock'); $this->drupalGet('admin/structure/block/manage/stark_testcontextawareblock');
$edit = [ $edit = [
'settings[context_mapping][user]' => '', 'settings[context_mapping][user]' => '',
]; ];
@ -262,7 +262,7 @@ class BlockUiTest extends BrowserTestBase {
$this->assertSession()->pageTextNotContains('User context found.'); $this->assertSession()->pageTextNotContains('User context found.');
// Tests that conditions with missing context are not displayed. // Tests that conditions with missing context are not displayed.
$this->drupalGet('admin/structure/block/manage/testcontextawareblock'); $this->drupalGet('admin/structure/block/manage/stark_testcontextawareblock');
$this->assertSession()->responseNotContains('No existing type'); $this->assertSession()->responseNotContains('No existing type');
$this->assertSession()->elementNotExists('xpath', '//*[@name="visibility[condition_test_no_existing_type][negate]"]'); $this->assertSession()->elementNotExists('xpath', '//*[@name="visibility[condition_test_no_existing_type][negate]"]');
} }
@ -275,7 +275,7 @@ class BlockUiTest extends BrowserTestBase {
// already exists. // already exists.
$url = 'admin/structure/block/add/test_block_instantiation/stark'; $url = 'admin/structure/block/add/test_block_instantiation/stark';
$this->drupalGet($url); $this->drupalGet($url);
$this->assertSession()->fieldValueEquals('id', 'displaymessage'); $this->assertSession()->fieldValueEquals('id', 'stark_displaymessage');
$edit = ['region' => 'content']; $edit = ['region' => 'content'];
$this->drupalGet($url); $this->drupalGet($url);
$this->submitForm($edit, 'Save block'); $this->submitForm($edit, 'Save block');
@ -283,14 +283,14 @@ class BlockUiTest extends BrowserTestBase {
// Now, check to make sure the form starts by auto-incrementing correctly. // Now, check to make sure the form starts by auto-incrementing correctly.
$this->drupalGet($url); $this->drupalGet($url);
$this->assertSession()->fieldValueEquals('id', 'displaymessage_2'); $this->assertSession()->fieldValueEquals('id', 'stark_displaymessage_2');
$this->drupalGet($url); $this->drupalGet($url);
$this->submitForm($edit, 'Save block'); $this->submitForm($edit, 'Save block');
$this->assertSession()->pageTextContains('The block configuration has been saved.'); $this->assertSession()->pageTextContains('The block configuration has been saved.');
// And verify that it continues working beyond just the first two. // And verify that it continues working beyond just the first two.
$this->drupalGet($url); $this->drupalGet($url);
$this->assertSession()->fieldValueEquals('id', 'displaymessage_3'); $this->assertSession()->fieldValueEquals('id', 'stark_displaymessage_3');
} }
/** /**
@ -339,7 +339,7 @@ class BlockUiTest extends BrowserTestBase {
// for the 'block-placement' querystring parameter. // for the 'block-placement' querystring parameter.
$this->clickLink('Place block'); $this->clickLink('Place block');
$this->submitForm([], 'Save block'); $this->submitForm([], 'Save block');
$this->assertSession()->addressEquals('admin/structure/block/list/stark?block-placement=scriptalertxsssubjectscript'); $this->assertSession()->addressEquals('admin/structure/block/list/stark?block-placement=stark-scriptalertxsssubjectscript');
// Removing a block will remove the block placement indicator. // Removing a block will remove the block placement indicator.
$this->clickLink('Remove'); $this->clickLink('Remove');

View File

@ -209,7 +209,7 @@ class DisplayBlockTest extends ViewTestBase {
$edit = ['region' => 'content']; $edit = ['region' => 'content'];
$this->submitForm($edit, 'Save block'); $this->submitForm($edit, 'Save block');
$storage = $this->container->get('entity_type.manager')->getStorage('block'); $storage = $this->container->get('entity_type.manager')->getStorage('block');
$block = $storage->load('views_block__test_view_block_block_1'); $block = $storage->load($default_theme . '_views_block__test_view_block_block_1');
// This will only return a result if our new block has been created with the // This will only return a result if our new block has been created with the
// expected machine name. // expected machine name.
$this->assertNotEmpty($block, 'The expected block was loaded.'); $this->assertNotEmpty($block, 'The expected block was loaded.');
@ -218,7 +218,7 @@ class DisplayBlockTest extends ViewTestBase {
// Place the same block again and make sure we have a new ID. // Place the same block again and make sure we have a new ID.
$this->drupalGet('admin/structure/block/add/views_block:test_view_block-block_1/' . $default_theme); $this->drupalGet('admin/structure/block/add/views_block:test_view_block-block_1/' . $default_theme);
$this->submitForm($edit, 'Save block'); $this->submitForm($edit, 'Save block');
$block = $storage->load('views_block__test_view_block_block_1_' . $i); $block = $storage->load($default_theme . '_views_block__test_view_block_block_1_' . $i);
// This will only return a result if our new block has been created with the // This will only return a result if our new block has been created with the
// expected machine name. // expected machine name.
$this->assertNotEmpty($block, 'The expected block was loaded.'); $this->assertNotEmpty($block, 'The expected block was loaded.');
@ -232,15 +232,15 @@ class DisplayBlockTest extends ViewTestBase {
$this->drupalGet('admin/structure/block/add/views_block:test_view_block-block_1/' . $default_theme); $this->drupalGet('admin/structure/block/add/views_block:test_view_block-block_1/' . $default_theme);
$this->submitForm($edit, 'Save block'); $this->submitForm($edit, 'Save block');
$block = $storage->load('views_block__test_view_block_block_1_4'); $block = $storage->load($default_theme . '_views_block__test_view_block_block_1_4');
$config = $block->getPlugin()->getConfiguration(); $config = $block->getPlugin()->getConfiguration();
$this->assertEquals(10, $config['items_per_page'], "'Items per page' is properly saved."); $this->assertEquals(10, $config['items_per_page'], "'Items per page' is properly saved.");
$edit['settings[override][items_per_page]'] = 5; $edit['settings[override][items_per_page]'] = 5;
$this->drupalGet('admin/structure/block/manage/views_block__test_view_block_block_1_4'); $this->drupalGet('admin/structure/block/manage/' . $default_theme . '_views_block__test_view_block_block_1_4');
$this->submitForm($edit, 'Save block'); $this->submitForm($edit, 'Save block');
$block = $storage->load('views_block__test_view_block_block_1_4'); $block = $storage->load($default_theme . '_views_block__test_view_block_block_1_4');
$config = $block->getPlugin()->getConfiguration(); $config = $block->getPlugin()->getConfiguration();
$this->assertEquals(5, $config['items_per_page'], "'Items per page' is properly saved."); $this->assertEquals(5, $config['items_per_page'], "'Items per page' is properly saved.");
@ -252,7 +252,7 @@ class DisplayBlockTest extends ViewTestBase {
$this->drupalGet('admin/structure/block/add/views_block:test_view_block-block_1/' . $default_theme); $this->drupalGet('admin/structure/block/add/views_block:test_view_block-block_1/' . $default_theme);
$this->submitForm($edit, 'Save block'); $this->submitForm($edit, 'Save block');
$block = $storage->load('views_block__test_view_block_block_1_5'); $block = $storage->load($default_theme . '_views_block__test_view_block_block_1_5');
$config = $block->getPlugin()->getConfiguration(); $config = $block->getPlugin()->getConfiguration();
$this->assertEquals('Custom title', $config['views_label'], "'Label' is properly saved."); $this->assertEquals('Custom title', $config['views_label'], "'Label' is properly saved.");
} }

View File

@ -109,7 +109,7 @@ class BlockContentCreationTest extends BlockContentTestBase {
$this->submitForm($custom_view_mode, 'Save'); $this->submitForm($custom_view_mode, 'Save');
// Go to the configure page and change the view mode. // Go to the configure page and change the view mode.
$this->drupalGet('admin/structure/block/manage/testblock'); $this->drupalGet('admin/structure/block/manage/stark_testblock');
// Test the available view mode options. // Test the available view mode options.
// Verify that the default view mode is available. // Verify that the default view mode is available.
@ -121,7 +121,7 @@ class BlockContentCreationTest extends BlockContentTestBase {
$this->submitForm($view_mode, 'Save block'); $this->submitForm($view_mode, 'Save block');
// Check that the view mode setting is shown because more than one exists. // Check that the view mode setting is shown because more than one exists.
$this->drupalGet('admin/structure/block/manage/testblock'); $this->drupalGet('admin/structure/block/manage/stark_testblock');
$this->assertSession()->fieldExists('settings[view_mode]'); $this->assertSession()->fieldExists('settings[view_mode]');
// Change the view mode. // Change the view mode.
@ -130,7 +130,7 @@ class BlockContentCreationTest extends BlockContentTestBase {
$this->submitForm($view_mode, 'Save block'); $this->submitForm($view_mode, 'Save block');
// Go to the configure page and verify the view mode has changed. // Go to the configure page and verify the view mode has changed.
$this->drupalGet('admin/structure/block/manage/testblock'); $this->drupalGet('admin/structure/block/manage/stark_testblock');
$this->assertSession()->fieldValueEquals('settings[view_mode]', 'test_view_mode'); $this->assertSession()->fieldValueEquals('settings[view_mode]', 'test_view_mode');
// Check that the block exists in the database. // Check that the block exists in the database.

View File

@ -231,7 +231,7 @@ class BlockContentTypeTest extends BlockContentTestBase {
$block = reset($blocks); $block = reset($blocks);
$this->assertSession()->addressEquals(Url::fromRoute('block.admin_add', ['plugin_id' => 'block_content:' . $block->uuid(), 'theme' => $theme])); $this->assertSession()->addressEquals(Url::fromRoute('block.admin_add', ['plugin_id' => 'block_content:' . $block->uuid(), 'theme' => $theme]));
$this->submitForm(['region' => 'content'], 'Save block'); $this->submitForm(['region' => 'content'], 'Save block');
$this->assertSession()->addressEquals(Url::fromRoute('block.admin_display_theme', ['theme' => $theme], ['query' => ['block-placement' => Html::getClass($edit['info[0][value]'])]])); $this->assertSession()->addressEquals(Url::fromRoute('block.admin_display_theme', ['theme' => $theme], ['query' => ['block-placement' => $theme . '-' . Html::getClass($edit['info[0][value]'])]]));
} }
else { else {
$this->fail('Could not load created block.'); $this->fail('Could not load created block.');

View File

@ -124,7 +124,7 @@ class FieldBlockTest extends WebDriverTestBase {
], ],
'third_party_settings' => [], 'third_party_settings' => [],
]; ];
$config = $this->container->get('config.factory')->get('block.block.datefield'); $config = $this->container->get('config.factory')->get('block.block.starterkit_theme_datefield');
$this->assertEquals($expected, $config->get('settings.formatter')); $this->assertEquals($expected, $config->get('settings.formatter'));
$this->assertEquals(['field.field.user.user.field_date'], $config->get('dependencies.config')); $this->assertEquals(['field.field.user.user.field_date'], $config->get('dependencies.config'));

View File

@ -31,7 +31,7 @@ class ContextualFiltersBlockContextTest extends ViewTestBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected $defaultTheme = 'starterkit_theme'; protected $defaultTheme = 'stark';
/** /**
* Views used by this test. * Views used by this test.
@ -103,7 +103,7 @@ class ContextualFiltersBlockContextTest extends ViewTestBase {
// Place test block via block UI to check if contexts are correctly exposed. // Place test block via block UI to check if contexts are correctly exposed.
$this->drupalGet( $this->drupalGet(
'admin/structure/block/add/views_block:test_view_block_with_context-block_1/starterkit_theme', 'admin/structure/block/add/views_block:test_view_block_with_context-block_1/stark',
['query' => ['region' => 'content']] ['query' => ['region' => 'content']]
); );
$edit = [ $edit = [
@ -115,7 +115,7 @@ class ContextualFiltersBlockContextTest extends ViewTestBase {
/** @var \Drupal\block\BlockInterface $block */ /** @var \Drupal\block\BlockInterface $block */
$block = $this->container->get('entity_type.manager') $block = $this->container->get('entity_type.manager')
->getStorage('block') ->getStorage('block')
->load('views_block__test_view_block_with_context_block_1'); ->load('stark_views_block__test_view_block_with_context_block_1');
$expected_settings = [ $expected_settings = [
'id' => 'views_block:test_view_block_with_context-block_1', 'id' => 'views_block:test_view_block_with_context-block_1',
'label' => '', 'label' => '',