1. We are overriding propertyDefinitions(), schema(), getValue() and setValue of EntityReferenceItem in DynamicEntityReferenceItem core has made some changes in these function we have to update these accordingly.
  2. Perhaps we can also override EntityReferenceItem::generateSampleValue()
  3. Perhaps we can remove/update DynamicEntityReferenceItem::onChange() in favour of EntityReferenceItem::onChange
  4. We can add generateSampleItems() as well.

Comments

jibran’s picture

Issue summary: View changes
jibran’s picture

jibran’s picture

Status: Needs review » Needs work

The last submitted patch, 3: 2365331-update-dynamicEntityReferenceItem-3.patch, failed testing.

larowlan’s picture

Looking good - do you want help with the fails?

jibran’s picture

jibran’s picture

Category: Task » Bug report
Priority: Normal » Critical
Status: Needs work » Needs review
StatusFileSize
new2.66 KB
new10.26 KB

#2137309: Typed data does not handle set() and onChange() consistently is in and it has broken HEAD and I have no idea how to fix this. Here is some more work. DynamicEntityReference is now exactly same as EntityReference :/

Status: Needs review » Needs work

The last submitted patch, 9: 2365331-update-dynamicEntityReferenceItem-9.patch, failed testing.

larowlan’s picture

Category: Bug report » Task
Priority: Critical » Normal
Status: Needs work » Needs review
StatusFileSize
new1.96 KB
new10.38 KB
+++ b/src/Plugin/Field/FieldType/DynamicEntityReferenceItem.php
@@ -68,10 +70,14 @@ class DynamicEntityReferenceItem extends ConfigurableEntityReferenceItem {
-    $properties['target_id'] = DataDefinition::create('string')
-      ->setLabel(t('Entity ID'));
+    $properties['target_id'] = DataDefinition::create('integer')
+        ->setLabel(t('Entity ID'))
+        ->setSetting('unsigned', TRUE)
+        ->setRequired(TRUE);

This change seems to be part of the problem, it breaks auto-creation of tags. I don't see a corresponding change in ER field - what was the reasoning?

Can't afford to spend anymore time on this today - damn typed data.

Status: Needs review » Needs work

The last submitted patch, 11: update-2365331-11.patch, failed testing.

larowlan’s picture

StatusFileSize
new68.55 KB

The issue is that the constraint gets out-of-whack - its trying to validate a different entity-type (not a user).
I wonder if our 'fake it' stuff is the issue here - overriding the entity-type somewhere too low, or somewhere we're missing where we need to force it - in the validation API.

jibran’s picture

+++ b/src/Plugin/Field/FieldType/DynamicEntityReferenceItem.php
@@ -70,10 +70,8 @@ class DynamicEntityReferenceItem extends ConfigurableEntityReferenceItem {
-    $properties['target_id'] = DataDefinition::create('integer')
-        ->setLabel(t('Entity ID'))
-        ->setSetting('unsigned', TRUE)
-        ->setRequired(TRUE);

This change is due to #2232477: Fatal when adding new fields with NOT NULL constraints in a base table that contains existing entities. We are only using content entities unlike ER so our taget_id will always be integer. If and when we plan to support config entities then we can update it to support strings.

I have seen the error in #13 and thanks for the idea I'll try to investigate more.

larowlan’s picture

Happy to keep it as string, but the setRequired(TRUE) is incompatible with auto-create

jibran’s picture

I am doing setRequired(TRUE) because of #2232477: Fatal when adding new fields with NOT NULL constraints in a base table that contains existing entities. Is there a reason why we want to keep it a string? We are only supporting entities which are implementing FieldableEntityInterface so making it integer make sense to me unless you have some other reason.
DER field can only support either content entities or config entities per field. In the future we can add a field storage option to choose between content entities or config entities and then we can update DERI::propertyDefinitions() and DERI::schema() same as ERI::propertyDefinitions() and ERI::schema() to support both content entities and config entities.

jibran’s picture

StatusFileSize
new10.72 KB

I have added individual commits for all the above fixed issues so that we can deal with the problem in hand here is the reroll version of the patch.

larowlan’s picture

No bot?

The last submitted patch, 17: 2365331-update-dynamicEntityReferenceItem-17.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 18: 2365331-update-dynamicEntityReferenceItem-18.patch, failed testing.

jibran’s picture

Status: Needs work » Needs review
StatusFileSize
new2.06 KB
new10.63 KB

Bot is back. This should be green.

Status: Needs review » Needs work

The last submitted patch, 22: 2365331-update-dynamicEntityReferenceItem-20.patch, failed testing.

jibran’s picture

Status: Postponed » Needs review

Status: Needs review » Needs work

The last submitted patch, 22: 2365331-update-dynamicEntityReferenceItem-20.patch, failed testing.

jibran’s picture

Status: Needs work » Needs review
StatusFileSize
new10.31 KB
new17.91 KB

Fixed the fails, updated the patch according to #2232477: Fatal when adding new fields with NOT NULL constraints in a base table that contains existing entities committed version, have done some clean up and added some docs so that we'll get less confuse next time ;-).

jibran’s picture

StatusFileSize
new3.74 KB
new19.08 KB
  1. +++ b/src/Plugin/Field/FieldType/DynamicEntityReferenceItem.php
    @@ -80,30 +87,18 @@ class DynamicEntityReferenceItem extends ConfigurableEntityReferenceItem {
    -      // $properties['entity']->getTargetDefinition()->addConstraint('Bundle', $settings['target_bundle']);
    

    We can add this constraint in setValue(). Do you think it is worth it? If yes we can discuss this in follow up.

larowlan’s picture

+++ b/src/Plugin/Field/FieldType/DynamicEntityReferenceItem.php
@@ -126,12 +121,14 @@ class DynamicEntityReferenceItem extends ConfigurableEntityReferenceItem {
+    $property = $this->get('entity');
+    if ($property_name == 'target_type' && !$property->getValue()) {

@@ -232,13 +264,19 @@ class DynamicEntityReferenceItem extends ConfigurableEntityReferenceItem {
+        $property = $this->get('entity');
+        $entity_id = $property->getTargetIdentifier();
...
+        $targetDefinition = $property->getTargetDefinition();

maybe we should call this $entity_property so it's clear?

Other than that, looks awesome - thanks again

  • jibran committed e5a31f4 on 8.x-1.x
    Issue #2365331 by jibran, larowlan: Update DynamicEntityReferenceItem...
jibran’s picture

Status: Needs review » Fixed
StatusFileSize
new2.6 KB

Fixed on commit. Thanks for the review and support.

jibran’s picture

Status: Fixed » Closed (fixed)

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