Crashes when Flags are used as relationships in views

Created on 2 October 2020, about 4 years ago
Updated 19 October 2024, 2 months ago

Problem/Motivation

When using Flags as a relationship in views the following two errors pops up:

Warning: array_flip(): Can only flip STRING and INTEGER values! in Drupal\Core\Entity\EntityStorageBase->loadMultiple() (line 266 of /var/www/drupal8/core/lib/Drupal/Core/Entity/EntityStorageBase.php).

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'field list': SELECT node_field_data.created AS node_field_data_created, node_field_data.nid AS nid, id AS id FROM {node_field_data} node_field_data WHERE node_field_data.status = :db_condition_placeholder_0 ORDER BY node_field_data_created DESC LIMIT 11 OFFSET 0; Array ( [:db_condition_placeholder_0] => 1 )

Steps to reproduce

Create a content View and add a Relationships to Flags

Proposed resolution

Please see the patch below

There are two problems:

  1. In the FlagService.php the getFlagById need to catch the situation when a NULL $flag_id is used. The called load function has an assertion for being called with NULL. So this must be catched.
      /**
       * {@inheritdoc}
       */
      public function getFlagById($flag_id) {
        return  $this->entityTypeManager->getStorage('flag')->load($flag_id);
      }
    
  2. To my findings, in the FlagViewsRelationship.php a call to the parent is missing even when a NULL flag is detected.
      /**
       * {@inheritdoc}
       */
      public function query() {
        if (!($flag = $this->getFlag())) {
          return;
        }
    ...
    
    1. The provided patch fixes these two errors.

      Remaining tasks

      None

      User interface changes

      None

      API changes

      None

      Data model changes

      None

πŸ› Bug report
Status

Postponed: needs info

Component

Flag core

Created by

πŸ‡ΈπŸ‡ͺSweden sl27257 Stockholm

Live updates comments and jobs are added and updated live.
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