public function evaluate(APILimitationValue $value, APIUserReference $currentUser, ValueObject $object, array $targets = null)
{
if (!$value instanceof APISubtreeLimitation) {
throw new InvalidArgumentException('$value', 'Must be of type: APISubtreeLimitation');
}
if ($object instanceof ContentCreateStruct) {
return $this->evaluateForContentCreateStruct($value, $targets);
} elseif ($object instanceof Content) {
$object = $object->getVersionInfo()->getContentInfo();
} elseif ($object instanceof VersionInfo) {
$object = $object->getContentInfo();
} elseif (!$object instanceof ContentInfo) {
// As this is Role limitation we need to signal abstain on unsupported $object
return self::ACCESS_ABSTAIN;
}
// Load locations if no specific placement was provided
if ($targets === null) {
if ($object->published) {
$targets = $this->persistence->locationHandler()->loadLocationsByContent($object->id);
} else {
// @todo Need support for draft locations to to work correctly
$targets = $this->persistence->locationHandler()->loadParentLocationsForDraftContent($object->id);
}
}
foreach ($targets as $target) {
if (!$target instanceof Location && !$target instanceof SPILocation) {
// As this is Role limitation we need to signal abstain on unsupported $targets
return self::ACCESS_ABSTAIN;
}
foreach ($value->limitationValues as $limitationPathString) {
if ($target->pathString === $limitationPathString) {
return true;
}
if (strpos($target->pathString, $limitationPathString) === 0) {
return true;
}
}
}
return false;
}