forked from ezsystems/ezpublish-kernel
/
ParameterProvider.php
49 lines (43 loc) · 1.65 KB
/
ParameterProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace eZ\Publish\Core\MVC\Symfony\FieldType\Relation;
use eZ\Publish\API\Repository\ContentService;
use eZ\Publish\API\Repository\Exceptions\NotFoundException;
use eZ\Publish\API\Repository\Exceptions\UnauthorizedException;
use eZ\Publish\API\Repository\Values\Content\Field;
use eZ\Publish\Core\MVC\Symfony\FieldType\View\ParameterProviderInterface;
class ParameterProvider implements ParameterProviderInterface
{
/** @var \eZ\Publish\API\Repository\ContentService */
private $contentService;
/**
* @param \eZ\Publish\API\Repository\ContentService $contentService
*/
public function __construct(ContentService $contentService)
{
$this->contentService = $contentService;
}
/**
* Returns a hash of parameters to inject to the associated fieldtype's view template.
* Returned parameters will only be available for associated field type.
*
* Key is the parameter name (the variable name exposed in the template, in the 'parameters' array).
* Value is the parameter's value.
*
* @param \eZ\Publish\API\Repository\Values\Content\Field $field The field parameters are provided for.
*
* @return array
*/
public function getViewParameters(Field $field)
{
try {
$contentInfo = $this->contentService->loadContentInfo($field->value->destinationContentId);
return [
'available' => !$contentInfo->isTrashed(),
];
} catch (NotFoundException $exception) {
return ['available' => false];
} catch (UnauthorizedException $exception) {
return ['available' => false];
}
}
}