|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of sonata-project. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2010 Thomas Rabaix |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Sonata\DoctrinePHPCRAdminBundle\Twig\Extension; |
|
13
|
|
|
|
|
14
|
|
|
use Sonata\AdminBundle\Admin\FieldDescriptionInterface; |
|
15
|
|
|
use PHPCR\NodeInterface; |
|
16
|
|
|
|
|
17
|
|
|
class SonataDoctrinePHPCRAdminExtension extends \Twig_Extension |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var \Twig_Environment |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $environment; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* {@inheritDoc} |
|
26
|
|
|
*/ |
|
27
|
|
|
public function initRuntime(\Twig_Environment $environment) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->environment = $environment; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* {@inheritDoc} |
|
35
|
|
|
*/ |
|
36
|
|
|
public function getName() |
|
37
|
|
|
{ |
|
38
|
|
|
return 'sonata_doctrine_phpcr_admin'; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* render a list element from the FieldDescription |
|
43
|
|
|
* |
|
44
|
|
|
* @param object $object |
|
45
|
|
|
* @param FieldDescriptionInterface $fieldDescription |
|
46
|
|
|
* @param array $params |
|
47
|
|
|
* |
|
48
|
|
|
* @return string |
|
49
|
|
|
*/ |
|
50
|
|
|
public function renderListElement($object, FieldDescriptionInterface $fieldDescription, $params = array()) |
|
51
|
|
|
{ |
|
52
|
|
|
$template = $this->getTemplate($fieldDescription, 'SonataAdminBundle:CRUD:base_list_field.html.twig'); |
|
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
return $this->output($fieldDescription, $template, array_merge($params, array( |
|
|
|
|
|
|
55
|
|
|
'admin' => $fieldDescription->getAdmin(), |
|
56
|
|
|
'object' => $object, |
|
57
|
|
|
'value' => $this->getValueFromFieldDescription($object, $fieldDescription), |
|
|
|
|
|
|
58
|
|
|
'field_description' => $fieldDescription |
|
59
|
|
|
))); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* {@inheritDoc} |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getFilters() |
|
66
|
|
|
{ |
|
67
|
|
|
return array( |
|
|
|
|
|
|
68
|
|
|
'render_node_property' => new \Twig_Filter_Method($this, 'renderNodeProperty', array('is_safe' => array('html'))), |
|
|
|
|
|
|
69
|
|
|
'render_node_path' => new \Twig_Filter_Method($this, 'renderNodePath', array('is_safe' => array('html'))), |
|
|
|
|
|
|
70
|
|
|
); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Renders a property of a node |
|
76
|
|
|
* |
|
77
|
|
|
* @param NodeInterface $node |
|
78
|
|
|
* @param string $property |
|
79
|
|
|
* |
|
80
|
|
|
* @return string String representation of the property |
|
81
|
|
|
*/ |
|
82
|
|
|
public function renderNodeProperty(NodeInterface $node, $property) |
|
83
|
|
|
{ |
|
84
|
|
|
return $node->getProperty($property)->getString(); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Renders a path of a node |
|
89
|
|
|
* |
|
90
|
|
|
* @param NodeInterface $node |
|
91
|
|
|
* |
|
92
|
|
|
* @return string Node path |
|
93
|
|
|
*/ |
|
94
|
|
|
public function renderNodePath(NodeInterface $node) |
|
95
|
|
|
{ |
|
96
|
|
|
return $node->getPath(); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.