Pm caption templatization - #5563
Conversation
241b734 to
4f50dac
Compare
There was a problem hiding this comment.
@rica-carv Getting the PM captions out of the four hardcoded LAN_PM call sites and into the template is the right move, and vartrue($PM_TEMPLATE['caption'], LAN_PM) is a sensible fallback shape. One change in here is a backwards-compatibility break, though, and it isn't flagged.
$PM_TEMPLATE['send'] changes from a string to an array
-$PM_TEMPLATE['send'] = "<div id='pm-send-pm'>
+$PM_TEMPLATE['send']['caption'] = "{LAN=LAN_PM}";
+$PM_TEMPLATE['send']['main'] = "<div id='pm-send-pm'>with the read side updated to match:
$PM_SEND_PM = e107::getTemplate('pm', 'pm', 'send')['main'];Any theme that overrides $PM_TEMPLATE['send'] as a string, which is the only shape it has ever had (pm_template.php#L90), now has ['main'] read off a string. On PHP 8 that's a TypeError: Cannot access offset of type string on string, so the send-PM page fatals rather than degrading.
The other three keys (inbox, outbox, blocked) are already arrays, so adding caption to them is free. send is the odd one out. Either:
- keep
senda string and hold its caption elsewhere, or - normalise it and handle both shapes on read:
$sendTmpl = e107::getTemplate('pm', 'pm', 'send');
$PM_SEND_PM = is_array($sendTmpl) ? varset($sendTmpl['main']) : $sendTmpl;The second is the better long-term answer, but it needs to be a deliberate, documented change with the shim in place, not a silent one.
pm_caption('') on the show page
$ns->tablerender($this->pm_caption($comeFrom), ...);$comeFrom is 'inbox', 'outbox' or ''. A default parameter value only applies when the argument is missing, not when it's empty, so the third case calls getTemplate('pm', 'pm', ''). vartrue() catches the fallout and you get LAN_PM, so nothing breaks, but the = 'inbox' default is misleading about what actually happens. $this->pm_caption($comeFrom ?: 'inbox') says what you mean.
Smaller things
- The
pm_caption()body is indented at column 0 while the rest of the class is at one tab, and the interior mixes tabs and spaces. It reads as pasted in. $caption = $pm->pm_caption('inbox');;and theoutboxline below it both end with a double semicolon.{LAN=LAN_PM}does resolve, via theelseif(defined($lan))fallback inlan.php#L17-L20, so it isn't a bug. It's just not how core writes it: the shortcode prependsLAN_itself, so everywhere else says{LAN=PM}. Worth matching so nobody copies the doubled form into a new template.pm_caption()is declared without a visibility keyword. The methods around it usefunctiontoo, so it's consistent with the file, butpublic functionwould be better in new code.
Sort the send key and this is a good change.
Motivation and Context
Allow full caption templatization im PM pages...
Description
Changed hardcoded lans inside PHP to template coded lan's, allowing full tempatization of captions is PM pages
How Has This Been Tested?
Tested with latest e107 from github
Types of Changes
Checklist