Problem/Motivation

There are namespace conflicts with the different entity relationship getter plugins:

  • There is no iterating when adding multiple similar entities to a form (eg multiple entities use the same namespace (entity_name and not entity_name_0, entity_name_1, etc))
  • When rendering the form fields for attached entities, the namespace for current user doesn't have ':'s but for reference entities the namespace is referenced_entity:entity:... confusing certain explode statements.
  • Etc
CommentFileSizeAuthor
#2 fix_namespace_issues-2849458-2.patch2.48 KByanniboi

Comments

yanniboi created an issue. See original summary.

yanniboi’s picture

StatusFileSize
new2.48 KB
yanniboi’s picture

+++ b/src/FlexiformEntityFormDisplay.php
@@ -244,6 +246,28 @@ class FlexiformEntityFormDisplay extends EntityFormDisplay implements FlexiformE
+      $parts = explode(':', $entity['plugin']);
+      if ($parts[0] == 'referenced_entity') {
+        $entity_type = $parts[2];
+        $referenced_definitions = \Drupal::entityManager()->getFieldDefinitions('profile', $parts[4]);
+        foreach ($referenced_definitions as $field_name => $definition) {
+          $definitions[$namespace . ':' . $field_name] = $definition;
+        }
+      }
+    }
+    $this->fieldDefinitions = $definitions;

this is currently hardcoded for the profile entity because the reference entity deriver (FormEntityTypedDataReferencedEntityDeriver) does not add the referenced entity type to the namespace (eg a profile on the user entity it specifies the user entity but not the profile entity) so there is no way of knowing which entity type to get the field definitions from unless we load the field properties from the field name and check the target entity.

yanniboi’s picture

Status: Active » Needs work
+++ b/src/FlexiformEntityFormDisplay.php
@@ -68,7 +68,9 @@ class FlexiformEntityFormDisplay extends EntityFormDisplay implements FlexiformE
-          list($namespace, $field_name) = explode(':', $name, 2);
+          $parts = explode(':', $name);
+          $field_name = array_pop($parts);
+          $namespace = implode(':', $parts);

This worked for current user where the namespace doesn't have ':'s but not for reference entities where the namespace has several ':' prior to seperating the field_name

rlmumford’s picture

Status: Needs work » Closed (works as designed)

I don't think we need this patch, because namespace and plugin_id are two different things.

yanniboi’s picture

Status: Closed (works as designed) » Needs work

Module does not work as designed. Need to fix plugin id being used instead of namespace in form display config.

rlmumford’s picture

Status: Needs work » Closed (outdated)