Custom non fieldable entities stop working properly with views

Created on 17 June 2020, over 4 years ago
Updated 20 July 2023, over 1 year ago

Hello,

I'm getting an error message when perfoming update.php on version 8.9.0. The views_post_update_field_names_for_multivalue_fields call fails, because my Entity does not implement Drupal\core\Entity\FieldableEntityInterface... (see screenshot).

It's not mandatory that an entity provides fields. I believe I have seen even a tag boolean fieldable tag that can be set in the @EntityType section. Anyway, in my case I only use values each matching to fields in the database.

As example, the code for one my entities looks like below:

/**
 * @EntityType(
 *   id = "dimension",
 *   label = @Translation("Dimension"),
 *   handlers = {
 *     "storage" = "Drupal\custom_base\Entity\Storage\DimensionStorage",
 *     "views_data" = "Drupal\custom_base\Entity\Views\DimensionViewsData",
 *     "form" = {
 *       "default" = "Drupal\custom_base\Form\DimensionForm",
 *       "delete" = "Drupal\custom_base\Form\EntityDeleteForm",
 *     },
 *   },
 *   entity_keys = {
 *     "id" = "id",
 *     "uuid" = "uuid",
 *     "label" = "title"
 *   }, 
 * )
 */
class DimensionEntity extends EntityBase
{
   ...
{

Maybe should ViewConfigUpdater::getMultivalueBaseFieldUpdateTableInfo method be working slightly differently :

 /**
   * Returns the multivalue base fields update table info.
   *
   * @return array
   *   An array of multivalue base field info.
   */
protected function getMultivalueBaseFieldUpdateTableInfo() {
    $table_info = &$this->multivalueBaseFieldsUpdateTableInfo;

    if (!isset($table_info)) {
        $table_info = [];

        foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
-          if ($entity_type->hasHandlerClass('views_data')) {
+          if ($entity_type->hasHandlerClass('views_data') && $entity_type->entityClassImplements(FieldableEntityInterface::class)) {
           $base_field_definitions = $this->entityFieldManager->getBaseFieldDefinitions($entity_type_id);

         ...

πŸ› Bug report
Status

Active

Version

9.5

Component
ViewsΒ  β†’

Last updated 1 day ago

Created by

πŸ‡«πŸ‡·France mathiasmg

Live updates comments and jobs are added and updated live.
  • Novice

    It would make a good project for someone who is new to the Drupal contribution process. It's preferred over Newbie.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024