I had setup a custom block type with a link field. I created a block instance with it.
It looks like even without assigning that block to a region it produces errors and makes the front-end of the site render without its theme. The messages:

Notice: Undefined index: path in link_field_formatter_view() (line 376 of core/modules/link/link.module).
Notice: Undefined index: options in link_field_formatter_view() (line 377 of core/modules/link/link.module).

I'm not absolutely sure these notices are the cause for the theme not being rendered. I can't delete the block using the link field so bit hard to reproduce.

Related Issues

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

larowlan’s picture

Assigned: Unassigned » larowlan
larowlan’s picture

Confirming a fatal is thrown, hence the theme blows up

sun’s picture

Priority: Normal » Critical

Loss of theme/page output is critical.

larowlan’s picture

Assigned: larowlan » Unassigned
FileSize
4.38 KB
3.02 KB

$item['path'] doesn't exist so far as I can see.
$item['options'] needs to be something else we get unsupported operand types.

sun’s picture

Assigned: Unassigned » larowlan
Status: Active » Needs review
sun’s picture

What happened to hook_field_prepare_view()?
http://drupalcode.org/project/drupal.git/blob/HEAD:/core/modules/link/li...

Why is it not called for blocks?

Status: Needs review » Needs work

The last submitted patch, link-formatter-1957748.pass_.patch, failed testing.

larowlan’s picture

Status: Needs work » Active

Sun pointed out that link_field_prepare_view not running for custom block.

larowlan’s picture

Status: Active » Needs review
FileSize
5.07 KB
3.02 KB

So turns out hook_field_prepare_view() isn't passed the correct field values if the entity is an NG entity.
We need to invoke the BC.

Status: Needs review » Needs work

The last submitted patch, link-formatter-1957748.pass_.9.patch, failed testing.

tim.plunkett’s picture

+++ b/core/modules/field/field.attach.incundefined
@@ -524,7 +524,11 @@ function _field_invoke_multiple($op, $entity_type, $entities, &$a = NULL, &$b =
+          // Enable BC if necessary.
+          $entity = $entity->getBCEntity();
           $grouped_items[$field_id][$langcode][$id] = isset($entity->{$field_name}[$langcode]) ? $entity->{$field_name}[$langcode] : array();
+          // Reset back to original.
+          $entity = $entity->getOriginalEntity();

@@ -565,6 +568,8 @@ function _field_invoke_multiple($op, $entity_type, $entities, &$a = NULL, &$b =
+          $entity = $entity->getBCEntity();
           $entity->{$field_name}[$langcode] = $grouped_items[$field_id][$langcode][$id];

I'd think you'd have to set it back again in the second hunk as well? Not sure if that's the cause of the fails, I didn't try it.

larowlan’s picture

Status: Needs work » Needs review
FileSize
5.19 KB
1.35 KB
larowlan’s picture

Resetting back to original entity as per #11

larowlan’s picture

Title: undefined indexes in link_field_formatter_view() » hook_field_prepare_view is passed empty field values for EntityNG Entities

New title

Status: Needs review » Needs work

The last submitted patch, link-formatter-1957748.13.patch, failed testing.

larowlan’s picture

Status: Needs work » Needs review
FileSize
5.24 KB
872 bytes

Wrong view mode.
Also, extra $language variable isn't used.

larowlan’s picture

Issue tags: +Entity system
Berdir’s picture

Issue tags: +Entity Field API
yoroy’s picture

I was wondering what kind of freak issue I had gotten subscribed to, but ah, this one :-)

Wim Leers’s picture

Status: Needs review » Needs work

At the bottom of #1818560-33: Convert taxonomy entities to the new Entity Field API (below the last horizontal rule, "Finally: manual testing…"), I explained in detail what seems to be the same problem. Berdir pointed me to this issue in #34 of that issue.
I applied the patch in #16 to check if it'd fix things. Unfortunately, it does not, it causes the site to break entirely:
InvalidArgumentException: Property uuid is unknown. in Drupal\image\Type\ImageItem->setValue() (line 101 of <drupalroot>/core/modules/image/lib/Drupal/image/Type/ImageItem.php).

(This is on the taxonomy term page of a taxonomy term that has an image field associated with it.)

So, AFAICT, this patch has the potential to break Drupal, hence marking as NW.

Finally, AFAICT this is not isolated to "link" fields, since image fields are what's failing for me. If I'm conflating two different issues, then my apologies and feel free to go back to NR.

Berdir’s picture

See also the discussion in #1839068: Implement the new entity field API for the file field type where we already discovered and discussed some of these issues but then forgot about it.

sun’s picture

Status: Needs work » Needs review
Issue tags: -Entity system, -Entity Field API

#16: link-formatter-1957748.16.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +Entity system, +Entity Field API

The last submitted patch, link-formatter-1957748.16.patch, failed testing.

Berdir’s picture

Status: Needs work » Needs review
FileSize
5.21 KB

Sorry that it took me so long to have a look at this :)

