Problem/Motivation
The EntityAggregator currently offers various entities that actually aren't supported.
Examples: After creating a sensor for Block entities, the message shows:
Drupal\Core\Entity\Query\QueryException: Aggregation over configuration entities is not supported
And when you try to edit it: LogicException: Getting the base fields is not supported for entity type Block. in Drupal\Core\Entity\EntityManager->buildBaseFieldDefinitions() (line 412 of core/lib/Drupal/Core/Entity/EntityManager.php).
Fixing the second error can be fixed by removing this code from the entityAggregator:
$entity_type = $this->entityManager->getDefinition($this->getEntityTypeId());
$form['verbose_fields']['available_fields'] = [
'#markup' => t('Available Fields for entity %type: <b>%fields</b>', [
'%type' => $entity_type->getLabel(),
'%fields' => implode(', ', array_keys($this->entityManager->getBaseFieldDefinitions($this->getEntityTypeId())))
]
),
];The getBaseFieldDefinitions method doesn't work with ConfigEntities.
Proposed resolution
Rename sensor to ContentEntityAggregatorSensorPlugin, remove the non-content entities from the dropdown selector.
Remaining tasks
Review issue, discuss, fix, provide patch, review patch and commit it.
User interface changes
None
API changes
None
Data model changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | modify-2534498-23-interdiff.txt | 2.36 KB | berdir |
| #23 | modify-2534498-23.patch | 12.96 KB | berdir |
| #18 | modify-2534498-18.patch | 12.44 KB | LKS90 |
| #18 | interdiff_17-18.txt | 1.41 KB | LKS90 |
| #17 | interdiff_15-17.txt | 1.52 KB | LKS90 |
Comments
Comment #1
berdirActually, I think we should do exactly that. Hide non-content entities, possibly rename the sensor ContentEntityAggregatorSensor.
Comment #2
LKS90 commentedComment #3
LKS90 commentedHere is the patch, I renamed the EntityAggregator to ContentEntityAggregator, so a folowup with a ConfigEntityAggregator should be easy. Maybe add a base EntityAggregator class from which both extend or something like that.
Validation is still missing:
Comment #4
berdir1. Validating this will be very hard. There are per-bundle fields and so on. Instead, make it not fatal if a field doesn't exist. as mentioned before, use hasField() on the entity before accessing it.
2. That's a separate bug, the exists callback is supposed to prevent that.
Comment #5
LKS90 commentedHere is a version without the fatal error. The second bug is new, I distinctly remember it working.
Comment #6
LKS90 commentedComment #7
berdirNot sure about this, might make a bit more sense, but it will also break existing installations completely.
I'd keep the current name for now.
That problem again ;)
Doesn't quite work like that, Content is a translatable string, so you would have to at least put t() around it. And I prefer to loop over entity types and check the entity class against the interface mentioned above. Contrib might add additional groups.
Comment #8
LKS90 commentedJust a quick upload to maybe get some feedback about getting the list of compatible entities.
Comment #9
LKS90 commentedFixed the problem I was having, is_subclass_of can use only string names for classes.
Comment #11
LKS90 commentedFixed test-fails! My entity_type dropdown didn't have keys, fixed that by setting them to the entity_id. Also removed a @todo about adding db aggregator tests.
Comment #12
miro_dietikerNice interdiff (0 bytes) ;-P
Aha, and which one? Placeholder?
WTF?
'ID', 'Label'... right?
I think you want test coverage. ;-)
Ah and the sensors all use 'id' and 'label' (small, ...).
Extracting keys and values again and again... :-S
Then you want to merge the closing bracket lines too and reduce indentation.
And finally, dreaming of nice test coverage...
Comment #13
LKS90 commentedI'll provide the old interdiff as well with this comment :).
The header had the field name, so I though it would be redundant to placeholder the field in there.
Changed it to:
field <em>test_wrong_field</em> is invalid.Fixed the default values for the header.
Simplified the array_keys/values stuff, it was just way more complicated than necessary.
Collapsed the the function closing bracket to the array closing bracket.
Added test coverage for the EntityAggregator.
Comment #15
LKS90 commentedAdded a default case for the conditions so if there are no conditions, an empty array is returned and array_values doesn't cause an exception anymore.
Comment #16
miro_dietikerThe "invalid field" output should be completely dropped like the field is empty. Otherwise it is too much visual noise.
Comment #17
LKS90 commentedRemoved the output when the field is invalid.
Comment #18
LKS90 commentedHere is the change from
FieldableEntityInterfacetoContentEntityInterfacefor the available entity_types. Also added the check for FieldableEntityInterface to the default case so the File entity type (just one example I currently know of) won't break things.Comment #23
berdirDidn't get that last change. The file entity thing is a core bug, I've opened #2539622: File uri field type has default formatter uri_link, throws exception when trying to render.
I've added a try/catch around it and then I'm just displaying that error. We need to do that more often to avoid completely broken pages.
Comment #24
berdirAnd committed!