Moderation-aware formatters for EntityReference fields

Created on 18 July 2014, over 10 years ago
Updated 13 February 2023, almost 2 years ago

Hello. I recently had to create support for Entity Reference fields in WB Moderation, so that Draft views show the Draft versions of related nodes instead of the default ones, typically normal users are not affected but editors/contributors can see the latest version of both the source content and the referenced content.

This is done by EntityReference Workbench: https://www.drupal.org/sandbox/fgm/entityreference_workbench

This could be merged in WB Moderation itself (in which case I'd just close the sandbox), or mentioned on the project page.

Feature request
Status

Needs review

Version

1.0

Component

Code

Created by

🇫🇷France fgm Paris, France

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇬🇧United Kingdom steven jones

    I've found a minor performance optimization, in:

    +++ b/workbench_moderation.module
    @@ -142,6 +142,154 @@ function workbench_moderation_menu() {
    +          $has_view_access = (entity_access('view', $target_type, $target_id) !== FALSE);
    +          $has_update_access = (entity_access('update', $target_type, $target_id) !== FALSE);
    +          $items[$nid][$delta]['access'] = ($has_view_access || $has_update_access);
    

    We always compute the $has_update_access value, but actually, if $has_view_access == TRUE, the we don't need to.
    If the update access is expensive to compute, then we can skip all of that by doing this:

    $items[$nid][$delta]['access'] = (entity_access('view', $target_type, $target_id) !== FALSE) || (entity_access('update', $target_type, $target_id) !== FALSE);
    

    Simple, and no functional change, except I suppose if the entity_access call has side-effects, but urgh, let's not go down that rabbit hole.

Production build 0.71.5 2024