diff --git a/content_entity_example/src/Entity/Contact.php b/content_entity_example/src/Entity/Contact.php index 29dd279..5b5cbdb 100644 --- a/content_entity_example/src/Entity/Contact.php +++ b/content_entity_example/src/Entity/Contact.php @@ -41,6 +41,9 @@ use Drupal\Core\Entity\EntityChangedTrait; * If there is a view available for this entity from the views module, it * overrides the list builder. @todo: any view? naming convention? * + * - views_data: We derive a views data class from EntityViewsData to make + * our entity visible to the views module. + * * - form: We derive our own forms to add functionality like additional fields, * redirects etc. These forms are called when the routing list an * '_entity_form' default for the entityType. Depending on the suffix @@ -79,6 +82,7 @@ use Drupal\Core\Entity\EntityChangedTrait; * handlers = { * "view_builder" = "Drupal\Core\Entity\EntityViewBuilder", * "list_builder" = "Drupal\content_entity_example\Entity\Controller\ContactListBuilder", + * "views_data" = "Drupal\content_entity_example\Entity\ContactViewsData", * "form" = { * "add" = "Drupal\content_entity_example\Form\ContactForm", * "edit" = "Drupal\content_entity_example\Form\ContactForm", diff --git a/content_entity_example/src/Entity/ContactViewsData.php b/content_entity_example/src/Entity/ContactViewsData.php new file mode 100644 index 0000000..e57e86e --- /dev/null +++ b/content_entity_example/src/Entity/ContactViewsData.php @@ -0,0 +1,40 @@ +t('Content Entity Example Contact'); + + // Make the Name field appear to Views as Last Name + $data['contact']['name']['title'] = $this->t('Last Name'); + + return $data; + } + +} \ No newline at end of file