Commit 956b110a authored by webchick's avatar webchick

Issue #1884762 by tim.plunkett, Gábor Hojtsy: Block forms should use #type => machine_name().

parent 0143d50f
......@@ -241,11 +241,15 @@ public function form($form, &$form_state) {
'#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 @@ public function blockForm($form, &$form_state) {
* @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);
}
......
......@@ -62,7 +62,7 @@ public function testLanguageBlockVisibility() {
// 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'));
......
......@@ -157,7 +157,7 @@ public function testCustomBlockFormat() {
$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 @@ function testBlockVisibility() {
// 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 @@ function testBlockVisibilityListedEmpty() {
// 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 @@ function testBlock() {
$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 @@ function testBlockRehash() {
// 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 @@ function testBlockModuleDisable() {
// 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'));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment