From 956b110a1e2440676452760250b634185b9afefc Mon Sep 17 00:00:00 2001 From: webchick Date: Sat, 19 Jan 2013 20:09:48 -0800 Subject: [PATCH] =?UTF-8?q?Issue=20#1884762=20by=20tim.plunkett,=20G=C3=A1?= =?UTF-8?q?bor=20Hojtsy:=20Block=20forms=20should=20use=20#type=20=3D>=20m?= =?UTF-8?q?achine=5Fname().?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/modules/block/lib/Drupal/block/BlockBase.php | 13 ++++++------- .../lib/Drupal/block/Tests/BlockLanguageTest.php | 2 +- .../block/lib/Drupal/block/Tests/BlockTest.php | 12 ++++++------ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/core/modules/block/lib/Drupal/block/BlockBase.php b/core/modules/block/lib/Drupal/block/BlockBase.php index c9812b7c5aa..73d97346b96 100644 --- a/core/modules/block/lib/Drupal/block/BlockBase.php +++ b/core/modules/block/lib/Drupal/block/BlockBase.php @@ -241,11 +241,15 @@ abstract class BlockBase extends PluginBase implements BlockInterface { '#default_value' => !$entity->isNew() ? $entity->label() : $definition['subject'], ); $form['machine_name'] = array( - '#type' => 'textfield', + '#type' => 'machine_name', '#title' => t('Block machine name'), '#maxlength' => 64, '#description' => t('A unique name to save this block configuration. Must be alpha-numeric and be underscore separated.'), '#default_value' => $entity->id(), + '#machine_name' => array( + 'exists' => 'block_load', + 'replace_pattern' => '[^a-z0-9_.]+', + ), '#required' => TRUE, '#disabled' => !$entity->isNew(), ); @@ -419,12 +423,7 @@ abstract class BlockBase extends PluginBase implements BlockInterface { * @see \Drupal\block\BlockBase::blockValidate() */ public function validate($form, &$form_state) { - if (empty($form['machine_name']['#disabled'])) { - if (preg_match('/[^a-zA-Z0-9_]/', $form_state['values']['machine_name'])) { - form_set_error('machine_name', t('Block name must be alphanumeric or underscores only.')); - } - } - else { + if (!empty($form['machine_name']['#disabled'])) { $config_id = explode('.', $form_state['values']['machine_name']); $form_state['values']['machine_name'] = array_pop($config_id); } diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockLanguageTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockLanguageTest.php index b9ac7142f3b..49fc6e258b1 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockLanguageTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockLanguageTest.php @@ -62,7 +62,7 @@ class BlockLanguageTest extends WebTestBase { // Enable a standard block and set the visibility setting for one language. $edit = array( 'visibility[language][langcodes][en]' => TRUE, - 'machine_name' => $this->randomName(8), + 'machine_name' => strtolower($this->randomName(8)), 'region' => 'sidebar_first', ); $this->drupalPost('admin/structure/block/add/system_powered_by_block' . '/' . $default_theme, $edit, t('Save block')); diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php index 67796b10f3e..cd6b40fee44 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php @@ -157,7 +157,7 @@ class BlockTest extends WebTestBase { $this->removeDefaultBlocks(); // Add a new custom block by filling out the input form on the admin/structure/block/add page. - $info = $this->randomName(8); + $info = strtolower($this->randomName(8)); $custom_block['machine_name'] = $info; $custom_block['info'] = $info; $custom_block['label'] = $this->randomName(8); @@ -199,7 +199,7 @@ class BlockTest extends WebTestBase { // Enable a standard block. $default_theme = variable_get('theme_default', 'stark'); $edit = array( - 'machine_name' => $this->randomName(8), + 'machine_name' => strtolower($this->randomName(8)), 'region' => 'sidebar_first', 'label' => $title, ); @@ -239,7 +239,7 @@ class BlockTest extends WebTestBase { // Enable a standard block. $default_theme = variable_get('theme_default', 'stark'); $edit = array( - 'machine_name' => $this->randomName(8), + 'machine_name' => strtolower($this->randomName(8)), 'region' => 'sidebar_first', 'label' => $title, 'visibility[path][visibility]' => BLOCK_VISIBILITY_LISTED, @@ -270,7 +270,7 @@ class BlockTest extends WebTestBase { $block = array(); $block['id'] = 'system_powered_by_block'; $block['label'] = $this->randomName(8); - $block['machine_name'] = $this->randomName(8); + $block['machine_name'] = strtolower($this->randomName(8)); $block['theme'] = variable_get('theme_default', 'stark'); $block['region'] = 'header'; @@ -351,7 +351,7 @@ class BlockTest extends WebTestBase { // Add a test block. $block = array(); $block['id'] = 'test_cache'; - $block['machine_name'] = $this->randomName(8); + $block['machine_name'] = strtolower($this->randomName(8)); $block['theme'] = variable_get('theme_default', 'stark'); $block['region'] = 'header'; $block = $this->drupalPlaceBlock('test_cache', array('region' => 'header')); @@ -427,7 +427,7 @@ class BlockTest extends WebTestBase { // that the form still functions as expected. $edit = array( 'label' => $this->randomName(8), - 'machine_name' => $this->randomName(8), + 'machine_name' => strtolower($this->randomName(8)), 'region' => 'sidebar_first', ); $this->drupalPost('admin/structure/block/add/system_powered_by_block/stark', $edit, t('Save block'));