Problem/Motivation
Views using the entity:user row plugin (e.g. moderation_dashboard, user profile views) randomly throw:
Warning: Undefined array key "entity_type" in Drupal\views\Plugin\views\row\EntityRow->init() (line 110)
Followed by:
PluginNotFoundException: The "" entity type does not exist.
The error occurs only when a user is logged in and has permission to access views that use the entity:user row plugin. It appears random because it depends on plugin discovery order.
Steps to reproduce
- Install Drupal 11.3.3 with the User module enabled.
- Create or use a View that displays users with row type "User view mode" (entity:user).
- Example: the moderation_dashboard view, or a custom view with base table users and row plugin entity:user.
- Log in as a user with permission to access that view (e.g. "use moderation dashboard").
- Navigate to a page that triggers the view (e.g. toolbar rendering, user profile).
- The error may appear intermittently depending on plugin discovery/cache state.
Verification: Run this when the error occurs:
drush php:eval "
\$def = \Drupal::service('plugin.manager.views.row')->getDefinition('entity:user', FALSE);
echo 'entity_type present: ' . (isset(\$def['entity_type']) ? 'yes' : 'NO') . PHP_EOL;
print_r(\$def);
"Output will show entity_type present: NO and the definition will reference Drupal\user\Plugin\views\row\UserRow with no entity_type key.
Proposed resolution
Derive entity_type from the plugin ID when it is missing from the definition. For derivative plugin IDs like entity:user, the entity type is the part after the colon.
File: core/modules/views/src/Plugin/views/row/EntityRow.php
Change: In init(), add a fallback when entity_type is not in the definition:
// Derive entity_type from definition or plugin_id (e.g. entity:user -> user).
$this->entityTypeId = $this->definition['entity_type']
?? (str_contains($this->pluginId ?? '', ':') ? explode(':', $this->pluginId, 2)[1] : NULL);
if (empty($this->entityTypeId)) {
throw new \InvalidArgumentException(sprintf(
'The row plugin %s requires an entity type. Set entity_type in the plugin definition or use a derivative plugin ID (e.g. entity:user).',
$this->pluginId ?? 'unknown'
));
}
This is backward-compatible: when entity_type is present (core derivative), it is used; when missing (UserRow), it is derived from the plugin ID.
Alternative Considered
Adding entity_type to the UserRow plugin definition would fix this for UserRow only. The proposed fix in EntityRow is more robust: it covers any attribute-based or custom plugin that overrides an entity row derivative without including entity_type.
Additional Notes
Workaround: Only drush cr (full cache rebuild) temporarily resolves the issue; drush cc bin (discovery and config do not, because the problem is the User module's plugin definition, not cache.
Affected modules: Any view using entity:user row (e.g. moderation_dashboard, custom user views).
Related: User module UserRow at core/modules/user/src/Plugin/views/row/UserRow.php line 13: #[ViewsRow("entity:user")].
| Comment | File | Size | Author |
|---|---|---|---|
| entity-row-userrow-entity-type-missing.patch | 1.34 KB | sdjili |
Issue fork drupal-3577163
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
cilefen commentedComment #3
quietone commentedHi, Issues for Drupal core should be targeted to the 'main' branch, our primary development branch. Changes are made on the main branch first, and are then back ported as needed according to the Core change policies. The version the problem was discovered on should be stated in the issue summary Problem/Motivation section. Thanks.
Comment #6
sivaji_ganesh_jojodae commentedI've ported the patch in the issue description to MR.