You are here

function flag_entity::applies_to_content_object in Flag 7.2

Checks whether the flag applies for the current entity bundle.

File

./flag.inc, line 1398
Implements various flags. Uses object oriented style inspired by that of Views 2.

Class

flag_entity
Base entity flag handler.

Code

function applies_to_content_object($entity) {
  $entity_info = entity_get_info($this->content_type);

  // The following conditions are applied:
  // - if the types array is empty, the flag applies to all bundles and thus
  //   to this entity.
  // - if the entity has no bundles, the flag applies to the entity.
  // - if the entity's bundle is in the list of types.
  if (empty($this->types) || empty($entity_info['entity keys']['bundle']) || in_array($entity->{$entity_info['entity keys']['bundle']}, $this->types)) {
    return TRUE;
  }
  return FALSE;
}