2017-09-15 143 views
0

在我的Drupal項目中,我有這樣的錯誤:參數1傳遞給EntityViewBuilder必須實現接口,NULL給出

Recoverable fatal error: Argument 1 passed to Drupal\Core\Entity\EntityViewBuilder::view() must implement interface Drupal\Core\Entity\EntityInterface, null given, called in /Users/team1/workspace/ga_p/modules/field_collection/src/Plugin/Field/FieldFormatter/FieldCollectionItemsFormatter.php on line 33 and defined in Drupal\Core\Entity\EntityViewBuilder->view() (line 110 of core/lib/Drupal/Core/Entity/EntityViewBuilder.php). I do not know if it's from having created multiple fields (fieldCollections)

但我不知道如何刪除這個錯誤。

Drupal的版本:8.3.4

+0

同樣的問題在這裏https://drupal.stackexchange.com/questions/245964/argument-1-passed-to-entityviewbuilder-must-implement-interface-null-given –

回答

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

+0

我不知道很好,他們如何把補丁。 你能否告訴我如何應用它的細節? 謝謝 – Javier

0

我執行

patch -p1 < bin/patchs/fieldCollection.patch

輸出:

can't find file to patch at input line 5

Perhaps you used the wrong -p

or --strip option? The text leading up to this was:

-------------------------- |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

-------------------------- File to patch:

在這一點上,我發現我的電腦 「FieldCollection.php」 的文件上,把絕對路徑

/用戶/team1/workspace/ga_p/modules/field_collection/src/Plugin/Field/FieldType/FieldCollection.php

patching file /Users/team1/workspace/ga_p/modules/field_collection/src/Plugin/Field/FieldType/FieldCollection.php

Hunk #1 FAILED at 183. Hunk #2 succeeded at 159 (offset -68 lines). 1

out of 2 hunks FAILED -- saving rejects to file

/Users/team1/workspace/ga_p/modules/field_collection/src/Plugin/Field/FieldType/FieldCollection.php.rej

can't find file to patch at input line 47 Perhaps you used the wrong

-p or --strip option? The text leading up to this was:

-------------------------- |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


File to patch: /Users/team1/workspace/ga_p/modules/field_collection/src/Plugin/Field/FieldWidget/FieldCollectionEmbedWidget.php

在這一點上,我在我的電腦上找到 「FieldCollectionEmbedWidget.php」 文件,並將絕對路徑

/用戶/ TEAM1 /工作區/ ga_p /模塊/ field_collection/src目錄/插件/場/FieldWidget/FieldCollectionEmbedWidget.php

patching file

/Users/team1/workspace/ga_p/modules/field_collection/src/Plugin/Field/FieldWidget/FieldCollectionEmbedWidget.php

Hunk #1 succeeded at 111 (offset 7 lines).

但是問題仍然存在

+0

該修補程序未應用 - 您需要在此運行命令/ Users/team1/workspace/ga_p/modules/field_collection/...否則手動掛起線路,重建緩存並重試。 –

+0

我在該文件夾中運行該命令並應用了補丁程序。但問題仍然存在...... – Javier

+0

您重建了緩存嗎? –

0

我試圖通過GIT

運行補丁

[email protected]:[~/workspace/ga_p/modules/field_collection]: (master): git apply -v /Users/team1/workspace/ga_p/bin/patchs/fieldCollection.patch

Skipped patch 'src/Plugin/Field/FieldType/FieldCollection.php'.

Skipped patch 'src/Plugin/Field/FieldWidget/FieldCollectionEmbedWidget.php'.

因爲它沒有工作,我嘗試過這樣的:

[email protected]:[~/workspace/ga_p/modules/field_collection]: (master): patch -p1 < /Users/team1/workspace/ga_p/bin/patchs/fieldCollection.patch

patching file src/Plugin/Field/FieldType/FieldCollection.php

Hunk #1 FAILED at 183.

Hunk #2 FAILED at 227.

2 out of 2 hunks FAILED -- saving rejects to file src/Plugin/Field/FieldType/FieldCollection.php.rej

patching file src/Plugin/Field/FieldWidget/FieldCollectionEmbedWidget.php

Reversed (or previously applied) patch detected! Assume -R? [n]

我不明白髮生了什麼。

請問,我該如何解決這個問題?

謝謝

相關問題