Unverified Commit 75534512 authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #3089523 by benjifisher, jhodgdon: Use progressive disclosure to hide...

Issue #3089523 by benjifisher, jhodgdon: Use progressive disclosure to hide Sort options on entity reference fields until bundles are selected
parent 7d5fbe96
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -232,6 +232,13 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
        '#limit_validation_errors' => [],
        '#default_value' => $configuration['sort']['field'],
      ];
      if ($entity_type->hasKey('bundle')) {
        $form['sort']['field']['#states'] = [
          'visible' => [
            ':input[name^="settings[handler_settings][target_bundles]["]' => ['checked' => TRUE],
          ],
        ];
      }

      $form['sort']['settings'] = [
        '#type' => 'container',
+8 −2
Original line number Diff line number Diff line
@@ -101,9 +101,16 @@ public function testFieldAdminHandler() {
    $entity_type_id = 'node';
    // Check that the type label is correctly displayed.
    $assert_session->pageTextContains('Content type');
    // Check that sort options are not yet visible.
    $sort_by = $page->findField('settings[handler_settings][sort][field]');
    $this->assertNotEmpty($sort_by);
    $this->assertFalse($sort_by->isVisible(), 'The "sort by" options are hidden.');
    // Select all bundles so that sort options are available.
    $bundles = $this->container->get('entity_type.bundle.info')->getBundleInfo($entity_type_id);
    foreach ($bundles as $bundle_name => $bundle_info) {
      $this->assertFieldByName('settings[handler_settings][target_bundles][' . $bundle_name . ']');
      $page->findField('settings[handler_settings][target_bundles][' . $bundle_name . ']')->setValue($bundle_name);
      $assert_session->assertWaitOnAjaxRequest();
    }

    reset($bundles);
@@ -143,8 +150,6 @@ public function testFieldAdminHandler() {
    $this->assertNoFieldByName('settings[handler_settings][sort][direction]');

    // Third step: confirm.
    $page->findField('settings[handler_settings][target_bundles][' . key($bundles) . ']')->setValue(key($bundles));
    $assert_session->assertWaitOnAjaxRequest();
    $this->drupalPostForm(NULL, [
      'required' => '1',
    ], t('Save settings'));
@@ -177,6 +182,7 @@ public function testFieldAdminHandler() {
    $this->drupalPostForm($bundle_path . '/fields/' . $field_name . '/storage', $edit, t('Save field settings'));
    $this->drupalGet($bundle_path . '/fields/' . $field_name);
    $this->assertFieldByName('settings[handler_settings][filter][type]', '_none');
    $this->assertFieldByName('settings[handler_settings][sort][field]', '_none');

    // Switch the target type to 'node'.
    $field_name = 'node.' . $this->type . '.field_test';