Problem/Motivation

Node state provided by workbench_moderation module, got copied to the cloned node independent of publishing options clone setting.

Proposed resolution

Reset workbench_moderation status with respect of publishing options clone settings.

Remaining tasks

n/a

User interface changes

n/a

API changes

n/a

Data model changes

n/a

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

coolestdude1’s picture

I am encountering the same issue as mentioned with similar messages

Warning: Creating default object from empty value in workbench_moderation_store() (line 1785 of /sites/all/modules/contrib/workbench_moderation/workbench_moderation.module).

EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7844 of /includes/common.inc).

As ladybug_3777 mentioned the issue was reported to workbench_moderation here #2331169 but the issue stems from node_clone functionality when assigning properties to cloned nodes. Assuming other modules are also affected. Drupal V7.38, Node Clone V7.x-1.0-rc2

(excuse the line number differences in workbench_moderation module as some custom code was in the mix, the custom code is no where near this functionality)

TAT_Audaxis’s picture

Hello,

I stumbled upon this page by searching for information on the same error.

Creating default object from empty value workbench_moderation.module:1787  [warning]
WD node: EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7844 of /var/www/includes/common.inc). [error]

The fact is... I don't have the node_clone module enabled! But I have Workbench Moderation 7.x-1.4 and -- I think it's related in my case -- uuid_features 7.x-1.0-alpha4 that I use to feature some nodes.

Hope this helps.

pwolanin’s picture

Status: Active » Closed (cannot reproduce)

Need more detailed steps to reproduce this.

ladybug_3777’s picture

Status: Closed (cannot reproduce) » Active

I'm not sure why you had trouble reproducing this error, but let me give you the steps I used with a stripped down site:

I installed Drupal 7.41 and I installed node clone (version 7.x-1.0-rc2) and Workbench Moderation (version 7.x-1.4)

I edited the Content Type Basic page and under the "Publishing Options" did the following

  • un-cheked "Published"
  • un-checked "Promote to front page"
  • left sticky as is (un-checked)
  • checked "Create a new revision"
  • checked "Enabled moderation of revisions"
  • Left the default moderation state set at "Draft"
  • I then added a new basic page, gave the page a title and set the moderation state to "PUBLISHED" and saved the node.
  • I went to the content listing page (admin/content) and clicked on the "clone" link under the Operations column.
  • I left everything with the default clone options and clicked "Save" (Item saved as a DRAFT).
  • I then went to Reports --> Recent Log Messages and you will then see these errors listed at the top of the log:

EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7879 of C:\inetpub\wwwroot\drupal_test\includes\common.inc).

Warning: Creating default object from empty value in workbench_moderation_store() (line 1787 of C:\inetpub\wwwroot\drupal_test\sites\all\modules\workbench_moderation\workbench_moderation.module).

If you follow those steps it should be easy to re-produce.

pwolanin’s picture

Thanks for those more detailed steps.

Perhaps you can try switching to the save-edit cloning method and see if it gives the same error?

In either case, workbench moderation's treatment of revisions as drafts might be the problem here. You would need to follow the code flow, and there might need to be some workbench-specific fixup code for an alter hook.

ladybug_3777’s picture

Workbench moderation has claimed the issue is not their responsibility to fix in this post https://www.drupal.org/node/2331169 I don't know where the true responsibility is, just hoping someone has a solution to fix it. Again, it's not a high priority problem since it seems to silently error and as far as I can tell clone worked just fine. (Unless something else is going on in the backend that I do not see)

