Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 294233

Removing a relationship that is used by a filter can prevent access to editing a view

$
0
0

Problem/Motivation

While playing with a view, i may have clicked multiple times on the remove button for a "representative node" fields. The view modification page was not working anymore and i reloaded the page.

At reload, the page showed multiple error, and i can not edit the view anymore.

First warning:
Warning : Undefined array key "tid_representative" dans Drupal\views\Plugin\views\HandlerBase->getEntityType() (ligne 709 de web/core/modules/views/src/Plugin/views/HandlerBase.php).

Second warning:
Warning : Trying to access array offset on value of type null dans Drupal\views\Plugin\views\HandlerBase->getEntityType() (ligne 710 de /app/web/core/modules/views/src/Plugin/views/HandlerBase.php).

Error:
InvalidArgumentException: A valid cache entry key is required. Use getAll() to get all table data. in Drupal\views\ViewsData->get() (line 140 of core/modules/views/src/ViewsData.php).

Steps to reproduce

1. In a view, add a "Taxonomy term: Representative node" relationship (like described by View Taxonomy Term and hide empty terms.
2. In the same view, add filters on the representative node content.
3. Remove the representative node relationship without removing the filters.

Proposed resolution

In HandlerBase.php, rewrite the getEntityType() method like this:

  /**
   * {@inheritdoc}
   */
  public function getEntityType() {
    // If the user has configured a relationship on the handler take that into
    // account.
    $relationship_key = $this->options['relationship'] ?? '';
    if ($relationship = $this->displayHandler->getOption('relationships')[$relationship_key] ?? NULL) {
      $table_data = $this->getViewsData()->get($relationship['table']);
      $views_data = $this->getViewsData()->get($table_data[$relationship['field']]['relationship']['base']);
    }

    if (isset($views_data['table']['entity type'])) {
      return $views_data['table']['entity type'];
    }
    else {
      throw new \Exception("No entity type for field {$this->options['id']} on view {$this->view->storage->id()}");
    }
  }

Remaining tasks

Make a better rewrite of getEntityType(), to have only one $views_data failsafe instead of the two introduce by the given solution.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

Fix error when editing view with filters from a missing representative node relationship.


Viewing all articles
Browse latest Browse all 294233


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>