public function canWriteToContainer(ElggEntity $entity, $user_guid = 0, $type = 'all', $subtype = 'all')
{
try {
$user = $this->entities->getUserForPermissionsCheck($user_guid);
} catch (UserFetchFailureException $e) {
return false;
}
if ($user) {
$user_guid = $user->guid;
}
$params = ['container' => $entity, 'user' => $user, 'subtype' => $subtype];
// Unlike permissions, logic check can be used to prevent certain entity
// types from being contained by other entity types,
// e.g. discussion reply objects can only be contained by discussion objects.
// This hook can also be used to apply status logic, e.g. to disallow
// new replies in closed discussions.
// We do not take a stand hence the return is null. This can be used by
// handlers to check if another hook has modified the value.
$logic_check = $this->hooks->trigger('container_logic_check', $type, $params);
if ($logic_check === false) {
return false;
}
$return = false;
if ($entity) {
// If the user can edit the container, they can also write to it
if ($entity->canEdit($user_guid)) {
$return = true;
}
}
// Container permissions can prevent users from writing to an entity.
// For instance, these permissions can prevent non-group members from writing
// content to the group.
return $this->hooks->trigger('container_permissions_check', $type, $params, $return);
}