Skip to content

Commit

Permalink
Merge branch '5.2' into 5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Jul 11, 2023
2 parents c1cca8d + fe99ef2 commit e548fe3
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 121 deletions.
63 changes: 24 additions & 39 deletions contao/classes/DataContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1688,55 +1688,40 @@ public function generateRecordLabel(array $row, string $table = null, bool $prot

$mode = $GLOBALS['TL_DCA'][$table]['list']['sorting']['mode'] ?? self::MODE_SORTED;

if (\is_callable($labelConfig['label_callback'] ?? null))
{
trigger_deprecation('contao/core-bundle', '5.2', 'Using a single callback for "list.label.label_callback" instead of an array of callbacks has been deprecated and will no longer work in Contao 6.');
$labelConfig['label_callback'] = array($labelConfig['label_callback']);
}

// Execute label_callback
if (\is_array($labelConfig['label_callback'] ?? null))
if (\is_array($labelConfig['label_callback'] ?? null) || \is_callable($labelConfig['label_callback'] ?? null))
{
if (\count($labelConfig['label_callback']) === 2 && \is_string($labelConfig['label_callback'][0]) && \is_string($labelConfig['label_callback'][1]))
if (\in_array($mode, array(self::MODE_TREE, self::MODE_TREE_EXTENDED)))
{
trigger_deprecation('contao/core-bundle', '5.2', 'Using a single callback for "list.label.label_callback" instead of an array of callbacks has been deprecated and will no longer work in Contao 6.');
$labelConfig['label_callback'] = array($labelConfig['label_callback']);
if (\is_array($labelConfig['label_callback']))
{
$label = System::importStatic($labelConfig['label_callback'][0])->{$labelConfig['label_callback'][1]}($row, $label, $this, '', false, $protected, $isVisibleRootTrailPage);
}
elseif (\is_callable($labelConfig['label_callback']))
{
$label = $labelConfig['label_callback']($row, $label, $this, '', false, $protected, $isVisibleRootTrailPage);
}
}

foreach ($labelConfig['label_callback'] as $callback)
elseif ($mode === self::MODE_PARENT)
{
if (\in_array($mode, array(self::MODE_TREE, self::MODE_TREE_EXTENDED)))
if (\is_array($labelConfig['label_callback']))
{
if (\is_array($callback))
{
$label = System::importStatic($callback[0])->{$callback[1]}($row, $label, $this, '', false, $protected, $isVisibleRootTrailPage);
}
elseif (\is_callable($callback))
{
$label = $callback($row, $label, $this, '', false, $protected, $isVisibleRootTrailPage);
}
$label = System::importStatic($labelConfig['label_callback'][0])->{$labelConfig['label_callback'][1]}($row, $label, $this);
}
elseif ($mode === self::MODE_PARENT)
elseif (\is_callable($labelConfig['label_callback']))
{
if (\is_array($callback))
{
$label = System::importStatic($callback[0])->{$callback[1]}($row, $label, $this);
}
elseif (\is_callable($callback))
{
$label = $callback($row, $label, $this);
}
$label = $labelConfig['label_callback']($row, $label, $this);
}
else
}
else
{
if (\is_array($labelConfig['label_callback']))
{
if (\is_array($callback))
{
$label = System::importStatic($callback[0])->{$callback[1]}($row, $label, $this, $args);
}
elseif (\is_callable($callback))
{
$label = $callback($row, $label, $this, $args);
}
$label = System::importStatic($labelConfig['label_callback'][0])->{$labelConfig['label_callback'][1]}($row, $label, $this, $args);
}
elseif (\is_callable($labelConfig['label_callback']))
{
$label = $labelConfig['label_callback']($row, $label, $this, $args);
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions contao/dca/tl_article.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@
(
'fields' => array('title', 'inColumn'),
'format' => '%s <span class="label-info">[%s]</span>',
'label_callback' => array
(
array('tl_article', 'addIcon')
)
'label_callback' => array('tl_article', 'addIcon')
),
'global_operations' => array
(
Expand Down
5 changes: 1 addition & 4 deletions contao/dca/tl_log.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@
(
'fields' => array('tstamp', 'text'),
'format' => '<span class="label-date">[%s]</span> %s',
'label_callback' => array
(
array('tl_log', 'colorize')
)
'label_callback' => array('tl_log', 'colorize')
),
'global_operations' => array
(
Expand Down
5 changes: 1 addition & 4 deletions contao/dca/tl_member.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@
(
'fields' => array('', 'firstname', 'lastname', 'username', 'dateAdded'),
'showColumns' => true,
'label_callback' => array
(
array('tl_member', 'addIcon')
)
'label_callback' => array('tl_member', 'addIcon')
),
'global_operations' => array
(
Expand Down
5 changes: 1 addition & 4 deletions contao/dca/tl_member_group.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@
(
'fields' => array('name'),
'format' => '%s',
'label_callback' => array
(
array('tl_member_group', 'addIcon')
)
'label_callback' => array('tl_member_group', 'addIcon')
),
'global_operations' => array
(
Expand Down
5 changes: 1 addition & 4 deletions contao/dca/tl_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@
),
'label' => array
(
'group_callback' => array
(
array('tl_module', 'getGroupHeader')
)
'group_callback' => array('tl_module', 'getGroupHeader')
),
'global_operations' => array
(
Expand Down
5 changes: 1 addition & 4 deletions contao/dca/tl_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,7 @@
(
'fields' => array('title'),
'format' => '%s',
'label_callback' => array
(
array('tl_page', 'addIcon')
)
'label_callback' => array('tl_page', 'addIcon')
),
'global_operations' => array
(
Expand Down
5 changes: 1 addition & 4 deletions contao/dca/tl_theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@
(
'fields' => array('name'),
'format' => '%s',
'label_callback' => array
(
array('tl_theme', 'addPreviewImage')
)
'label_callback' => array('tl_theme', 'addPreviewImage')
),
'global_operations' => array
(
Expand Down
5 changes: 1 addition & 4 deletions contao/dca/tl_user.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@
(
'fields' => array('', 'name', 'username', 'dateAdded'),
'showColumns' => true,
'label_callback' => array
(
array('tl_user', 'addIcon')
)
'label_callback' => array('tl_user', 'addIcon')
),
'global_operations' => array
(
Expand Down
5 changes: 1 addition & 4 deletions contao/dca/tl_user_group.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@
(
'fields' => array('name'),
'format' => '%s',
'label_callback' => array
(
array('tl_user_group', 'addIcon')
)
'label_callback' => array('tl_user_group', 'addIcon')
),
'global_operations' => array
(
Expand Down
56 changes: 10 additions & 46 deletions contao/drivers/DC_Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -4648,32 +4648,14 @@ protected function parentView()
}
}

if (\is_callable($GLOBALS['TL_DCA'][$table]['list']['sorting']['header_callback'] ?? null))
{
trigger_deprecation('contao/core-bundle', '5.2', 'Using a single callback for "list.sorting.header_callback" instead of an array of callbacks has been deprecated and will no longer work in Contao 6.');
$GLOBALS['TL_DCA'][$table]['list']['sorting']['header_callback'] = array($GLOBALS['TL_DCA'][$table]['list']['sorting']['header_callback']);
}

// Trigger the header_callback (see #3417)
if (\is_array($GLOBALS['TL_DCA'][$table]['list']['sorting']['header_callback'] ?? null))
{
if (\count($GLOBALS['TL_DCA'][$table]['list']['sorting']['header_callback']) === 2 && \is_string($GLOBALS['TL_DCA'][$table]['list']['sorting']['header_callback'][0]) && \is_string($GLOBALS['TL_DCA'][$table]['list']['sorting']['header_callback'][1]))
{
trigger_deprecation('contao/core-bundle', '5.2', 'Using a single callback for "list.sorting.header_callback" instead of an array of callbacks has been deprecated and will no longer work in Contao 6.');
$GLOBALS['TL_DCA'][$table]['list']['sorting']['header_callback'] = array($GLOBALS['TL_DCA'][$table]['list']['sorting']['header_callback']);
}

foreach ($GLOBALS['TL_DCA'][$table]['list']['sorting']['header_callback'] as $callback)
{
if (\is_array($callback))
{
$add = System::importStatic($callback[0])->{$callback[1]}($add, $this);
}
elseif (\is_callable($callback))
{
$add = $callback($add, $this);
}
}
$add = System::importStatic($GLOBALS['TL_DCA'][$table]['list']['sorting']['header_callback'][0])->{$GLOBALS['TL_DCA'][$table]['list']['sorting']['header_callback'][1]}($add, $this);
}
elseif (\is_callable($GLOBALS['TL_DCA'][$table]['list']['sorting']['header_callback'] ?? null))
{
$add = $GLOBALS['TL_DCA'][$table]['list']['sorting']['header_callback']($add, $this);
}

// Output the header data
Expand Down Expand Up @@ -6513,32 +6495,14 @@ protected function formatGroupHeader($field, $value, $mode, $row)
}
}

if (\is_callable($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['group_callback'] ?? null))
{
trigger_deprecation('contao/core-bundle', '5.2', 'Using a single callback for "list.label.group_callback" instead of an array of callbacks has been deprecated and will no longer work in Contao 6.');
$GLOBALS['TL_DCA'][$this->strTable]['list']['label']['group_callback'] = array($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['group_callback']);
}

// Call the group callback ($group, $sortingMode, $firstOrderBy, $row, $this)
if (\is_array($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['group_callback'] ?? null))
{
if (\count($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['group_callback']) === 2 && \is_string($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['group_callback'][0]) && \is_string($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['group_callback'][1]))
{
trigger_deprecation('contao/core-bundle', '5.2', 'Using a single callback for "list.label.group_callback" instead of an array of callbacks has been deprecated and will no longer work in Contao 6.');
$GLOBALS['TL_DCA'][$this->strTable]['list']['label']['group_callback'] = array($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['group_callback']);
}

foreach ($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['group_callback'] as $callback)
{
if (\is_array($callback))
{
$group = System::importStatic($callback[0])->{$callback[1]}($group, $mode, $field, $row, $this);
}
elseif (\is_callable($callback))
{
$group = $callback($group, $mode, $field, $row, $this);
}
}
$group = System::importStatic($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['group_callback'][0])->{$GLOBALS['TL_DCA'][$this->strTable]['list']['label']['group_callback'][1]}($group, $mode, $field, $row, $this);
}
elseif (\is_callable($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['group_callback'] ?? null))
{
$group = $GLOBALS['TL_DCA'][$this->strTable]['list']['label']['group_callback']($group, $mode, $field, $row, $this);
}

return $group;
Expand Down
3 changes: 3 additions & 0 deletions src/EventListener/DataContainerCallbackListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ class DataContainerCallbackListener
'panel_callback',
'paste_button_callback',
'button_callback',
'label_callback',
'header_callback',
'child_record_callback',
'input_field_callback',
'options_callback',
'group_callback',
'url_callback',
'title_tag_callback',
];
Expand Down

0 comments on commit e548fe3

Please sign in to comment.