Commit d38ab8a3 authored by alexpott's avatar alexpott

Issue #2170289 by plopesc, InternetDevels: Entity Display modes form allows to...

Issue #2170289 by plopesc, InternetDevels: Entity Display modes form allows to create machine names including dots.
parent ebad2e61
......@@ -27,6 +27,8 @@ class EntityDisplayModeAddForm extends EntityDisplayModeFormBase {
public function buildForm(array $form, array &$form_state, $entity_type_id = NULL) {
$this->targetEntityTypeId = $entity_type_id;
$form = parent::buildForm($form, $form_state);
// Change replace_pattern to avoid undesired dots.
$form['id']['#machine_name']['replace_pattern'] = '[^a-z0-9_]+';
$definition = $this->entityManager->getDefinition($this->targetEntityTypeId);
$form['#title'] = $this->t('Add new %label @entity-type', array('%label' => $definition->getLabel(), '@entity-type' => $this->entityType->getLowercaseLabel()));
return $form;
......
......@@ -48,8 +48,16 @@ public function testEntityViewModeUI() {
$this->drupalGet('admin/structure/display-modes/view/add');
$this->assertNoLink(t('Test entity - revisions and data table'), 'An entity type with no view builder cannot have view modes.');
// Test adding a view mode.
// Test adding a view mode including dots in machine_name.
$this->clickLink(t('Test entity'));
$edit = array(
'id' => strtolower($this->randomName()) . '.' . strtolower($this->randomName()),
'label' => $this->randomString(),
);
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertRaw('The machine-readable name must contain only lowercase letters, numbers, and underscores.');
// Test adding a view mode.
$edit = array(
'id' => strtolower($this->randomName()),
'label' => $this->randomString(),
......@@ -86,8 +94,16 @@ public function testEntityFormModeUI() {
$this->drupalGet('admin/structure/display-modes/form/add');
$this->assertNoLink(t('Entity Test without label'), 'An entity type with no form controller cannot have form modes.');
// Test adding a form mode.
// Test adding a view mode including dots in machine_name.
$this->clickLink(t('Test entity'));
$edit = array(
'id' => strtolower($this->randomName()) . '.' . strtolower($this->randomName()),
'label' => $this->randomString(),
);
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertRaw('The machine-readable name must contain only lowercase letters, numbers, and underscores.');
// Test adding a form mode.
$edit = array(
'id' => strtolower($this->randomName()),
'label' => $this->randomString(),
......
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