在我的Drupal项目中,我有这个错误:
可恢复的致命错误:参数1传递给 Drupal \ Core \ Entity \ EntityViewBuilder :: view()必须实现接口 Drupal \ Core \ Entity \ EntityInterface,null给定,调用 /Users/team1/workspace/ga_p/modules/field_collection/src/Plugin/Field/FieldFormatter/FieldCollectionItemsFormatter.php 在第33行并在Drupal \ Core \ Entity \ EntityViewBuilder-> view()中定义 (core / lib / Drupal / Core / Entity / EntityViewBuilder.php的第110行)。我做 不知道是否是创建了多个字段 (fieldCollections)
但我不知道如何删除此错误。
Drupal版本:8.3.4
答案 0 :(得分:2)
试试这个补丁
diff --git a/src/Plugin/Field/FieldType/FieldCollection.php b/src/Plugin/Field/FieldType/FieldCollection.php
index 8721220..c5335be 100644
--- a/src/Plugin/Field/FieldType/FieldCollection.php
+++ b/src/Plugin/Field/FieldType/FieldCollection.php
@@ -183,19 +183,15 @@ class FieldCollection extends EntityReferenceItem {
public function preSave() {
if ($field_collection_item = $this->getFieldCollectionItem()) {
- // TODO: Handle node cloning
- /*
- if (!empty($host_entity->is_new) && empty($entity->is_new)) {
+ $host = $this->getEntity();
+
+ // Handle node cloning
+ if($host->isNew() && !$field_collection_item->isNew()) {
// If the host entity is new but we have a field_collection that is not
// new, it means that its host is being cloned. Thus we need to clone
// the field collection entity as well.
- $new_entity = clone $entity;
- $new_entity->target_id = NULL;
- $new_entity->revision_id = NULL;
- $new_entity->is_new = TRUE;
- $entity = $new_entity;
+ $field_collection_item = $field_collection_item->createDuplicate();
}
- */
// TODO: Handle deleted items
/*
@@ -231,11 +227,10 @@ class FieldCollection extends EntityReferenceItem {
}
*/
- $this->newHostRevision = $this->getEntity()->isNewRevision();
+ $this->newHostRevision = $host->isNewRevision();
// If the host entity is saved as new revision, do the same for the item.
if ($this->newHostRevision) {
- $host = $this->getEntity();
$field_collection_item->setNewRevision();
diff --git a/src/Plugin/Field/FieldWidget/FieldCollectionEmbedWidget.php b/src/Plugin/Field/FieldWidget/FieldCollectionEmbedWidget.php
index 4d6ae09..800383f 100644
--- a/src/Plugin/Field/FieldWidget/FieldCollectionEmbedWidget.php
+++ b/src/Plugin/Field/FieldWidget/FieldCollectionEmbedWidget.php
@@ -104,9 +104,8 @@ class FieldCollectionEmbedWidget extends WidgetBase {
protected function formMultipleElements(FieldItemListInterface $items, array &$form, FormStateInterface $form_state) {
// We don't want to render empty items on field collection fields
// unless a) the field collection is empty ; b) the form is rebuilding,
- // which means that the user clicked on "Add another item"; or
- // c) we are creating a new entity.
- if ((count($items) > 0) && !$form_state->isRebuilding() && !$items->getEntity()->isNew()) {
+ // which means that the user clicked on "Add another item"
+ if ((count($items) > 0) && !$form_state->isRebuilding()) {
$field_name = $this->fieldDefinition->getName();
$cardinality = $this->fieldDefinition->getFieldStorageDefinition()->getCardinality();
$parents = $form['#parents'];
提到here。
答案 1 :(得分:0)
我执行
patch -p1<箱/斑块/ fieldCollection.patch
输出:
无法在输入第5行找到要修补的文件
也许您使用了错误的-p
或--strip选项?导致这一点的文本是:
-------------------------- | diff --git a / src / Plugin / Field / FieldType / FieldCollection.php
b / src / Plugin / Field / FieldType / FieldCollection.php | index
8721220..c5335be 100644 | --- a / src / Plugin / Field / FieldType / FieldCollection.php | +++
B / SRC /插件/字段/的FieldType / FieldCollection.php
--------------------------文件补丁:
在这一点上,我在计算机上找到" FieldCollection.php"文件并放入绝对路径
/Users/team1/workspace/ga_p/modules/field_collection/src/Plugin/Field/FieldType/FieldCollection.php
修补文件 /Users/team1/workspace/ga_p/modules/field_collection/src/Plugin/Field/FieldType/FieldCollection.php
Hunk#1在188处失败.Hunk#2在159处成功(偏移-68线)。 1
out of 2 hunks FAILED - 将拒绝保存到文件
/Users/team1/workspace/ga_p/modules/field_collection/src/Plugin/Field/FieldType/FieldCollection.php.rej
无法在输入第47行找到要修补的文件。也许您使用了错误的
-p或--strip选项?导致这一点的文本是:
-------------------------- | diff --git a / src / Plugin / Field / FieldWidget / FieldCollectionEmbedWidget.php
b / src / Plugin / Field / FieldWidget / FieldCollectionEmbedWidget.php | index
4d6ae09..800383f 100644 | ---
a / src / Plugin / Field / FieldWidget / FieldCollectionEmbedWidget.php | +++
B / SRC /插件/字段/ FieldWidget / FieldCollectionEmbedWidget.php
要修补的文件: /Users/team1/workspace/ga_p/modules/field_collection/src/Plugin/Field/FieldWidget/FieldCollectionEmbedWidget.php
在这一点上,我在我的计算机上找到了#34; FieldCollectionEmbedWidget.php"文件并放入绝对路径
/Users/team1/workspace/ga_p/modules/field_collection/src/Plugin/Field/FieldWidget/FieldCollectionEmbedWidget.php
修补文件
/Users/team1/workspace/ga_p/modules/field_collection/src/Plugin/Field/FieldWidget/FieldCollectionEmbedWidget.php
Hunk#1在111处成功(偏移7行)。
但问题仍然存在
答案 2 :(得分:0)
我试图通过GIT运行补丁
team1@MacBook-Pro-de-Javi:[~/workspace/ga_p/modules/field_collection]: (master): git apply -v /Users/team1/workspace/ga_p/bin/patchs/fieldCollection.patch
Skipped patch&#s; src / Plugin / Field / FieldType / FieldCollection.php'。
Skipped patch' src / Plugin / Field / FieldWidget / FieldCollectionEmbedWidget.php'。
由于它不起作用我尝试了这样:
team1@MacBook-Pro-de-Javi:[~/workspace/ga_p/modules/field_collection]: (master): patch -p1 < /Users/team1/workspace/ga_p/bin/patchs/fieldCollection.patch
修补文件src / Plugin / Field / FieldType / FieldCollection.php
Hunk#1在188处失败。
Hunk#2在227失败。
2个帅哥中的2个失败 - 将拒绝保存到文件src / Plugin / Field / FieldType / FieldCollection.php.rej
修补文件src / Plugin / Field / FieldWidget / FieldCollectionEmbedWidget.php
检测到反转(或先前应用)的补丁!假设-R? [N]
我不明白发生了什么。
请问,我该如何解决这个问题?
谢谢