User tests: Successful: Unsuccessful:
Pull Request for Issue #33396
Fix calling startTabSet twice causes PHP Error
Run startTabSet twice with the same input params
\Joomla\CMS\HTML\Helpers\Bootstrap::startTabSet('asd', []);
\Joomla\CMS\HTML\Helpers\Bootstrap::startTabSet('asd', []);
One set of output:
<ul class="joomla-tabs nav nav-tabs" id="asdTabs" role="tablist"></ul>
<div class="tab-content" id="asdContent">
none
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
Labels |
Added:
?
|
@PhilETaylor there's some background here: #32146 and #32357
In short, although we tried to not break the B/C for tabs and modals factories we assumed that the old code was sufficient enough and there weren't any further improvements. That said I think devs should make sure that their element ids are totally unique, eg use a pattern like company-product-specifier
which should guarantee uniqueness. I don't think that the core should go into this rabbit hole of ensuring the uniqueness of ids, it's not the core's responsibility it's down to the dev understanding what they're instructing the framework to do...
. I don't think that the core should go into this rabbit hole of ensuring the uniqueness of ids, it's not the core's responsibility
But ... Im not happy leaving a PHP error, we would not do that anywhere else in Joomla
Can we throw a nice exception instead if someone uses the same id twice? or just ignore it and carry on silently outputting crap HTML that then its up to the developer to debug and fix?
Status | Pending | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2021-04-29 11:12:25 |
Closed_By | ⇒ | PhilETaylor |
Can we throw a nice exception instead if someone uses the same id twice?
That would be ok but manipulating the id to "fix" it magically is a route that the core should not follow.
Awesome thanks. I'll add this back to my todo pile :)
Im not convinced this is the full correct fix. Sure it fixes the PHP issue which was reported, but the developer (DX) experience is bad.
The root cause is a developer trying to use the same
$selector
for two different Tab Sets. Which is not allowed.Paging @dgrammatiko who might have more ideas. We could append to the
$selector
an integer if its already been used before.You also get funky results if you reuse the same id's as the second param to
addTab
, again we could append an integer to that too.The problem is, is if a developer reuses the same selector more than once, we dont really want this PHP error, but equally we dont want an awkward missing tabs...
Before applying this PR with the code below, you would just get a PHP error.
After applying this PR with this code...
would give this with this PR applied:
Screen.Recording.2021-04-28.at.09.51.19.pm.mp4