- Status changed to Needs review
about 1 year ago 11:31am 6 October 2023 - π«π·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()
fromcore/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 namegetEntityTypeId()
seems more suitable. - Status changed to Needs work
about 1 year ago 8:31pm 10 November 2023 - π«π·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? - Status changed to Needs review
about 1 year ago 10:13pm 21 November 2023 - π«π·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? - π«π·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 withrelationship: 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 abase_table: redirect_404
but no annotation to provide a suitablegetViewsData()
function throughviews_data
as said in https://api.drupal.org/api/drupal/core%21modules%21views%21views.api.php..., unlike for the typeredirect
.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
about 1 year ago 1:08pm 24 November 2023 - Status changed to Needs review
about 1 year ago 9:15pm 24 November 2023 - π«π·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
11 months ago 5:18pm 17 January 2024 - π«π·France dqd London | N.Y.C | Paris | Hamburg | Berlin
Will try to ping some Views maintainers in Slack to collect opinions on this.