field_attach_*() function never should be called with an EntityNG object, that simply doesn't work. So the fault is in EntityRenderController. The existing link field test already fail when ported to use EntityTest (which is NG) instead of TestEntity (which is not), so I just copied over my fix from #1822000: Remove Drupal\field_test\Plugin\Entity\Type\TestEntity in favor of EntityTest, where I'm working on this.

Given that, not sure if we need additional test coverage for this. that issue will provide test coverage as soon as we switch to NG and then this will be mostly a test duplicate. But I kept it for now. Can also try to get over just the link field tests from that issue not sure if they can be isolated easily.

Also fixed ImageItem to work like FieldItemBase and accept all additional things values, at least for now until we have converted everything, then we can switch to use ->entity for this.

Berdir’s picture

Ok, those tests actually call field_attach_*() directly, must have been others that failed. I do wonder if those tests should be converted to use EntityTest instead of a real entity and live in link.module or field.module?

Wim Leers’s picture

Title: hook_field_prepare_view is passed empty field values for EntityNG Entities » hook_field_prepare_view() is passed empty field values for EntityNG Entities
Status: Needs review » Reviewed & tested by the community
Issue tags: +sprint, +Spark

Works perfectly.

Berdir’s picture

Assigned: larowlan » Unassigned

Unassigning @larowlan :)

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/lib/Drupal/Core/Entity/EntityRenderController.phpundefined
@@ -28,7 +28,11 @@ public function __construct($entity_type) {
   public function buildContent(array $entities, array $displays, $view_mode, $langcode = NULL) {
-    field_attach_prepare_view($this->entityType, $entities, $displays, $langcode);
+    $bc_entities = array();
+    foreach ($entities as $entity) {
+      $bc_entities[$entity->id()] = $entity->getBCEntity();
+    }
+    field_attach_prepare_view($this->entityType, $bc_entities, $displays, $langcode);
     module_invoke_all('entity_prepare_view', $this->entityType, $entities, $displays, $view_mode);

I think we could do with a comment to explain what's going on here...

amateescu’s picture

Status: Needs work » Needs review
FileSize
2.82 KB
4.83 KB

Actually, I think that what was going on there is totally unnecessary. Both field_attach_prepare_view() and field_attach_view() have the swtich to BC entities incorporated, the problem was that in field_attach_prepare_view() it was called a bit late.

Berdir’s picture

Oh, didn't know that.

It's a bit inconsistent with all other field_attach_*() functions right now, which except a BC entity. Maybe we should change all these others in a follow-up as well? That would simplify #1822000: Remove Drupal\field_test\Plugin\Entity\Type\TestEntity in favor of EntityTest a lot.

amateescu’s picture

Sure, anything that makes that patch easier gets a huge ++ from me :)

fago’s picture

Status: Needs review » Reviewed & tested by the community

Good fix and comes with tests -> RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 0261175 and pushed to 8.x. Thanks!

amateescu’s picture

Component: link.module » entity system
Status: Fixed » Reviewed & tested by the community

Also, this doesn't have anything to do with link.module, it's more like.. Field API meets EntityNG, unpredictable things are bound to happen :)

amateescu’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, Alex!

Wim Leers’s picture

Issue tags: -sprint

#34: Indeed, that's what I'd been thinking too :)

Thanks!

yoroy’s picture

Never trust me to know the right component for stuff like this :)

Berdir’s picture

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

added related issues section