Issue #1884762 by tim.plunkett, Gábor Hojtsy: Block forms should use #type => machine_name().
parent
0143d50f5d
commit
956b110a1e
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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'));
|
||||
|
|
|
@ -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'));
|
||||
|
|
Loading…
Reference in New Issue