我将项目升级到 drupal 10,我有一个问题:
当我想在媒体视图中过滤时,更改页面,这在这里不起作用是我的错误:
AssertionError:无法加载 ID 为 NULL 的“entity_browser”实体。在assert()中(/var/www/drupal/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php第261行)。
我真的不知道在哪里进行干预,如果它来自我的函数 load 、模块或自定义主题
here is my function load:
**
* {@inheritdoc}
*/
public function load($id) {
assert(!is_null($id), sprintf('Cannot load the "%s" entity with NULL ID.', $this->entityTypeId));
$entities = $this->loadMultiple([$id]);
return $entities[$id] ?? NULL;
}
我该如何修复这个错误?
我是一名初级开发人员,在这个项目上我尝试制作补丁,但在网上没有发现任何结论。不知道如何介入解决问题
我在同一段代码上遇到问题,不知何故 id 为空并且起源尚不清楚,我仍在尝试修复它。不确定它是否正确,但函数无论如何都会返回 null,那么为什么不返回 null 而不是断言呢?
public function load($id) {
if(is_null($id)){
return null;
}
assert(!is_null($id), sprintf('Cannot load the "%s" entity with NULL ID.', $this->entityTypeId));
$entities = $this->loadMultiple([$id]);
return $entities[$id] ?? NULL;
}
这是一个补丁:
diff --git lib/Drupal/Core/Entity/EntityStorageBase.php lib/Drupal/Core/Entity/EntityStorageBase.php
index 0182b75cf8..809d283c5a 100644
--- lib/Drupal/Core/Entity/EntityStorageBase.php
+++ lib/Drupal/Core/Entity/EntityStorageBase.php
@@ -292,6 +292,9 @@ abstract class EntityStorageBase extends EntityHandlerBase implements EntityStor
* {@inheritdoc}
*/
public function load($id) {
+ if(is_null($id)){
+ return null;
+ }
assert(!is_null($id), sprintf('Cannot load the "%s" entity with NULL ID.', $this->entityTypeId));
$entities = $this->loadMultiple([$id]);
return $entities[$id] ?? NULL;