Commit 4118ac6c authored by catch's avatar catch

Issue #3158651 by paulocs, benjifisher, abhisekmazumdar, himanshu_sindhwani,...

Issue #3158651 by paulocs, benjifisher, abhisekmazumdar, himanshu_sindhwani, sarvjeetsingh, mayurjadhav, Vidushi Mehta, janmejaig, thalles, quietone: Sort direction is not hidden when no sort field is selected
parent 652efc72
......@@ -246,18 +246,31 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
'#process' => [[EntityReferenceItem::class, 'formProcessMergeParent']],
];
if ($configuration['sort']['field'] != '_none') {
$form['sort']['settings']['direction'] = [
'#type' => 'select',
'#title' => $this->t('Sort direction'),
'#required' => TRUE,
'#options' => [
'ASC' => $this->t('Ascending'),
'DESC' => $this->t('Descending'),
$form['sort']['settings']['direction'] = [
'#type' => 'select',
'#title' => $this->t('Sort direction'),
'#required' => TRUE,
'#options' => [
'ASC' => $this->t('Ascending'),
'DESC' => $this->t('Descending'),
],
'#default_value' => $configuration['sort']['direction'],
'#states' => [
'visible' => [
':input[name="settings[handler_settings][sort][field]"]' => [
'!value' => '_none',
],
],
],
];
if ($entity_type->hasKey('bundle')) {
$form['sort']['settings']['direction']['#states']['visible'][] = [
':input[name^="settings[handler_settings][target_bundles]["]' => [
'checked' => TRUE,
],
'#default_value' => $configuration['sort']['direction'],
];
}
}
$form['auto_create'] = [
......
......@@ -126,10 +126,12 @@ public function testFieldAdminHandler() {
// Option 0: no sort.
$this->assertSession()->fieldValueEquals('settings[handler_settings][sort][field]', '_none');
$sort_by = $page->findField('settings[handler_settings][sort][field]');
$this->assertSession()->fieldNotExists('settings[handler_settings][sort][direction]');
$sort_direction = $page->findField('settings[handler_settings][sort][direction]');
$this->assertFalse($sort_direction->isVisible());
// Option 1: sort by field.
$sort_by->setValue('nid');
$assert_session->waitForField('settings[handler_settings][sort][direction]');
$assert_session->assertWaitOnAjaxRequest();
$this->assertTrue($sort_direction->isVisible());
$this->assertSession()->fieldValueEquals('settings[handler_settings][sort][direction]', 'ASC');
// Test that the sort-by options are sorted.
......@@ -154,7 +156,24 @@ public function testFieldAdminHandler() {
// Set back to no sort.
$sort_by->setValue('_none');
$assert_session->assertWaitOnAjaxRequest();
$this->assertSession()->fieldNotExists('settings[handler_settings][sort][direction]');
$this->assertFalse($sort_direction->isVisible());
// Sort by nid, then select no bundles. The sort fields and sort direction
// should not display. Then select all bundles again.
$sort_by->setValue('nid');
$assert_session->assertWaitOnAjaxRequest();
foreach ($bundles as $bundle_name => $bundle_info) {
$this->assertSession()->fieldExists('settings[handler_settings][target_bundles][' . $bundle_name . ']');
$page->findField('settings[handler_settings][target_bundles][' . $bundle_name . ']')->uncheck();
$assert_session->assertWaitOnAjaxRequest();
}
$sort_direction = $page->findField('settings[handler_settings][sort][direction]');
$this->assertFalse($sort_direction->isVisible());
foreach ($bundles as $bundle_name => $bundle_info) {
$this->assertSession()->fieldExists('settings[handler_settings][target_bundles][' . $bundle_name . ']');
$page->findField('settings[handler_settings][target_bundles][' . $bundle_name . ']')->setValue($bundle_name);
$sort_direction = $page->findField('settings[handler_settings][sort][direction]');
}
// Third step: confirm.
$this->drupalPostForm(NULL, [
......@@ -191,6 +210,13 @@ public function testFieldAdminHandler() {
$this->assertSession()->fieldValueEquals('settings[handler_settings][filter][type]', '_none');
$this->assertSession()->fieldValueEquals('settings[handler_settings][sort][field]', '_none');
// Check that sort direction is visible only when a sort field is selected.
$sort_direction = $page->findField('settings[handler_settings][sort][direction]');
$this->assertFalse($sort_direction->isVisible());
$sort_by->setValue('name');
$assert_session->assertWaitOnAjaxRequest();
$this->assertTrue($sort_direction->isVisible());
// Switch the target type to 'node'.
$field_name = 'node.' . $this->type . '.field_test';
$edit = [
......
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