Elgg\UserCapabilities::canEditAnnotation PHP Method

canEditAnnotation() public method

Determines whether or not the user can edit this annotation
See also: elgg_set_ignore_access()
public canEditAnnotation ( ElggEntity $entity, integer $user_guid, ElggAnnotation $annotation = null ) : boolean
$entity ElggEntity Object entity
$user_guid integer The GUID of the user (defaults to currently logged in user)
$annotation ElggAnnotation Annotation
return boolean
    public function canEditAnnotation(ElggEntity $entity, $user_guid = 0, ElggAnnotation $annotation = null)
    {
        if (!$annotation) {
            return false;
        }
        try {
            $user = $this->entities->getUserForPermissionsCheck($user_guid);
        } catch (UserFetchFailureException $e) {
            return false;
        }
        $result = false;
        if ($user) {
            // If the owner of annotation is the specified user, they can edit.
            if ($annotation->owner_guid == $user->guid) {
                $result = true;
            }
            // If the user can edit the entity this is attached to, they can edit.
            if ($result == false && $entity->canEdit($user->guid)) {
                $result = true;
            }
        }
        // Trigger plugin hook - note that $user may be null
        $params = ['entity' => $entity, 'user' => $user, 'annotation' => $annotation];
        return $this->hooks->trigger('permissions_check', 'annotation', $params, $result);
    }