- Issue created by @just_like_good_vibes
- 🇫🇷France just_like_good_vibes PARIS
More investigations : the buggy entity ( that is supposed to be a random entity but it's not) is already there in layout builder.
We got it fromLayoutBuilderContextEntityResolver::guessLayoutBuilderEntity
. - 🇫🇷France just_like_good_vibes PARIS
The problem is in this code from the SampleEntityGenerator.
$entity = $tempstore->get("$entity_type_id.$bundle_id")
the entity in there is not the supposed random entity.
- 🇫🇷France just_like_good_vibes PARIS
Ok, now i think i have it .
We have a serious bug inside our code, because we were supposing sample entities to be really sample, without an id.
and this is false in the case of some entity reference fields, because of that code in\Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::generateSampleValue
// Select a random number of references between the last 50 referenceable // entities created. if ($referenceable = $selection_handler->getReferenceableEntities(NULL, 'CONTAINS', 50)) { $group = array_rand($referenceable); $values['target_id'] = array_rand($referenceable[$group]); return $values; }
- 🇫🇷France just_like_good_vibes PARIS
@christian, as we discussed today, here is a better implementation of sample entity generator,
getting rid of peace of real contents in entity reference fields.
Please note :
- i carefully cleaned in the case of layout builder generated entity or when we generate an entity with our generator
- we clean recursively, because yes it's required... that's why we only traverse some fields, and the configurable ones to be more precise. When i let the base fields, the traversal goes crazy everywhere... especially the author fields, picture..etc and in cascade.
- it fixes the bug i managed to reproduce in the lab today :) - 🇫🇷France just_like_good_vibes PARIS
the fix here is correcting the reproduction of the bug i made in lab, but after some testing, it does not solve yet my real world initial problem.
those “bad”
sample values are quite a big problem compared the assumptions we made. maybe we are not taking the problem in the right sense. the real problem here, is that sometimes, some sample entities do not have values in referenced entities, because those samples are not real samples, they are real entities borrowed. to cover our needs here and fill the gap, we only need random entities where they are missing. if we could identify, through a conext or whatever, that the current entity in the context is a sample, then we could fill that gap more easily than trying to patch every sample entity.