Follow-up to #2413641: Add OptionWidgets for single value target type DER fields

Problem/Motivation

target type select doesn't make sense when DER has only one target type.

Proposed resolution

Remove target_type select form dynamic_entity_reference_default widget.

Remaining tasks

Write and fix tests.

User interface changes

Simple autocomplete field for DER with on target type

API changes

None

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jibran’s picture

lol @ last patch.

Status: Needs review » Needs work

The last submitted patch, 1: hide_entity_type-2448401-1.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 1: hide_entity_type-2448401-1.patch, failed testing.

jibran’s picture

Issue tags: +ER feature parity
JeroenT’s picture

Status: Needs work » Needs review
FileSize
1.81 KB

Patch no longer applied. Created a new patch.

Status: Needs review » Needs work

The last submitted patch, 6: hide_entity_type-2448401-6.patch, failed testing.

JeroenT’s picture

Status: Needs work » Needs review
FileSize
1.81 KB
457 bytes

Created a new patch. Let's see if this fixes the failed tests.

Status: Needs review » Needs work

The last submitted patch, 8: hide_entity_type-2448401-8.patch, failed testing.

jibran’s picture

+++ b/src/Plugin/Field/FieldWidget/DynamicEntityReferenceWidget.php
@@ -97,7 +97,7 @@
-        '#type' => 'value',
+        '#type' => 'hidden',

'value' is safer than 'hidden'. See https://api.drupal.org/api/drupal/developer%21topics%21forms_api_referen... and https://api.drupal.org/api/drupal/developer%21topics%21forms_api_referen... for more details.

JeroenT’s picture

Status: Needs work » Needs review
FileSize
49.14 KB

Let's see if this fixes the tests.

JeroenT’s picture

FileSize
8.29 KB

This is the right patch.

JeroenT’s picture

jibran’s picture

Great work @JeroenT. Just one point after that I think it is ready.

+++ b/tests/src/Functional/DynamicEntityReferenceWidgetTest.php
@@ -113,7 +113,6 @@ class DynamicEntityReferenceWidgetTest extends BrowserTestBase {
-      $field_name . '[0][target_type]' => $referenced_node->getEntityTypeId(),

Let's assert selectNotExists or something similar to make sure it is not on the page.

JeroenT’s picture

jibran’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs manual testing

I have done manual testing. It works great. This is RTBC for me. Can you please upload the patch for 8.x-2.x branch?

JeroenT’s picture

To be clear:

Patch in #15 is for 8.x-1.x
Patch in #17 is for 8.x-2.x

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 17: hide_entity_type-2448401-17-8.x-2.x.patch, failed testing.

JeroenT’s picture

Will look at the 8.x-2.x patch this evening.

JeroenT’s picture

Status: Needs work » Needs review
FileSize
7.22 KB
jibran’s picture

Thanks for the patch.

+++ b/tests/src/Functional/DynamicEntityReferenceWidgetTest.php
@@ -116,6 +116,9 @@
+    // Only 1 target_type is configured, so this field is not available on the
+    // node add/edit page.
+    $assert_session->fieldNotExists($field_name . '[0][target_type]');

Seems like we are missing this from 2.x patch.

JeroenT’s picture

The problem in DynamicEntityReferenceWidget test was that in 8.x-2.x there are multiple target_types instead of 1 as in 8.x-1.x. Moved adding of the config_test target_entity to method testEntityReferenceDefaultWidget.

Edit: Should be tested against 8.x-2.x of course..

JeroenT’s picture

Status: Needs review » Needs work

The last submitted patch, 22: hide_entity_type-2448401-22-8.x-2.x.patch, failed testing.

JeroenT’s picture

Status: Needs work » Needs review

2 green patches again.

#15 = 8.x-1.x
#22 = 8.x-2.x

jibran’s picture

+++ b/tests/src/Functional/DynamicEntityReferenceWidgetTest.php
@@ -134,6 +132,19 @@ class DynamicEntityReferenceWidgetTest extends BrowserTestBase {
+    $field_config = FieldConfig::loadByName('node', 'reference_content', $field_name);
+    $field_config_settings = $field_config->getSettings();
+    $field_config->setSetting('config_test', [
+      'handler' => 'default',
+      'handler_settings' => [],
+    ]);
+    $field_config->save();
+
+    $field_storage_config = FieldStorageConfig::loadByName('node', $field_name);
+    $field_storage_config_settings = $field_storage_config->getSettings();
+    $field_storage_config->setSetting('entity_type_ids', ['node', 'config_test']);
+    $field_storage_config->save();
+

@@ -144,6 +155,9 @@ class DynamicEntityReferenceWidgetTest extends BrowserTestBase {
+    // Multiple target_types are configured, so this field should be available
+    // on the node add/edit page.
+    $assert_session->fieldExists($field_name . '[0][target_type]');

@@ -153,6 +167,11 @@ class DynamicEntityReferenceWidgetTest extends BrowserTestBase {
+
+    $field_config->setSettings($field_config_settings);
+    $field_config->save();
+    $field_storage_config->setSettings($field_storage_config_settings);
+    $field_storage_config->save();

I think tests changes from #2829602: Disable optgroup in select list when only 1 target_bundle is available. also got into this patch other then that this is RTBC.

JeroenT’s picture

@jibran,

These are not the same changes as in #2829602: Disable optgroup in select list when only 1 target_bundle is available.. I added these changes in testEntityReferenceDefaultWidget so I can test if the target_type select is present when you can reference multiple entity types and not present when you can reference only 1 entity type. I also had to add this to test the reference with config entitites.

jibran’s picture

Status: Needs review » Reviewed & tested by the community

Oh! got it. Thanks for explanation. This is also ready.

  • jibran committed 369f0b3 on 8.x-2.x authored by JeroenT
    Issue #2448401 by JeroenT, jibran: Hide entity type selector from...
jibran’s picture

I committed #22 to 8.x-2.x.

JeroenT’s picture

Status: Reviewed & tested by the community » Fixed

Great!

JeroenT’s picture

Status: Fixed » Reviewed & tested by the community

Putting back to RTBC because this patch is not committed to 8.x-1.x.

jibran’s picture

Status: Reviewed & tested by the community » Fixed

Pushed to 8.x-1.x

  • jibran committed 8f44fb5 on 8.x-1.x authored by JeroenT
    Issue #2448401 by JeroenT, jibran: Hide entity type selector from...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.