After #2555027: Support non-numeric entity ID's DER field can refer content entities with string ids but it doesn't allow config entity references at least from ui. There are no tests for this.

Add two pre-configured fields, just like ER in core, one will allow content entities and other will allow config entities so that we can keep the UX part of this issue simple.

Comments

jibran created an issue. See original summary.

chx’s picture

I believe the API allows for this already and it's not entirely clear how UI would work as many config entities do not even have a label! Are we going to restrict to those that have one? Fall back to the id?

jibran’s picture

Issue tags: +ER feature parity
chx’s picture

This is tests only ; we won't add a config entity UI as core doesn't have such either.

jibran’s picture

Just confirmed from @dawehner that we don't need the views integration for this as well.

jhedstrom’s picture

Status: Active » Needs review
StatusFileSize
new2.34 KB

I started in on a test (not sure if its the right approach, but it takes an existing test and then tries to reference a config entity). The test fails for a variety of reasons--one I've fixed in this patch, but the other is failing with an incorrect primitive typed data validation error (since target_id is still apparently an integer, and a config entity id is a string--an issue I thought had been resolved).

Status: Needs review » Needs work

The last submitted patch, 6: 2766187-06.patch, failed testing.

jhedstrom’s picture

Ah, I'd been working on the wrong branch!

jhedstrom’s picture

Status: Needs work » Needs review
StatusFileSize
new111.36 KB

This applies, and it passes too. Do we need further tests?

Status: Needs review » Needs work

The last submitted patch, 9: 2766187-09.patch, failed testing.

jhedstrom’s picture

Status: Needs work » Needs review

This time...

jhedstrom’s picture

StatusFileSize
new2.4 KB

Status: Needs review » Needs work

The last submitted patch, 12: 2766187-11.patch, failed testing.

jibran’s picture

Thank you for working on this.
We need following test cases and please create a new test file.

  1. Config entity only configurable DER field.
  2. Content entity and config entity configurable DER field.
  3. Config entity only basefield DER field.
  4. Config entity only revisonable basefield DER field.
  5. Content entity and config entity basefield DER field.
  6. Content entity and config entity revisonable basefield DER field.

For last four you can update dynamic_entity_reference_entity_test_entity_base_field_info with states.

As per #4 we don't want to expose it in field config settings form for configurable fields so just add some asserts to existing UI test to make sure it is not happening.

We also need some UI tests for autocomplete and autocreate just like \Drupal\Tests\dynamic_entity_reference\Functional\DynamicEntityReferenceTest

We also have to update \Drupal\dynamic_entity_reference\Plugin\Field\FieldType\DynamicEntityReferenceItem::defaultFieldSettings.

jhedstrom’s picture

Status: Needs work » Needs review
StatusFileSize
new14.63 KB
new13.91 KB

This adds the 6 test cases noted in #14 to a new test class.

I have not yet updated the UI tests, so that still needs to be done. Posting here for now, I may be able to get back to this later today.

Status: Needs review » Needs work

The last submitted patch, 15: 2766187-15.patch, failed testing.

jhedstrom’s picture

Status: Needs work » Needs review
StatusFileSize
new929 bytes
new14.53 KB

This should fix the fails, as mentioned in #14 the default settings method needs updating.

jhedstrom’s picture

StatusFileSize
new3.41 KB
new16.98 KB

This adds the UI test.

jibran’s picture

Thank you, this's some great work.
Sorry, I missed two test cases:

  1. string id content entity and config entity.
  2. string id content entity, int id content entity and config entity.

Only remaining things are

We also need some UI tests for autocomplete and autocreate just like \Drupal\Tests\dynamic_entity_reference\Functional\DynamicEntityReferenceTest

These should be specfic to config entity reference.

We also have to update \Drupal\dynamic_entity_reference\Plugin\Field\FieldType\DynamicEntityReferenceItem::defaultFieldSettings.

