1

What is the proper way to address and modify a node's authored on date? I created a slew of new nodes via a CSV import via the Feeds module. These nodes now have the date of 2013-07-11 as the authored on date as that's when I did the import. But each node refers to a previous date and I need the authored on date to reflect that.

I have a content type I've created that has a separate Date field where I choose the date. I'd like to eliminate that and just use the authored on date instead.

I'm trying to use VBO to run a custom PHP snippet to make this change but the examples I've found so far do not work.

$object->created = $object->field_date[0]['value'];
node_save($object);

This snippet when run through VBO returns errors:

Notice: Undefined variable: object in eval() (line 1 of /home/chriscor/public_html /hi_tracker/sites/all/modules/contrib/views_bulk_operations/actions/script.action.inc(20) : eval()'d code).

Notice: Trying to get property of non-object in eval() (line 1 of /home/chriscor/public_html/hi_tracker/sites/all/modules/contrib/views_bulk_operations/actions/script.action.inc(20) : eval()'d code).

EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7693 of /home/chriscor/public_html/hi_tracker/includes/common.inc).

Any idea what I'm missing?

0

It looks like the $object variable doesn't exist, or isn't in scope. Check the arguments your function receives for the proper node object.

  • Thanks Yuriy. I'm not even writing a function though. All I want to do is run some code in the custom PHP code section of VBO that updates the authored on date. Is there perhaps a better way to do this? – ccorbett Jul 15 '13 at 19:12
  • Ah, right, that's why there's the eval business going on. Then it's the same issue as what I described, just in a different context. Try replacing $object with $node; if that still doesn't work, you'll need to refer to the VBO documentation to see what the correct object name is. – Yuriy Babenko Jul 15 '13 at 22:00
0

So, you have probably figure this out by now but in Drupal 7 I had to change $object to $entity and it work - kind of...it is printing today's date in there and not copying the date from the field_post_date into created. Anyway this change will get rid of the error.

This video helped me along with this link:

This code worked...

$entity -> created = strtotime($entity->field_post_date[LANGUAGE_NONE][0]['value']);
node_save($entity);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.