You are here

public function EntityDrupalWrapper::access in Entity API 7

Note that this method checks property access, but can be used for checking entity access *only* if the wrapper is not a property (i.e. has no parent wrapper). To be safe, better use EntityDrupalWrapper::entityAccess() for checking entity access.

Overrides EntityMetadataWrapper::access

File

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

Class

EntityDrupalWrapper
Provides a wrapper for entities registrered in hook_entity_info().

Code

public function access($op, $account = NULL) {
  if (!empty($this->info['parent'])) {

    // If this is a property, make sure the user is able to view the
    // currently referenced entity also.
    if ($this
      ->entityAccess('view', $account) === FALSE) {
      return FALSE;
    }
    if (parent::access($op, $account) === FALSE) {
      return FALSE;
    }

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

    // This is not a property, so fallback on entity access.
    if ($op == 'edit') {

      // If the operation is "edit" determine if its actually a "create" for
      // new un-saved entities, or an "update" for existing ones.
      return $this
        ->entityAccess($this
        ->getIdentifier() ? 'update' : 'create', $account);
    }
    return $this
      ->entityAccess('view', $account);
  }
}