diff --git a/core/lib/Drupal/Core/Block/BlockBase.php b/core/lib/Drupal/Core/Block/BlockBase.php index fc614b0121c..bcc3954ae69 100644 --- a/core/lib/Drupal/Core/Block/BlockBase.php +++ b/core/lib/Drupal/Core/Block/BlockBase.php @@ -245,7 +245,7 @@ abstract class BlockBase extends ContextAwarePluginBase implements BlockPluginIn $transliterated = $this->transliteration()->transliterate($admin_label, LanguageInterface::LANGCODE_DEFAULT, '_'); $transliterated = Unicode::strtolower($transliterated); - $transliterated = preg_replace('@[^a-z0-9_]+@', '', $transliterated); + $transliterated = preg_replace('@[^a-z0-9_.]+@', '', $transliterated); return $transliterated; } diff --git a/core/modules/block/src/BlockForm.php b/core/modules/block/src/BlockForm.php index 8417c3597fd..35258b8cd94 100644 --- a/core/modules/block/src/BlockForm.php +++ b/core/modules/block/src/BlockForm.php @@ -147,7 +147,7 @@ class BlockForm extends EntityForm { '#default_value' => !$entity->isNew() ? $entity->id() : $this->getUniqueMachineName($entity), '#machine_name' => array( 'exists' => '\Drupal\block\Entity\Block::load', - 'replace_pattern' => '[^a-z0-9_]+', + 'replace_pattern' => '[^a-z0-9_.]+', 'source' => array('settings', 'label'), ), '#required' => TRUE, diff --git a/core/modules/block/tests/src/Kernel/BlockMachineNameTest.php b/core/modules/block/tests/src/Kernel/BlockMachineNameTest.php deleted file mode 100644 index 34c2635fdf0..00000000000 --- a/core/modules/block/tests/src/Kernel/BlockMachineNameTest.php +++ /dev/null @@ -1,86 +0,0 @@ -installSchema('system', ['sequence']); - $this->installEntitySchema('block_content'); - $this->installEntitySchema('user'); - } - - /** - * Tests machine name collisions. - */ - public function testMachineNamesShouldNotCollideIfBlockTitlesContainPeriod() { - // Create a block type. - $type = BlockContentType::create([ - 'id' => 'whizzy', - 'label' => 'Tis whizzy', - ]); - $type->save(); - - // And a block content entity. - $block_content = BlockContent::create([ - 'type' => 'Tis whizzy', - 'info' => 'This. is whizzy', - ]); - $block_content->save(); - - // Use \Drupal\Core\Block\BlockBase::getMachineNameSuggestion to generate - // an ID. - $plugin_id = 'block_content' . PluginBase::DERIVATIVE_SEPARATOR . $block_content->uuid(); - $block_plugin = $this->container->get('plugin.manager.block')->createInstance($plugin_id, []); - $method = new \ReflectionMethod($block_plugin, 'getMachineNameSuggestion'); - $method->setAccessible(TRUE); - $id = $method->invoke($block_plugin); - - // Now place the block content entity. - $block = $this->placeBlock($plugin_id, [ - 'label' => 'This. is whizzy', - 'id' => $id, - ]); - - $theme = $this->container->get('config.factory')->get('system.theme')->get('default'); - - // Create a new entity. - /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */ - $entity_type_manager = $this->container->get('entity_type.manager'); - $new_entity = $entity_type_manager->getStorage('block')->create(array('plugin' => $plugin_id, 'theme' => $theme)); - - // Now generate a default ID like - // \Drupal\block\BlockForm::getUniqueMachineName does. - /** @var \Drupal\block\BlockForm $form_object */ - $form_object = $entity_type_manager->getFormObject('block', 'default'); - $form_object->setEntity($new_entity); - - $unique_id = $form_object->getUniqueMachineName($new_entity); - - // Assert that the new ID is different to the old one. - $this->assertNotEquals($unique_id, $block->id()); - } - -}