Active
Project:
Drupal core
Version:
main
Component:
entity system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
9 May 2021 at 07:35 UTC
Updated:
16 Aug 2023 at 15:14 UTC
Jump to comment: Most recent
There are several attempts to provide the same views integration to base fields then the one we can get by using the Field UI.
Most promising seems to be #2337515: Allow @FieldType to customize views data
Until this nice to have feature will be in, we could create a documentation on this topic.
I think we need it because I could not find any step by step tutorial on the web and I found a lot of people stuck by this issue.
Most of them turn back and remove the base fields and replace them by config fields. (which sometimes is a poor design)
My idea is to have an example for most used base fields: datetime, reference_field, integer, ...
Comments
Comment #2
duneblLet first start with an exemple for a datetime field used in a BankOperation entity which should store bank operation data
=>I need help to extends properly
EntityViewsData1-The base field is created as follow in the
modules/custom/bank_operation/src/Entity/BankOperation.phpNotes:
a- The
views_datakey is pointing to a class which will be created in step 2b- The operation_date base field have the
datetimetype2- To integrate with Views we must extends and use our own EntityViewsData class (mandatory until #2337515: Allow @FieldType to customize views data is landed)
Extract from
modules/custom/bank_operation/src/BankOperationViewsData.php:Note:
This class is created according to the value of the
views_datakey used in the entity annotation.Comment #4
fvictoire commentedI am not sure it answers to all your question but you can find documentation with the hook_views_data (in api.drupal.org). The getViewsData method of class EntityViewsData returns the same format data like this hook.
Comment #7
ptmkenny commentedTo update the example in #2 point 2, the code should be this:
Based on this comment