Commit caac9c9f authored by catch's avatar catch
Browse files

Issue #3084436 by longwave, simonminter, Spokje, alexpott, alisonjo315,...

Issue #3084436 by longwave, simonminter, Spokje, alexpott, alisonjo315, pameeela, webel: Config export field should be cleared when config type changes
parent cf221c04
......@@ -75,6 +75,8 @@ public function getFormId() {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $config_type = NULL, $config_name = NULL) {
$form['#prefix'] = '<div id="js-config-form-wrapper">';
$form['#suffix'] = '</div>';
foreach ($this->entityTypeManager->getDefinitions() as $entity_type => $definition) {
if ($definition->entityClassImplements(ConfigEntityInterface::class)) {
$this->definitions[$entity_type] = $definition;
......@@ -95,7 +97,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $config_t
'#default_value' => $config_type,
'#ajax' => [
'callback' => '::updateConfigurationType',
'wrapper' => 'edit-config-type-wrapper',
'wrapper' => 'js-config-form-wrapper',
],
];
$default_type = $form_state->getValue('config_type', $config_type);
......@@ -134,7 +136,8 @@ public function buildForm(array $form, FormStateInterface $form_state, $config_t
*/
public function updateConfigurationType($form, FormStateInterface $form_state) {
$form['config_name']['#options'] = $this->findConfiguration($form_state->getValue('config_type'));
return $form['config_name'];
unset($form['export']['#value']);
return $form;
}
/**
......
<?php
namespace Drupal\Tests\config\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
/**
* Tests the config export form.
*
* @group config
*/
class ConfigExportTest extends WebDriverTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['config', 'system'];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests Ajax form functionality on the config export page.
*/
public function testAjaxOnExportPage() {
$this->drupalLogin($this->drupalCreateUser([
'export configuration',
]));
$page = $this->getSession()->getPage();
// Check that the export is empty on load.
$this->drupalGet('admin/config/development/configuration/single/export');
$this->assertSession()->fieldValueEquals('export', '');
// Check that the export is filled when selecting a config name.
$page->selectFieldOption('config_name', 'system.site');
$this->assertSession()->assertWaitOnAjaxRequest();
$this->assertSession()->fieldValueNotEquals('export', '');
// Check that the export is emptied again when selecting a config type.
$page->selectFieldOption('config_type', 'Action');
$this->assertSession()->assertWaitOnAjaxRequest();
$this->assertSession()->fieldValueEquals('export', '');
}
}
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