diff --git a/src/Resources/contao/classes/DataContainer.php b/src/Resources/contao/classes/DataContainer.php index 0528969347..cf4c7f6d91 100644 --- a/src/Resources/contao/classes/DataContainer.php +++ b/src/Resources/contao/classes/DataContainer.php @@ -1113,6 +1113,27 @@ protected function getPickerInputField($value, $attributes='') return ''; } + /** + * Return the data-picker-value attribute with the currently selected picker values (see #1816) + * + * @return string + */ + protected function getPickerValueAttribute() + { + // Only load the previously selected values for the checkbox field type (see #2346) + if ($this->strPickerFieldType != 'checkbox') + { + return ''; + } + + $values = array_map($this->objPickerCallback, $this->arrPickerValue); + $values = array_map('strval', $values); + $values = json_encode($values); + $values = htmlspecialchars($values); + + return ' data-picker-value="' . $values . '"'; + } + /** * Build the sort panel and return it as string * diff --git a/src/Resources/contao/drivers/DC_Folder.php b/src/Resources/contao/drivers/DC_Folder.php index f7432fb54a..80b33e3fb7 100644 --- a/src/Resources/contao/drivers/DC_Folder.php +++ b/src/Resources/contao/drivers/DC_Folder.php @@ -444,14 +444,6 @@ public function showAll() $icon = $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['icon'] ?: 'filemounts.svg'; $label = Image::getHtml($icon) . ' '; - // Pass previously selected values to picker (#1816) - $prevPickerValue = ''; - - if ($this->strPickerFieldType) - { - $prevPickerValue = ' data-picker-value="' . htmlspecialchars(json_encode(array_map('strval', $this->arrPickerValue))) . '"'; - } - // Build the tree $return = $this->panel() . Message::generate() . '
' . ((Input::get('act') == 'select') ? ' @@ -467,7 +459,7 @@ public function showAll()

' . $GLOBALS['TL_LANG']['MSC']['selectNewPosition'] . '

' : '') . ' -
' . ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['breadcrumb'] ?? '') . ((Input::get('act') == 'select' || $this->strPickerFieldType == 'checkbox') ? ' +
getPickerValueAttribute() . '>' . ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['breadcrumb'] ?? '') . ((Input::get('act') == 'select' || $this->strPickerFieldType == 'checkbox') ? '
' : '') . ' diff --git a/src/Resources/contao/drivers/DC_Table.php b/src/Resources/contao/drivers/DC_Table.php index 630b051852..09eb54fe8e 100644 --- a/src/Resources/contao/drivers/DC_Table.php +++ b/src/Resources/contao/drivers/DC_Table.php @@ -3643,14 +3643,6 @@ protected function treeView()

' . $GLOBALS['TL_LANG']['MSC']['noResult'] . '

'; } - // Pass previously selected values to picker (#1816) - $prevPickerValue = ''; - - if ($this->strPickerFieldType) - { - $prevPickerValue = ' data-picker-value="' . htmlspecialchars(json_encode(array_map('strval', $this->arrPickerValue))) . '"'; - } - $return .= ((Input::get('act') == 'select') ? '
@@ -3659,7 +3651,7 @@ protected function treeView()

' . $GLOBALS['TL_LANG']['MSC']['selectNewPosition'] . '

' : '') . ' -
' . $breadcrumb . ((Input::get('act') == 'select' || ($this->strPickerFieldType == 'checkbox')) ? ' +
getPickerValueAttribute() . '>' . $breadcrumb . ((Input::get('act') == 'select' || ($this->strPickerFieldType == 'checkbox')) ? '
' : '') . ' @@ -4202,14 +4194,6 @@ protected function parentView() return $return; } - // Pass previously selected values to picker (#1816) - $prevPickerValue = ''; - - if ($this->strPickerFieldType) - { - $prevPickerValue = ' data-picker-value="' . htmlspecialchars(json_encode(array_map('strval', $this->arrPickerValue))) . '"'; - } - $return .= ((Input::get('act') == 'select') ? ' @@ -4219,7 +4203,7 @@ protected function parentView()

' . $GLOBALS['TL_LANG']['MSC']['selectNewPosition'] . '

' : '') . ' -
+
getPickerValueAttribute() . '>
'; // List all records of the child table @@ -4840,20 +4824,12 @@ protected function listView() { $result = $objRow->fetchAllAssoc(); - // Pass previously selected values to picker (#1816) - $prevPickerValue = ''; - - if ($this->strPickerFieldType) - { - $prevPickerValue = ' data-picker-value="' . htmlspecialchars(json_encode(array_map('strval', $this->arrPickerValue))) . '"'; - } - $return .= ((Input::get('act') == 'select') ? '
' : '') . ' -
' . ((Input::get('act') == 'select' || $this->strPickerFieldType == 'checkbox') ? ' +
getPickerValueAttribute() . '>' . ((Input::get('act') == 'select' || $this->strPickerFieldType == 'checkbox') ? '
' : '') . '