Spin off from #526122: Autocomplete widget for taxonomy term fields:

On entity preview (currently comments and nodes have previews), the values handed out by widgets are transformed into field values passed to field_attach_view().
Since widgets are supposed to massage their data into ready-for-storage format, the values coming from preview 'look' like regular values loaded from storage, with the difference that they didn't go through hook_field_load() and hook_field_attach_load().

This is annoying, because hook_field_load() is used to load additional information about the values (e.g for 'taxo term' field type, load term name from the tid).
Then each formatter needs to handle the case where hook_field_load() hasn't run and thus load the data it needs itself.

Attached patch makes sure values coming from preview run through hook_field_load() and hook_field_attach_load().

It relies on the presence of an $object->in_preview boolean flag. There's no legacy discrepancies here like those we had to handle for 'id key' or 'bundle key', both node and comment set this flag on their previews, so we are allowed to write this flag name in stone and not bother with exposing an 'in_preview key' in hook_fieldable_info().

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

yched’s picture

FileSize
1.85 KB

Heh, that copy/paste was a little naive...
Better patch.

Status: Needs review » Needs work

The last submitted patch failed testing.

yched’s picture

Status: Needs work » Needs review
FileSize
1.93 KB

Grr, I uploaded the same patch twice. That one should work.

Status: Needs review » Needs work

The last submitted patch failed testing.

yched’s picture

Status: Needs work » Needs review
FileSize
1.94 KB

gosh.

bjaspan’s picture

I do not understand why you are using FIELD_LOAD_REVISION:

+    $objects = array($id => $object);
+    $age = FIELD_LOAD_REVISION;
+    _field_invoke_multiple('load', $obj_type, $objects, $age);

If that is correct, it needs a comment to explain it to me. :-)

yched’s picture

Yeah, the thing is we don't have any information here to determine the correct value for $age, so using FIELD_LOAD_REVISION, which is the 'most generic' case.
I'll add a comment when I'm where I can reroll.

As a side note: I'm note sure the $age param is actually useful for hook_field_load() and hook_field_attach_load(). Note that we already don't reflect the $options param from field_attach_load().

Status: Needs review » Needs work

The last submitted patch failed testing.

catch’s picture

Category: task » bug

This is a bug, not a task. #493314: Add multiple hook for formatters deals with a similar area.

raj47i’s picture

Status: Needs work » Needs review

#1: field_preview.patch queued for re-testing.

scor’s picture

Title: Run hook_field_load() and hook_field_attach_load() on values before preview » Fields not rendered properly during comment preview
FileSize
2.19 KB
2.23 KB

Marking #1061212: image_field_formatter fails in comment preview as duplicate, and retitling this issue to highlight the bug it fixes in the comment preview. To reproduce, add a file or image field to comment, and preview a new comment or an existing comment.

I'm attaching a reroll of #5 which solves the comment issue. I've also added the removal of _field_invoke_multiple() in node_preview() since this is now handled in field_attach_view() directly.

scor’s picture

ah, so -D8.patch is not recognized?

Status: Needs review » Needs work

The last submitted patch, 549710_11_field_preview.patch, failed testing.

scor’s picture

Version: 7.x-dev » 8.x-dev
Status: Needs work » Needs review

forgot to bump version.

scor’s picture

#12: 549710_11_field_preview.patch queued for re-testing.

scor’s picture

Pasting the notices this patch fixes so people experiencing these errors can find this issue... These notices happen when previewing file and image fields on comments.

Notice: Undefined index: uri in image_field_formatter_view() (line 551 of modules/image/image.field.inc).
Notice: Undefined property: stdClass::$uri in theme_file_link() (line 726 of modules/file/file.module).
Notice: Undefined property: stdClass::$filemime in theme_file_icon() (line 764 of modules/file/file.module).
Notice: Undefined property: stdClass::$filemime in file_icon_path() (line 808 of modules/file/file.module).
Notice: Undefined property: stdClass::$filemime in file_icon_map() (line 851 of modules/file/file.module).
Notice: Undefined property: stdClass::$filemime in file_icon_path() (line 823 of modules/file/file.module).
Notice: Undefined property: stdClass::$filemime in theme_file_link() (line 733 of modules/file/file.module).
Notice: Undefined property: stdClass::$filesize in theme_file_link() (line 733 of modules/file/file.module).
SocialNicheGuru’s picture

Status: Needs review » Needs work

The last submitted patch, 12: 549710_11_field_preview.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

catch’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)
Issue tags: +Bug Smash Initiative

There's no longer field rendering separate from entity rendering, so closing this as outdated.