Tried using this module with the workbench moderation module enabled and noticed when ever I edit an existing referenced entity even after saving new changes aren't reflected. Did some digging and discovered this is because the workbench moderation module creates the new saved content as a draft and there is no option from the inline entity edit form to change the moderation state. This would be a nice feature to have.

Comments

John Pitcairn’s picture

Category: feature » bug

>> active (no patch to review)

If Field Collection is anything to go by, support for Workbench Moderation could be difficult.

Ideally a new non-default revision of the referenced entity should be saved if the parent node entity is also saving a new non-published revision. The referenced entity's revision_id should be included, not just the entity id, so you see the difference between published and draft revisions when viewing the parent node.

This gets tricky because Workbench Moderation is a node module - it does not support Entity API's native is_default flag. Workbench Moderation also defers its processing until shutdown, and Field API has already saved the new field revision data as default (published) as a result.

See #1901892: Most recent Field Collection revision always appears in View when using Workbench Moderation and #1807460: Field collection doesn't play nice with workbench moderation (patch)

Kristen Pol’s picture

Issue summary: View changes

Updated issue summary.

John Pitcairn’s picture

Category: bug » feature
Status: Needs review » Active

And this would be a feature request, not a bug.

edutrul’s picture

Issue summary: View changes

I love this! and this needs to be in d8 as well!

edutrul’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
darol100’s picture

1++ for this feature.

dawehner’s picture

For me this sounds really like #2791139: Allow IEF save revisions nodes bundles to be honest. This patch makes it certainly possible to let those two concepts work together.

darol100’s picture

@dawehner I agree with you. Should we close this issue and update the another issue ?

dawehner’s picture

Status: Active » Closed (duplicate)

@darol100
Yeah I believe we can mark this issue as a duplicate of the other one. The other one needs some more testing for example, so in case anyone is interested into that, give it a try.

darol100’s picture

TomTech’s picture

I just had to deal with this issue integrating workbench_moderation, inline_entity_form, and entityreference on D7. The referencd patches are D8.

At least in D7, it seems the main piece missing in the integration is that workbench_moderation injects itself using hook_node_form_alter. But, inline_entity_form doesn't invoke that, since it uses its own node form.

I was able to make this work using the following two hooks. Probably needs to be tested in a greater variety of use cases, but works for what I need right now. I'll create a small integration module if this can't be integrated into workbench_moderation.

/**
 * Implements hook_inline_entity_form_entity_form_alter().
 */
function MYMODULE_inline_entity_form_entity_form_alter(&$entity_form, &$form_state) {
  if ($entity_form['#entity_type'] == 'node') {
    // When editing using an IEF, the node_form_alter calls are not invoked.
    // We need workbench_moderation to be involved, so we will call it directly.

    // It is expecting a #node, so copy #entity there.
    $entity_form['#node'] = $entity_form['#entity'];

    // Make the call.
    workbench_moderation_form_node_form_alter($entity_form, $form_state);

    // Remove the #node, so we don't confuse anyone else.
    unset($entity_form['#node']);

    // If this content is moderated, we need to alter a few things
    // that workbench did.
    if (!empty($entity_form['revision_information']['workbench_moderation_state_new'])) {
      // Let's move moderation state to the bottom of the form.
      $entity_form['revision_information']['#weight'] = 10;
      // Hide the status field, since workbench_moderation takes care of this.
      $entity_form['status']['#access'] = FALSE;
      // Remove the submit handler that workbench put in, which
      // would attempt a redirect in our ajax call.
      unset($entity_form['actions']['submit']['#submit']['workbench_moderation_node_form_submit']);
    }
  }
}

/**
 * Implements hook_node_submit().
 */
function MYMODULE_node_submit($node, $form, &$form_state) {
  // Move the moderation properties/values from the array to the node.
  if (!empty($form['#ief_id'])) {
    if (!empty($node->revision_information)) {
      foreach ($node->revision_information as $key => $value) {
        $node->{$key} = $value;
      }
    }
  }
}