Loading core/lib/Drupal/Core/Render/Element/MachineName.php +2 −1 Original line number Diff line number Diff line Loading @@ -39,7 +39,8 @@ * name'). * - replace_pattern: (optional) A regular expression (without delimiters) * matching disallowed characters in the machine name. Defaults to * '[^a-z0-9_]+'. * '[^a-z0-9_]+'. If a different replace_pattern is used, the machine * name element's '#description' should be updated accordingly. * - replace: (optional) A character to replace disallowed characters in the * machine name via JavaScript. Defaults to '_' (underscore). When using a * different character, 'replace_pattern' needs to be set accordingly. Loading core/modules/shortcut/src/ShortcutSetForm.php +1 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ public function form(array $form, FormStateInterface $form_state) { ]; $form['id'] = [ '#type' => 'machine_name', '#description' => $this->t('A unique machine-readable name. Can only contain lowercase letters, numbers, and hyphens.'), '#machine_name' => [ 'exists' => '\Drupal\shortcut\Entity\ShortcutSet::load', 'source' => ['label'], Loading core/modules/shortcut/tests/src/Functional/ShortcutSetsTest.php +29 −1 Original line number Diff line number Diff line Loading @@ -36,6 +36,8 @@ protected function setUp(): void { * Tests creating a shortcut set. */ public function testShortcutSetAdd(): void { $set_storage = $this->container->get('entity_type.manager')->getStorage('shortcut_set'); $this->drupalGet('admin/config/user-interface/shortcut'); $this->clickLink('Add shortcut set'); $edit = [ Loading @@ -43,12 +45,38 @@ public function testShortcutSetAdd(): void { 'id' => $this->randomMachineName(), ]; $this->submitForm($edit, 'Save'); $new_set = $this->container->get('entity_type.manager')->getStorage('shortcut_set')->load($edit['id']); $new_set = $set_storage->load($edit['id']); $this->assertSame($edit['id'], $new_set->id(), 'Successfully created a shortcut set.'); $this->drupalGet('user/' . $this->adminUser->id() . '/shortcuts'); // Verify that generated shortcut set was listed as a choice on the user // account page. $this->assertSession()->pageTextContains($new_set->label()); // Verify that hyphens are allowed characters in machine names and that the // machine name element description reflects this unique naming scheme. $this->drupalGet('admin/config/user-interface/shortcut/add-set'); $this->assertSession()->pageTextContains('A unique machine-readable name. Can only contain lowercase letters, numbers, and hyphens.'); $expected_id2 = 'id-with-hyphens'; $edit2 = [ 'label' => 'Hyphenated machine name', 'id' => $expected_id2, ]; $this->submitForm($edit2, 'Save'); $new_set2 = $set_storage->load($expected_id2); $this->assertEquals($expected_id2, $new_set2->id()); // Verify that underscores are disallowed characters in machine names. $this->drupalGet('admin/config/user-interface/shortcut/add-set'); $expected_id3 = 'id_with_underscores'; $edit3 = [ 'label' => 'Underscored machine name', 'id' => $expected_id3, ]; $this->submitForm($edit3, 'Save'); $this->assertSession()->pageTextContains('The machine-readable name must contain only lowercase letters, numbers, and hyphens.'); // Verify that no data was saved, since validation failed. $this->assertNull($set_storage->load($expected_id3)); } /** Loading Loading
core/lib/Drupal/Core/Render/Element/MachineName.php +2 −1 Original line number Diff line number Diff line Loading @@ -39,7 +39,8 @@ * name'). * - replace_pattern: (optional) A regular expression (without delimiters) * matching disallowed characters in the machine name. Defaults to * '[^a-z0-9_]+'. * '[^a-z0-9_]+'. If a different replace_pattern is used, the machine * name element's '#description' should be updated accordingly. * - replace: (optional) A character to replace disallowed characters in the * machine name via JavaScript. Defaults to '_' (underscore). When using a * different character, 'replace_pattern' needs to be set accordingly. Loading
core/modules/shortcut/src/ShortcutSetForm.php +1 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ public function form(array $form, FormStateInterface $form_state) { ]; $form['id'] = [ '#type' => 'machine_name', '#description' => $this->t('A unique machine-readable name. Can only contain lowercase letters, numbers, and hyphens.'), '#machine_name' => [ 'exists' => '\Drupal\shortcut\Entity\ShortcutSet::load', 'source' => ['label'], Loading
core/modules/shortcut/tests/src/Functional/ShortcutSetsTest.php +29 −1 Original line number Diff line number Diff line Loading @@ -36,6 +36,8 @@ protected function setUp(): void { * Tests creating a shortcut set. */ public function testShortcutSetAdd(): void { $set_storage = $this->container->get('entity_type.manager')->getStorage('shortcut_set'); $this->drupalGet('admin/config/user-interface/shortcut'); $this->clickLink('Add shortcut set'); $edit = [ Loading @@ -43,12 +45,38 @@ public function testShortcutSetAdd(): void { 'id' => $this->randomMachineName(), ]; $this->submitForm($edit, 'Save'); $new_set = $this->container->get('entity_type.manager')->getStorage('shortcut_set')->load($edit['id']); $new_set = $set_storage->load($edit['id']); $this->assertSame($edit['id'], $new_set->id(), 'Successfully created a shortcut set.'); $this->drupalGet('user/' . $this->adminUser->id() . '/shortcuts'); // Verify that generated shortcut set was listed as a choice on the user // account page. $this->assertSession()->pageTextContains($new_set->label()); // Verify that hyphens are allowed characters in machine names and that the // machine name element description reflects this unique naming scheme. $this->drupalGet('admin/config/user-interface/shortcut/add-set'); $this->assertSession()->pageTextContains('A unique machine-readable name. Can only contain lowercase letters, numbers, and hyphens.'); $expected_id2 = 'id-with-hyphens'; $edit2 = [ 'label' => 'Hyphenated machine name', 'id' => $expected_id2, ]; $this->submitForm($edit2, 'Save'); $new_set2 = $set_storage->load($expected_id2); $this->assertEquals($expected_id2, $new_set2->id()); // Verify that underscores are disallowed characters in machine names. $this->drupalGet('admin/config/user-interface/shortcut/add-set'); $expected_id3 = 'id_with_underscores'; $edit3 = [ 'label' => 'Underscored machine name', 'id' => $expected_id3, ]; $this->submitForm($edit3, 'Save'); $this->assertSession()->pageTextContains('The machine-readable name must contain only lowercase letters, numbers, and hyphens.'); // Verify that no data was saved, since validation failed. $this->assertNull($set_storage->load($expected_id3)); } /** Loading