dnadesign /
silverstripe-elemental
| 1 | <?php |
||
| 2 | |||
| 3 | namespace DNADesign\Elemental\GraphQL; |
||
| 4 | |||
| 5 | use DNADesign\Elemental\Models\ElementalArea; |
||
| 6 | use Exception; |
||
| 7 | use GraphQL\Type\Definition\ResolveInfo; |
||
| 8 | use InvalidArgumentException; |
||
| 9 | use SilverStripe\GraphQL\OperationResolver; |
||
| 10 | |||
| 11 | class ReadOneAreaResolver implements OperationResolver |
||
| 12 | { |
||
| 13 | public function resolve($object, array $args, $context, ResolveInfo $info) |
||
| 14 | { |
||
| 15 | $area = ElementalArea::get()->byID($args['ID']); |
||
| 16 | |||
| 17 | if (!$area) { |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 18 | throw new InvalidArgumentException('Could not find elemental area matching ID ' . $args['ID']); |
||
| 19 | } |
||
| 20 | |||
| 21 | if (!$area->canView($context['currentUser'])) { |
||
| 22 | throw new Exception('Current user cannot view element areas'); |
||
| 23 | } |
||
| 24 | |||
| 25 | return $area; |
||
| 26 | } |
||
| 27 | } |
||
| 28 |