This is still pending.

  1. +++ b/src/Plugin/Field/FieldType/DynamicEntityReferenceItem.php
    @@ -510,13 +515,21 @@ class DynamicEntityReferenceItem extends EntityReferenceItem {
    +  public static function getTargetTypes($settings, $include_configuration_entities = TRUE) {
    

    I think the second param should be FALSE by default but if making it TRUE makes the changes minimum then it's alright.

  2. +++ b/tests/src/Kernel/DynamicEntityReferenceConfigEntityTest.php
    @@ -0,0 +1,345 @@
    +      'settings' => [],
    

    We should add some settings here.

  3. +++ b/tests/src/Kernel/DynamicEntityReferenceConfigEntityTest.php
    @@ -0,0 +1,345 @@
    +  public function testBaseField() {
    ...
    +  public function testRevisionableBaseField() {
    ...
    +  public function testMixedBaseField() {
    ...
    +  public function testMixedRevisionableBaseField() {
    

    Let's move basefield tests to separate file.

jhedstrom’s picture

StatusFileSize
new26.49 KB
new22.96 KB

This should address nearly everything from #20. I'm now working on the additional UI tests mentioned.

This is still pending.

That was actually added in #17.

jhedstrom’s picture

StatusFileSize
new5.39 KB
new28.09 KB

This test is failing for config entity auto create, because core assumes any auto-created entity has a bundle. From DefaultSelection::createNewEntity():

    $entity_type = $this->entityManager->getDefinition($entity_type_id);
    $bundle_key = $entity_type->getKey('bundle');

$bundle_key comes back as empty, leading to the test failure error (Exception: Error: Cannot access empty property). Should this be pushed to a follow-up issue since it might require fixing core?

Status: Needs review » Needs work

The last submitted patch, 21: 2766187-21.patch, failed testing.

jibran’s picture

Let's add a core bug if there is not one yet. #2405467: Add EntityType and Bundle constraint on entity property of DynamicEntityReferenceItem is in and I think we might have to adapt here.

jibran’s picture

That was actually added in #17.

Sorry, it was a one line thing so I missed it in the patch. :)
Thank you for the awsome work. This needs a reroll after #2405467: Add EntityType and Bundle constraint on entity property of DynamicEntityReferenceItem.

jhedstrom’s picture

I added #2822647: DefaultSelection::createNewEntity() assumes entity type has a bundle key. However, now the issue is that config entities do not auto-generate an ID, so that method probably needs further updating...

jhedstrom’s picture

Stepping back for a minute, I'd say we should split auto-create of config entities off into a separate issue--I'm not aware of any config entities that could consist only of a label, and provide value...

jhedstrom’s picture

Status: Needs work » Needs review
StatusFileSize
new28.11 KB

This is a reroll, still containing the failing config auto-create test.

Status: Needs review » Needs work

The last submitted patch, 27: 2766187-27.patch, failed testing.

jibran’s picture

+1 to #26. Let's get this in.

jhedstrom’s picture

I added #2823371: Add support for auto-create config entities as a follow-up. We probably still need the autocomplete test though.

jhedstrom’s picture

Status: Needs work » Needs review
StatusFileSize
new7.25 KB
new27.15 KB

This removes the auto-create test, and adds an autocomplete test for config entities. Anything left to do here?

jibran’s picture

I think we are almost ready. Just wait for #2729463: List of view_modes is empty in dynamic_entity_reference_entity_view formatter then we can commit this. #2458353: DER fields should add selection handler config dependencies will become a bug after this so should we move it here? Just few minor observations and thanks for the new patch and tests.

  1. +++ b/dynamic_entity_reference.views.inc
    @@ -159,7 +159,7 @@ function dynamic_entity_reference_views_data() {
    -      $targets = array_intersect(DynamicEntityReferenceItem::getTargetTypes($field->getSettings()), array_keys($sql_entity_types));
    +      $targets = array_intersect(DynamicEntityReferenceItem::getTargetTypes($field->getSettings(), TRUE), array_keys($sql_entity_types));
    

    Do we need this? I don't think so. views data for config entities, it doesn't make sense unless I'm missing something?

  2. +++ b/src/Plugin/Field/FieldType/DynamicEntityReferenceItem.php
    @@ -56,6 +56,10 @@ class DynamicEntityReferenceItem extends EntityReferenceItem {
         $labels = \Drupal::service('entity_type.repository')->getEntityTypeLabels(TRUE);
         $options = $labels[(string) t('Content', [], ['context' => 'Entity type group'])];
    ...
    +    // Add configuration entities.
    +    $options += $labels[(string) t('Configuration', [], ['context' => 'Entity type group'])];
    

    We can just use labels as is without passing TRUE to getEntityTypeLabels().

jhedstrom’s picture

StatusFileSize
new1.87 KB
new26.25 KB

Good call on those changes in #32. For the views one, config entities were already being excluded because of the sql storage check, so removing that makes the code clearer.

I will look into rolling the test from #2458353: DER fields should add selection handler config dependencies into this patch.

jhedstrom’s picture

StatusFileSize
new4.89 KB
new31.14 KB

This rolls in the test from #2458353: DER fields should add selection handler config dependencies, and finishes the @todo in that patch.

jibran’s picture

jhedstrom’s picture

StatusFileSize
new31.14 KB

Rebased off of latest 2.x.

  • jibran committed 27e42fe on 8.x-2.x authored by jhedstrom
    Issue #2766187 by jhedstrom, jibran: Allow config entity references
    
jibran’s picture

Status: Needs review » Fixed

Thanks! committed to 8.x-2.x

  • jibran committed 8f65c0a on 8.x-2.x
    Issue #2766187 by jibran: PHPCS fix: Allow config entity references
    

Status: Fixed » Closed (fixed)

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