0

In my module (fork of ECK Clone) I'm trying to set a default value when an entity of type "Course" is cloned.

Currently I do:

function eck_clone_clone_entity($entity, $account = FALSE) {

  $original_entity = clone $entity;

  $entity->id = NULL;

  if ($account && isset($entity->uid)) {
    $entity->uid = $account->uid;
  }

  if (isset($entity->created)) {
    $entity->created = NULL;
  }

  if (isset($entity->changed)) {
    $entity->changed = NULL;
  }

  if (isset($entity->title)) {
    $entity->title = t('Clone of !title', array('!title' => $entity->title));
  }

  $entity->status = 1;
  $entity->some_boolean = 1;
  $entity->content_status = 1164;

  $context = array('original_entity' => $original_entity);

  drupal_alter('clone_eck', $entity, $context);

  entity_save($entity->type, $entity);

  return $entity;
}

PS: some_boolean value gets set, but not the status. I wonder why.

What I need is to check if the $entity is of the type "Course". I thought it would be as simple as wrapping it in an if statement like so:

if($type == 'course') {
    $entity->some_boolean = 0;
    $entity->content_status = 665;
    $entity->course_number = 3;
    $entity->tag_line = "some other tag line here";
  }

But that doesn't work. Any idea? PS: some_boolean value gets set, but not the status.

1
  • 1
    In your code above, $type is never set. – Kevin Apr 21 at 16:35
0

Like @Kevin pointed out, $type was never set. That was helpful.
I believe this works:

if($entity->type == 'course') {
  $entity->some_boolean = 0;
  $entity->content_status = 665;
  $entity->course_number = 3;
  $entity->tag_line = "some other tag line here";
}

If you can improve this, please let me know. Much appreciated.

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.