Error Exception: No entity type for field path on view redirect_404 in Drupal\views\Plugin\views\HandlerBase->getEntityType() (line 712 of

Created on 22 April 2019, about 5 years ago
Updated 17 January 2024, 5 months ago

I get this error when I modify redirect_404 View using DataTables view format

Exception: No entity type for field path on view redirect_404 in Drupal\views\Plugin\views\HandlerBase->getEntityType() (line 712 of /home/grupog/public_html/core/modules/views/src/Plugin/views/HandlerBase.php).

Drupal Core and Modules Version
Drupal core 8.7.0-rc1
DataTables 8.x-1.0-rc1+3-dev (2018-Sep-12)
Redirect 8.x-1.3+1-dev (2019-Jan-06)

View elements
FORMAT
Format:DataTables | Settings

FIELDS
Redirect 404: Path (Path)
Redirect 404: Count (Count)
Redirect 404: Timestamp (Last accessed)
Redirect 404: Language (Language)
Redirect 404: Operations (Operations)

FILTER CRITERIA
List additional actions
Redirect 404: Path (exposed)
Redirect 404: Language (exposed)
Redirect 404: Resolved (= False)

πŸ› Bug report
Status

Postponed: needs info

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States RobertoGuzman

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.

  • Status changed to Needs review 9 months ago
  • πŸ‡«πŸ‡·France Chris64 France

    Looking at this, the problem seems to be a view problem, and not a DataTables problem: Some thing is wrong in the views. Therefore I propose status Closed (works as designed) or (won't fix).

    Indeed, the error message comes from the function, getEntityType() from core/modules/views/src/Plugin/views/HandlerBase.php. The function exists for the used entity.

    However, the error in interesting. May be some hints to solve this kind of problem have to be given here. The function's code is,

      public function getEntityType() {
        // If the user has configured a relationship on the handler take that into
        // account.
        if (!empty($this->options['relationship']) && $this->options['relationship'] != 'none') {
          $relationship = $this->displayHandler->getOption('relationships')[$this->options['relationship']];
          $table_data = $this->getViewsData()->get($relationship['table']);
          $views_data = $this->getViewsData()->get($table_data[$relationship['field']]['relationship']['base']);
        }
        else {
          $views_data = $this->getViewsData()->get($this->view->storage->get('base_table'));
        }
    
        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()}");
        }
      }

    Then the error is thrown if !isset($views_data['table']['entity type']). In a view a wrong relationship configuration may cause such a problem.

    More comments. The name of the involved function is strange. Since in the Drupal's core,

    core/lib/Drupal/Core/Entity/EntityInterface.php
      /**
       * Gets the entity type definition.
       *
       * @return \Drupal\Core\Entity\EntityTypeInterface
       *   The entity type definition.
       */
      public function getEntityType();
    
      /**
       * Gets the ID of the type of the entity.
       *
       * @return string
       *   The entity type ID.
       */
      public function getEntityTypeId();
    core/modules/field/src/Entity/FieldStorageConfig.php
      /**
       * Loads a field config entity based on the entity type and field name.
       *
       * @param string $entity_type_id
       *   ID of the entity type.
       * @param string $field_name
       *   Name of the field.
       *
       * @return \Drupal\field\FieldStorageConfigInterface|null
       *   The field config entity if one exists for the provided field name,
       *   otherwise NULL.
       */
      public static function loadByName($entity_type_id, $field_name) {

    But in the views part of the core,

    core/modules/views/src/Plugin/views/ViewsHandlerInterface.php
      /**
       * Determines the entity type used by this handler.
       *
       * If this handler uses a relationship, the base class of the relationship is
       * taken into account.
       *
       * @return string
       *   The machine name of the entity type.
       */
      public function getEntityType();

    Therefore, even getEntityType() is the right function a name getEntityTypeId() seems more suitable.

  • Status changed to Needs work 8 months ago
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Back to NW as of #10

  • πŸ‡«πŸ‡·France Chris64 France

    @Anybody, I think getEntityType/getEntityTypeId problem from #10 πŸ› Error Exception: No entity type for field path on view redirect_404 in Drupal\views\Plugin\views\HandlerBase->getEntityType() (line 712 of Needs review should be an other issue. As a task. Don't you? Therefore, open an other issue and close this one?

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    @Chris64: I'm not into this enough. This issue should fix the issue from the summary and in from #5. If there's another, separate bug we should open a separate issue for that, yes.

  • Status changed to Needs review 7 months ago
  • πŸ‡«πŸ‡·France Chris64 France

    @Anybody, I see about the summary and #5 πŸ› Error Exception: No entity type for field path on view redirect_404 in Drupal\views\Plugin\views\HandlerBase->getEntityType() (line 712 of Needs review . As I said in #10 πŸ› Error Exception: No entity type for field path on view redirect_404 in Drupal\views\Plugin\views\HandlerBase->getEntityType() (line 712 of Needs review at the beginning I don't think it is a problem from this module. I think,

    Then the error is thrown if !isset($views_data['table']['entity type']). In a view a wrong relationship configuration may cause such a problem.

    The message is still about some thing wrong. Therefore the problem for me is why $views_data['table']['entity type'] is not set? In view. How it is possible? That is not a Datatables module bug. However the question is interesting, and could need an answer. What should be done with it? Change the issue to a View issue?

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Perhaps #3 helps?

    It only happens if I make fields sortable.

    is this reproducible or do we need details?

  • πŸ‡«πŸ‡·France Chris64 France

    We can try to figure out better what's happened. From #3 πŸ› Error Exception: No entity type for field path on view redirect_404 in Drupal\views\Plugin\views\HandlerBase->getEntityType() (line 712 of Needs review ,

    It only happens if I make fields sortable.

    Yes, since the troublesome function getEntityType() is only reached if the column if sortable,

          if (empty($options['info'][$field]['sortable']) || !$fields[$field]->clickSortable()) {
            $column_options['bSortable'] = FALSE;
          }
          else {
            $info = FieldStorageConfig::loadByName($fields[$field]->getEntityType(), $field);

    #5 πŸ› Error Exception: No entity type for field path on view redirect_404 in Drupal\views\Plugin\views\HandlerBase->getEntityType() (line 712 of Needs review is the closer,

    The problem is that the module assumes sort fields are field objects on an entity which is fine for most cases but breaks on any table exposed to views that is not defined by an entity type.

    Some fields could not provide their type through the getEntityType() function.

    For example, from the summary, the type redirect_404 from module Redirect is set with relationship: none, and since,

        if (!empty($this->options['relationship']) && $this->options['relationship'] != 'none') {
    ...
        else {
          $views_data = $this->getViewsData()->get($this->view->storage->get('base_table'));
        }

    'base_table' information are required. There is a base_table: redirect_404 but no annotation to provide a suitable getViewsData() function through views_data as said in https://api.drupal.org/api/drupal/core%21modules%21views%21views.api.php..., unlike for the type redirect.

    A walkaround is to make not sortable columns with such a field. Knowing some unsupported types should make this easy to reproduce. Moreover, unsupported field types should be collected to know.

  • Status changed to Needs work 7 months ago
  • πŸ‡«πŸ‡·France Chris64 France
  • Status changed to Needs review 7 months ago
  • πŸ‡«πŸ‡·France Chris64 France

    Indeed @Anybody there is a problem. May be the approach need to be changed. Here a proposition based on $fields[$field]->options['type'] instead.

  • Status changed to Postponed: needs info 5 months ago
  • πŸ‡©πŸ‡ͺGermany diqidoq Berlin | Hamburg | New York | London | Paris

    Will try to ping some Views maintainers in Slack to collect opinions on this.

Production build 0.69.0 2024