IF statement to check if loaded entity is of type In my module (fork of ECK Clone) I'm trying to set a default value when an entity of type &quot;Course&quot; is cloned.
Currently I do:
function eck_clone_clone_entity($entity, $account = FALSE) {

  $original_entity = clone $entity;

  $entity-&gt;id = NULL;

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

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

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

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

  $entity-&gt;status = 1;
  $entity-&gt;some_boolean = 1;
  $entity-&gt;content_status = 1164;

  $context = array('original_entity' =&gt; $original_entity);

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

  entity_save($entity-&gt;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 &quot;Course&quot;.
I thought it would be as simple as wrapping it in an if statement like so:
if($type == 'course') {
    $entity-&gt;some_boolean = 0;
    $entity-&gt;content_status = 665;
    $entity-&gt;course_number = 3;
    $entity-&gt;tag_line = &quot;some other tag line here&quot;;
  }

But that doesn't work. Any idea?
PS: some_boolean value gets set, but not the status.
Like @Kevin pointed out, $type was never set. That was helpful.
I believe this works:
if($entity-&gt;type == 'course') {
  $entity-&gt;some_boolean = 0;
  $entity-&gt;content_status = 665;
  $entity-&gt;course_number = 3;
  $entity-&gt;tag_line = &quot;some other tag line here&quot;;
}

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