-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathTreePickerProvider.php
More file actions
117 lines (99 loc) · 2.94 KB
/
Copy pathTreePickerProvider.php
File metadata and controls
117 lines (99 loc) · 2.94 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/**
* This file is part of contao-community-alliance/dc-general.
*
* (c) 2013-2024 Contao Community Alliance.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* This project is provided in good faith and hope to be usable by anyone.
*
* @package contao-community-alliance/dc-general
* @author Sven Baumann <baumann.sv@gmail.com>
* @author Ingolf Steinhardt <info@e-spin.de>
* @copyright 2013-2024 Contao Community Alliance.
* @license https://github.com/contao-community-alliance/dc-general/blob/master/LICENSE LGPL-3.0-or-later
* @filesource
*/
namespace ContaoCommunityAlliance\DcGeneral\Contao\Picker;
use Contao\CoreBundle\Picker\DcaPickerProviderInterface;
use Contao\CoreBundle\Picker\PickerConfig;
/**
* Provides the tree picker.
*/
class TreePickerProvider extends AbstractAwarePickerProvider implements DcaPickerProviderInterface
{
/**
* {@inheritdoc}
*/
public function getName(): string
{
return 'ccaTreePicker';
}
/**
* {@inheritdoc}
*/
public function supportsContext(string $context): bool
{
return 'cca_tree' === $context;
}
/**
* {@inheritdoc}
*/
public function supportsValue(PickerConfig $config): bool
{
if ('cca_tree' === $config->getContext()) {
return is_numeric($config->getValue());
}
return false !== strpos($config->getValue(), '{{link_url::');
}
/**
* {@inheritdoc}
*/
public function getDcaTable(PickerConfig|null $config = null): string
{
return 'tl_page';
}
/**
* {@inheritdoc}
*/
public function getDcaAttributes(PickerConfig $config): array
{
$value = $config->getValue();
$attributes = ['fieldType' => 'radio'];
if ('cca_tree' === $config->getContext()) {
if ($fieldType = $config->getExtra('fieldType')) {
$attributes['fieldType'] = $fieldType;
}
if (\is_array($rootNodes = $config->getExtra('rootNodes'))) {
$attributes['rootNodes'] = $rootNodes;
}
if ($value) {
$attributes['value'] = \array_map('intval', \explode(',', $value));
}
return $attributes;
}
if ($value && false !== \strpos($value, '{{link_url::')) {
$attributes['value'] = \str_replace(['{{link_url::', '}}'], '', $value);
}
return $attributes;
}
/**
* {@inheritdoc}
*/
public function convertDcaValue(PickerConfig $config, mixed $value): int|string
{
if ('cca_tree' === $config->getContext()) {
return (int) $value;
}
return '{{link_url::' . $value . '}}';
}
/**
* {@inheritdoc}
*/
protected function getRouteParameters(?PickerConfig $config = null)
{
return ['do' => 'tree'];
}
}