Commit 86977a15 authored by alexpott's avatar alexpott

Issue #1919930 by tim.plunkett, nlisgo: Bundle entity form IDs violate module...

Issue #1919930 by tim.plunkett, nlisgo: Bundle entity form IDs violate module namespaces (both on server-side + front-end CSS)
parent c01a6803
...@@ -83,7 +83,7 @@ public function getBaseFormId() { ...@@ -83,7 +83,7 @@ public function getBaseFormId() {
public function getFormId() { public function getFormId() {
$form_id = $this->entity->getEntityTypeId(); $form_id = $this->entity->getEntityTypeId();
if ($this->entity->getEntityType()->hasKey('bundle')) { if ($this->entity->getEntityType()->hasKey('bundle')) {
$form_id = $this->entity->bundle() . '_' . $form_id; $form_id .= '_' . $this->entity->bundle();
} }
if ($this->operation != 'default') { if ($this->operation != 'default') {
$form_id = $form_id . '_' . $this->operation; $form_id = $form_id . '_' . $this->operation;
......
...@@ -108,11 +108,6 @@ public function form(array $form, FormStateInterface $form_state) { ...@@ -108,11 +108,6 @@ public function form(array $form, FormStateInterface $form_state) {
$current_user = $this->currentUser(); $current_user = $this->currentUser();
// Override the default CSS class name, since the user-defined node type
// name in 'TYPE-node-form' potentially clashes with third-party class
// names.
$form['#attributes']['class'][0] = Html::getClass('node-' . $node->getType() . '-form');
// Changed must be sent to the client, for later overwrite error checking. // Changed must be sent to the client, for later overwrite error checking.
$form['changed'] = array( $form['changed'] = array(
'#type' => 'hidden', '#type' => 'hidden',
......
...@@ -52,7 +52,7 @@ protected function setUp() { ...@@ -52,7 +52,7 @@ protected function setUp() {
} }
/** /**
* Tests that pages with the 'page_node_form' included twice work correctly. * Tests that pages with the 'node_page_form' included twice work correctly.
*/ */
function testMultiForm() { function testMultiForm() {
// HTML IDs for elements within the field are potentially modified with // HTML IDs for elements within the field are potentially modified with
...@@ -60,8 +60,8 @@ function testMultiForm() { ...@@ -60,8 +60,8 @@ function testMultiForm() {
// desired elements. // desired elements.
$field_name = 'field_ajax_test'; $field_name = 'field_ajax_test';
$field_xpaths = array( $field_xpaths = array(
'page-node-form' => '//form[@id="page-node-form"]//div[contains(@class, "field-name-field-ajax-test")]', 'node-page-form' => '//form[@id="node-page-form"]//div[contains(@class, "field-name-field-ajax-test")]',
'page-node-form--2' => '//form[@id="page-node-form--2"]//div[contains(@class, "field-name-field-ajax-test")]', 'node-page-form--2' => '//form[@id="node-page-form--2"]//div[contains(@class, "field-name-field-ajax-test")]',
); );
$button_name = $field_name . '_add_more'; $button_name = $field_name . '_add_more';
$button_value = t('Add another item'); $button_value = t('Add another item');
......
...@@ -89,7 +89,7 @@ function testPreserveFormActionAfterAJAX() { ...@@ -89,7 +89,7 @@ function testPreserveFormActionAfterAJAX() {
// submission and verify it worked by ensuring the updated page has two text // submission and verify it worked by ensuring the updated page has two text
// field items in the field for which we just added an item. // field items in the field for which we just added an item.
$this->drupalGet('node/add/page'); $this->drupalGet('node/add/page');
$this->drupalPostAjaxForm(NULL, array(), array('field_ajax_test_add_more' => t('Add another item')), 'system/ajax', array(), array(), 'page-node-form'); $this->drupalPostAjaxForm(NULL, array(), array('field_ajax_test_add_more' => t('Add another item')), 'system/ajax', array(), array(), 'node-page-form');
$this->assert(count($this->xpath('//div[contains(@class, "field-name-field-ajax-test")]//input[@type="text"]')) == 2, 'AJAX submission succeeded.'); $this->assert(count($this->xpath('//div[contains(@class, "field-name-field-ajax-test")]//input[@type="text"]')) == 2, 'AJAX submission succeeded.');
// Submit the form with the non-Ajax "Save" button, leaving the title field // Submit the form with the non-Ajax "Save" button, leaving the title field
...@@ -102,7 +102,7 @@ function testPreserveFormActionAfterAJAX() { ...@@ -102,7 +102,7 @@ function testPreserveFormActionAfterAJAX() {
// Ensure that the form contains two items in the multi-valued field, so we // Ensure that the form contains two items in the multi-valued field, so we
// know we're testing a form that was correctly retrieved from cache. // know we're testing a form that was correctly retrieved from cache.
$this->assert(count($this->xpath('//form[contains(@id, "page-node-form")]//div[contains(@class, "form-item-field-ajax-test")]//input[@type="text"]')) == 2, 'Form retained its state from cache.'); $this->assert(count($this->xpath('//form[contains(@id, "node-page-form")]//div[contains(@class, "form-item-field-ajax-test")]//input[@type="text"]')) == 2, 'Form retained its state from cache.');
// Ensure that the form's action is correct. // Ensure that the form's action is correct.
$forms = $this->xpath('//form[contains(@class, "node-page-form")]'); $forms = $this->xpath('//form[contains(@class, "node-page-form")]');
......
...@@ -67,29 +67,29 @@ public function testFormId($expected, $definition) { ...@@ -67,29 +67,29 @@ public function testFormId($expected, $definition) {
*/ */
public function providerTestFormIds() { public function providerTestFormIds() {
return array( return array(
array('article_node_form', array( array('node_article_form', array(
'bundle' => 'article',
'entity_type' => 'node', 'entity_type' => 'node',
'bundle' => 'article',
'operation' => 'default', 'operation' => 'default',
)), )),
array('article_node_delete_form', array( array('node_article_delete_form', array(
'bundle' => 'article',
'entity_type' => 'node', 'entity_type' => 'node',
'bundle' => 'article',
'operation' => 'delete', 'operation' => 'delete',
)), )),
array('user_user_form', array( array('user_user_form', array(
'bundle' => 'user',
'entity_type' => 'user', 'entity_type' => 'user',
'bundle' => 'user',
'operation' => 'default', 'operation' => 'default',
)), )),
array('user_form', array( array('user_form', array(
'bundle' => '',
'entity_type' => 'user', 'entity_type' => 'user',
'bundle' => '',
'operation' => 'default', 'operation' => 'default',
)), )),
array('user_delete_form', array( array('user_delete_form', array(
'bundle' => '',
'entity_type' => 'user', 'entity_type' => 'user',
'bundle' => '',
'operation' => 'delete', 'operation' => 'delete',
)), )),
); );
......
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