You are here

protected function EntityStructureWrapper::propertyAccess in Entity API 7

File

includes/entity.wrapper.inc, line 522
Provides wrappers allowing easy usage of the entity metadata.

Class

EntityStructureWrapper
Provides a general wrapper for any data structure. For this to work the metadata has to be passed during construction.

Code

protected function propertyAccess($name, $op, $account = NULL) {
  $info = $this
    ->getPropertyInfo($name);

  // If a property should be edited and this is part of an entity, make sure
  // the user has update access for this entity.
  if ($op == 'edit') {
    $entity = $this;
    while (!$entity instanceof EntityDrupalWrapper && isset($entity->info['parent'])) {
      $entity = $entity->info['parent'];
    }
    if ($entity instanceof EntityDrupalWrapper && $entity
      ->entityAccess('update', $account) === FALSE) {
      return FALSE;
    }
  }
  if (!empty($info['access callback'])) {
    $data = $this
      ->dataAvailable() ? $this
      ->value() : NULL;
    return call_user_func($info['access callback'], $op, $name, $data, $account, $this->type);
  }
  elseif ($op == 'edit' && isset($info['setter permission'])) {
    return user_access($info['setter permission'], $account);
  }

  // If access is unknown, we return TRUE.
  return TRUE;
}