|
6 | 6 | * @author Benny Born <[email protected]>
|
7 | 7 | * @author Michael Bösherz <[email protected]>
|
8 | 8 | * @license LGPL-3.0-or-later
|
9 |
| - * @copyright Copyright (c) 2024, numero2 - Agentur für digitales Marketing GbR |
| 9 | + * @copyright Copyright (c) 2025, numero2 - Agentur für digitales Marketing GbR |
10 | 10 | */
|
11 | 11 |
|
12 | 12 |
|
@@ -60,51 +60,83 @@ public function addBackendHelperFields( $dc ) {
|
60 | 60 | ->addField(['bh_info'], 'expert_legend', 'append')
|
61 | 61 | ;
|
62 | 62 |
|
63 |
| - foreach( $GLOBALS['TL_DCA']['tl_page']['palettes'] as $key => $value ) { |
| 63 | + foreach( $GLOBALS['TL_DCA'][$dc->table]['palettes'] as $key => $value ) { |
64 | 64 |
|
65 | 65 | if( in_array($key, ['__selector__', 'default']) ) {
|
66 | 66 | continue;
|
67 | 67 | }
|
68 | 68 |
|
69 |
| - $pm->applyToPalette($key, 'tl_page'); |
| 69 | + $pm->applyToPalette($key, $dc->table); |
70 | 70 | }
|
71 | 71 | }
|
72 | 72 |
|
73 | 73 |
|
74 | 74 | /**
|
75 |
| - * Add backend helper information to the label |
| 75 | + * Sets the new label callback with respect to any previously added ones |
76 | 76 | *
|
77 |
| - * @param array $row |
78 |
| - * @param string $label |
79 |
| - * @param Contao\DataContainer $dc |
80 |
| - * @param string $imageAttribute |
81 |
| - * @param boolean $blnReturnImage |
82 |
| - * @param boolean $blnProtected |
83 |
| - * @param boolean $isVisibleRootTrailPage |
84 |
| - * |
85 |
| - * @return string |
| 77 | + * @param Contao\DataContainer $dc |
86 | 78 | *
|
87 |
| - * @Callback(table="tl_page", target="list.label.label") |
| 79 | + * @Callback(table="tl_page", target="config.onload") |
88 | 80 | */
|
89 |
| - public function addBackendHelperInfos( $row, $label, DataContainer|null $dc=null, $imageAttribute='', $blnReturnImage=false, $blnProtected=false, $isVisibleRootTrailPage=false ) { |
| 81 | + public function setLabelCallback( $dc ) { |
| 82 | + |
| 83 | + $previousCallback = $GLOBALS['TL_DCA'][$dc->table]['list']['label']['label_callback'] ?? null; |
| 84 | + |
| 85 | + $callback = [$this, 'addBackendHelperInfos']; |
90 | 86 |
|
91 |
| - $t = System::importStatic('tl_page'); |
| 87 | + $GLOBALS['TL_DCA'][$dc->table]['list']['label']['label_callback'] = function () use ($callback, $previousCallback) { |
92 | 88 |
|
93 |
| - if( method_exists($t, 'addIcon') ) { |
94 |
| - $defaultLabel = $t->addIcon(...func_get_args()); |
| 89 | + $args = \func_get_args(); |
| 90 | + $result = null; |
| 91 | + |
| 92 | + if( \is_callable($previousCallback) || \is_array($previousCallback) ) { |
| 93 | + $result = $this->executeCallback($previousCallback, $args); |
| 94 | + } |
| 95 | + |
| 96 | + return $this->executeCallback($callback, [$args, $result]); |
| 97 | + }; |
| 98 | + } |
| 99 | + |
| 100 | + |
| 101 | + /** |
| 102 | + * @param callable|array<string, string> $callback |
| 103 | + * @param array<mixed> $args |
| 104 | + * |
| 105 | + * @return mixed |
| 106 | + */ |
| 107 | + private function executeCallback( $callback, array $args ) { |
| 108 | + |
| 109 | + if( \is_array($callback) ) { |
| 110 | + |
| 111 | + return \call_user_func_array( |
| 112 | + [System::importStatic($callback[0]), $callback[1]], |
| 113 | + $args, |
| 114 | + ); |
95 | 115 | }
|
96 | 116 |
|
| 117 | + return $callback(...$args); |
| 118 | + } |
| 119 | + |
| 120 | + |
| 121 | + /** |
| 122 | + * Add backend helper information to the label |
| 123 | + * |
| 124 | + * @param array $args |
| 125 | + * @param string $label |
| 126 | + * |
| 127 | + * @return string |
| 128 | + */ |
| 129 | + public function addBackendHelperInfos( array $args, string $label ): string { |
| 130 | + |
97 | 131 | $request = $this->requestStack->getCurrentRequest();
|
98 | 132 | if( !$request || !$this->scopeMatcher->isBackendRequest($request) ) {
|
99 |
| - return $defaultLabel; |
| 133 | + return $label; |
100 | 134 | }
|
101 | 135 |
|
102 |
| - if( !empty($row['bh_info']) ) { |
103 |
| - |
104 |
| - $info = '<span class="bh_info">' . $row['bh_info'] . '</span>'; |
105 |
| - $defaultLabel = preg_replace("%</a>$%", $info.'</a>', $defaultLabel); |
| 136 | + if( !empty($args[0]['bh_info']) ) { |
| 137 | + $label .= '<span class="bh_info">' . $args[0]['bh_info'] . '</span>'; |
106 | 138 | }
|
107 | 139 |
|
108 |
| - return $defaultLabel; |
| 140 | + return $label; |
109 | 141 | }
|
110 | 142 | }
|
0 commit comments