entities – How to use “content entity” type in a View?

Add a views_data handler to the entity type. Either the core standard EntityViewsData

content_entity_example/src/Entity/Contact.php

  *   handlers = {
  *     "views_data" = "DrupalviewsEntityViewsData",

or a custom handler:

content_entity_example/src/Entity/Contact.php

  *   handlers = {
  *     "views_data" = "Drupalcontent_entity_exampleEntityContactViewsData",

content_entity_example/src/Entity/ContactViewsData.php

<?php

namespace Drupalcontent_entity_exampleEntity;

use DrupalviewsEntityViewsData;

/**
 * Makes the content_entity_example entity available to Views
 *
 * @ingroup content_entity_example
 */
class ContactViewsData extends EntityViewsData {

  /**
   * {@inheritdoc}
   */
  public function getViewsData() {
    $data = parent::getViewsData();

    // $data from the parent is enough to make it work but modify as required.

    // Give it a more description name in the dropdown when creating a new view.
    $data('contact')('table')('base')('title') = $this->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;
  }

}

To apply this code to the example module use the patch from this issue https://www.drupal.org/project/examples/issues/2725833