If you mean using the "Clone content" link that is shown when you are viewing the node, then yes, I just tried that and the error happens using that cloning method as well. :-(

I'll keep my stripped down Drupal site up for a while if you want me to try out anything else for you.

pwolanin’s picture

No, I mean in the module settings you can choose between a "prepoulate" mode and a "save-edit" mode. I expect you'll see the same problem with save-edit also, but it's worth a try.

ladybug_3777’s picture

Actually, the error is NOT present when I change to the save-edit option. Interesting....

One other strange thing I noticed, (probably a different issue) is when using the save-edit option if I clone from the content listing page, the node is cloned and saved, I don't see the edit node page. HOWEVER, if I use the "clone content" link when viewing the node itself, I AM brought to the node edit page. (Odd that clone would act differently based on the link I use to do the cloning) With the "pre-populate the node form field"s option turned on I am always brought to the node edit page regardless of the link I use to clone.

Leeteq’s picture

Version: 7.x-1.0-rc2 » 7.x-1.x-dev
gdaw’s picture

My testing has shown different results, and I get the same error message using both settings (admin/config/content/clone) "Pre-populate the node form fields" + "Save as a new node then edit".

Only when the page being cloned is Published does the error occur for me. If the page being cloned is in Draft or Ready to publish state there will be no error message. In all cases the newly cloned page is a Draft with no Published.

ladybug_3777’s picture

I can partially confirm what gdaw has seen. Although I do still see different behavior using the save-edit option, I agree that when I am seeing the error when pre-populate is turned on that the error is not there if the item I'm cloning is a draft only instead of published.

iSoLate’s picture

I think the issue lies in the following lines:

if (variable_get('clone_reset_'. $node->type, FALSE)) {
    $node_options = variable_get('node_options_'. $node->type, array('status', 'promote'));
    // Fill in the default values.
    foreach (array('status', 'moderate', 'promote', 'sticky', 'revision') as $key) {
      // Cast to int since that's how they need to be saved to the DB.
      $node->$key = (int) in_array($key, $node_options);
    }
  }

Especially the entry 'moderate'... Shouldn't this be 'workbench_moderation'? I didn't write a patch for this because I am not sure about it, maybe there was another reason for this.

For now I fixed it by adding the following in another module:

/**
 * Implements hook_clone_node_alter().
 */
function MODULE_clone_node_alter(&$node, $context) {
  $node->workbench_moderation = 0;
}

This works because in workbench_moderation_moderate() the following code is being executed:

  if (!empty($node->workbench_moderation['published']) || !empty($node->workbench_moderation['current']->unpublishing)) {
    // Clone the node to make sure our data arrives intact in the shutdown
    // function. It might still be altered before the shutdown is reached.
    drupal_register_shutdown_function('workbench_moderation_store', clone $node);
  }

Thus when cloning, at this point, the workbench_moderation settings got cloned as well so when cloning a published node the following structure will be filled:
$node->workbench_moderation['current']
$node->workbench_moderation['published]
etc.

The current will have the new clone node settings but the published entry will have the original published node settings so it will go through the workbench_moderation_store() function where the following will be called:

  if (empty($node->workbench_moderation['current']->unpublishing)) {
    $live_revision = workbench_moderation_node_live_load($node);
    $live_revision->status = 1;
  }

But for the new clone, workbench_moderation_node_live_load($node) will give back a woeful result which will be saved later inside the workbench_moderation_store() function so you will get the exception...

ladybug_3777’s picture

So are you taking the approach of this method: https://www.drupal.org/node/386440 Where you are basically excluding workbench moderation from being cloned?

Is there a specific reason you chose to set the value to a 0 instead of NULL? I didn't fully follow the last part regarding the shutdown_function piece so I think I'm just missing an important piece you are explaining.

The idea of just excluding that bit from being cloned is probably a good workaround though

iSoLate’s picture

I just used the same logic as node_clone does when it sets the default values for things like 'sticky', 'moderate', etc so:
$node->$key = (int) in_array($key, $node_options);
which would result in 0. But I assume either 0 or NULL would work.

alexharries’s picture

Hmm, I'm also seeing this issue, and it seems that once the node is saved in this broken state, it remains in this confused state...

I tried iSoLate's suggestion to use a hook alter but that didn't seem to work - possibly because $node->workbench_moderation is an object of states rather than a bool?

fengtan’s picture

We are also experiencing this issue.

Confirmed that the error goes away when using the save-edit method instead of the pre-populate one (admin/config/content/clone).

Attached is a quick patch based on what @iSoLate described in comment #12 -- it seems to work, though I am not sure what the implications are. If we go that route, maybe we will need to update {system} and assign workbench_moderation a higher weight than node_clone's.

fengtan’s picture

Alternatively, how about implementing hook_node_clone_alter() as described in #12 in workbench_moderation ? Made a suggestion here: https://www.drupal.org/node/2331169#comment-11114593

l0ke’s picture

Status: Active » Needs review
Related issues: +#2331169: Problem with module node clone
l0ke’s picture

Title: Issue when used with Workbench Moderation » Reset Workbench Moderation state
Issue summary: View changes
FileSize
525 bytes

I think there is a better place for workbench_moderation information reset. _clone_node_prepare seems to be the best place because it allows to control a reset to defaults via settings that node_clone module provides.

seantwalsh’s picture

I ran into this issue as well, only to realize that the configuration of node_clone provided a solution.

On the config page (/admin/config/content/clone), there is a section "Should the publishing options ( e.g. published, promoted, etc) be reset to the defaults?" by checking off the ones that are applicable cloning and using workbench_moderation results in the expected behavior of the cloned node being reset to the content type's default publishing options. Thus, cloning a published node saves the node as unpublished if that is the default publishing option.

DrIPA’s picture

I can confirm that #20 is working.
Would be nice to have this documented.

junaidpv’s picture

Enhancement over #19. Improved if conditions.

lily.yan’s picture

#22 is working for me. Thanks.

ebremner’s picture

So after trying #20, we were still getting the error on cloning content. In order to fix the cloning we used the patch from #22 and that seems to have fixed the issue.

kpaxman’s picture

There is a typo on the PHP comments in the patch in comment #22 - is "newly ceared" meant to be "newly created" or "newly cleared"? (I almost just posted an updated patch, but decided I wasn't 100% sure of the intent.)

junaidpv’s picture

Sorry for the typo. Corrected the comments.

michel.settembrino’s picture

Status: Needs review » Reviewed & tested by the community

#26 is working for me!