|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Routes. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright Zikula contributors (Zikula) |
|
7
|
|
|
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License |
|
8
|
|
|
* @author Zikula contributors <[email protected]>. |
|
9
|
|
|
* |
|
10
|
|
|
* @see https://ziku.la |
|
11
|
|
|
* |
|
12
|
|
|
* @version Generated by ModuleStudio 1.5.0 (https://modulestudio.de). |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
declare(strict_types=1); |
|
16
|
|
|
|
|
17
|
|
|
namespace Zikula\RoutesModule\Twig\Base; |
|
18
|
|
|
|
|
19
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface; |
|
20
|
|
|
use Twig\Extension\RuntimeExtensionInterface; |
|
21
|
|
|
use Zikula\Bundle\CoreBundle\Doctrine\EntityAccess; |
|
22
|
|
|
use Zikula\Bundle\CoreBundle\Translation\TranslatorTrait; |
|
23
|
|
|
use Zikula\ExtensionsModule\Api\ApiInterface\VariableApiInterface; |
|
24
|
|
|
use Zikula\RoutesModule\Helper\EntityDisplayHelper; |
|
25
|
|
|
use Zikula\RoutesModule\Helper\ListEntriesHelper; |
|
26
|
|
|
use Zikula\RoutesModule\Helper\WorkflowHelper; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Twig runtime base class. |
|
30
|
|
|
*/ |
|
31
|
|
|
abstract class AbstractTwigRuntime implements RuntimeExtensionInterface |
|
32
|
|
|
{ |
|
33
|
|
|
use TranslatorTrait; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var VariableApiInterface |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $variableApi; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var EntityDisplayHelper |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $entityDisplayHelper; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var WorkflowHelper |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $workflowHelper; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var ListEntriesHelper |
|
52
|
|
|
*/ |
|
53
|
|
|
protected $listHelper; |
|
54
|
|
|
|
|
55
|
|
|
public function __construct( |
|
56
|
|
|
TranslatorInterface $translator, |
|
57
|
|
|
VariableApiInterface $variableApi, |
|
58
|
|
|
EntityDisplayHelper $entityDisplayHelper, |
|
59
|
|
|
WorkflowHelper $workflowHelper, |
|
60
|
|
|
ListEntriesHelper $listHelper |
|
61
|
|
|
) { |
|
62
|
|
|
$this->setTranslator($translator); |
|
63
|
|
|
$this->variableApi = $variableApi; |
|
64
|
|
|
$this->entityDisplayHelper = $entityDisplayHelper; |
|
65
|
|
|
$this->workflowHelper = $workflowHelper; |
|
66
|
|
|
$this->listHelper = $listHelper; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* The zikularoutesmodule_objectState filter displays the name of a given object's workflow state. |
|
71
|
|
|
* Examples: |
|
72
|
|
|
* {{ item.workflowState|zikularoutesmodule_objectState }} {# with visual feedback #} |
|
73
|
|
|
* {{ item.workflowState|zikularoutesmodule_objectState(false) }} {# no ui feedback #}. |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getObjectState(string $state = 'initial', bool $uiFeedback = true): string |
|
76
|
|
|
{ |
|
77
|
|
|
$stateInfo = $this->workflowHelper->getStateInfo($state); |
|
78
|
|
|
|
|
79
|
|
|
$result = $stateInfo['text']; |
|
80
|
|
|
if (true === $uiFeedback) { |
|
81
|
|
|
$result = '<span class="badge badge-' . $stateInfo['ui'] . '">' . $result . '</span>'; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
return $result; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* The zikularoutesmodule_listEntry filter displays the name |
|
89
|
|
|
* or names for a given list item. |
|
90
|
|
|
* Example: |
|
91
|
|
|
* {{ entity.listField|zikularoutesmodule_listEntry('entityName', 'fieldName') }}. |
|
92
|
|
|
*/ |
|
93
|
|
|
public function getListEntry( |
|
94
|
|
|
string $value, |
|
95
|
|
|
string $objectType = '', |
|
96
|
|
|
string $fieldName = '', |
|
97
|
|
|
string $delimiter = ', ' |
|
98
|
|
|
): string { |
|
99
|
|
|
if ((empty($value) && '0' !== $value) || empty($objectType) || empty($fieldName)) { |
|
100
|
|
|
return $value; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
return $this->listHelper->resolve($value, $objectType, $fieldName, $delimiter); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* The zikularoutesmodule_formattedTitle filter outputs a formatted title for a given entity. |
|
111
|
|
|
* Example: |
|
112
|
|
|
* {{ myPost|zikularoutesmodule_formattedTitle }}. |
|
113
|
|
|
*/ |
|
114
|
|
|
public function getFormattedEntityTitle(EntityAccess $entity): string |
|
115
|
|
|
{ |
|
116
|
|
|
return $this->entityDisplayHelper->getFormattedTitle($entity); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|