? Pending

User tests: Successful: Unsuccessful:

avatar PhilETaylor
PhilETaylor
28 Apr 2021

Pull Request for Issue #33396

Summary of Changes

Fix calling startTabSet twice causes PHP Error

Testing Instructions

Run startTabSet twice with the same input params

\Joomla\CMS\HTML\Helpers\Bootstrap::startTabSet('asd', []);
\Joomla\CMS\HTML\Helpers\Bootstrap::startTabSet('asd', []);

Actual result BEFORE applying this Pull Request

Screenshot 2021-04-28 at 21 22 35

Expected result AFTER applying this Pull Request

One set of output:

<ul class="joomla-tabs nav nav-tabs" id="asdTabs" role="tablist"></ul>
<div class="tab-content" id="asdContent">

Documentation Changes Required

none

avatar PhilETaylor PhilETaylor - open - 28 Apr 2021
avatar PhilETaylor PhilETaylor - change - 28 Apr 2021
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 28 Apr 2021
Category Libraries
avatar PhilETaylor PhilETaylor - change - 28 Apr 2021
The description was changed
avatar PhilETaylor PhilETaylor - edited - 28 Apr 2021
avatar PhilETaylor PhilETaylor - change - 28 Apr 2021
Labels Added: ?
avatar PhilETaylor PhilETaylor - change - 28 Apr 2021
The description was changed
avatar PhilETaylor PhilETaylor - edited - 28 Apr 2021
avatar PhilETaylor
PhilETaylor - comment - 28 Apr 2021

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...

echo \Joomla\CMS\HTML\Helpers\Bootstrap::startTabSet('asd', []);
echo \Joomla\CMS\HTML\Helpers\Bootstrap::addTab('asd', 'myid','mytitle');
echo 'aa aa aa aa';
echo \Joomla\CMS\HTML\Helpers\Bootstrap::endTab();
echo \Joomla\CMS\HTML\Helpers\Bootstrap::addTab('asd', 'myid2','mytitle2');
echo 'bb bb bb bb';
echo \Joomla\CMS\HTML\Helpers\Bootstrap::endTab();
echo \Joomla\CMS\HTML\Helpers\Bootstrap::endTabSet();


echo \Joomla\CMS\HTML\Helpers\Bootstrap::startTabSet('asd', []);
echo \Joomla\CMS\HTML\Helpers\Bootstrap::addTab('asd', 'myid11','mytitle');
echo 'aaa aaa aaa aaa';
echo \Joomla\CMS\HTML\Helpers\Bootstrap::endTab();
echo \Joomla\CMS\HTML\Helpers\Bootstrap::addTab('asd', 'myid22','mytitle2');
echo 'bbb bbb bbb bbb';
echo \Joomla\CMS\HTML\Helpers\Bootstrap::endTab();
echo \Joomla\CMS\HTML\Helpers\Bootstrap::endTabSet();

would give this with this PR applied:

Screen.Recording.2021-04-28.at.09.51.19.pm.mp4
avatar dgrammatiko
dgrammatiko - comment - 29 Apr 2021

@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...

avatar PhilETaylor
PhilETaylor - comment - 29 Apr 2021

. 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?

avatar PhilETaylor PhilETaylor - change - 29 Apr 2021
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2021-04-29 11:12:25
Closed_By PhilETaylor
avatar PhilETaylor PhilETaylor - close - 29 Apr 2021
avatar dgrammatiko
dgrammatiko - comment - 29 Apr 2021

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.

avatar PhilETaylor
PhilETaylor - comment - 29 Apr 2021

Awesome thanks. I'll add this back to my todo pile :)

avatar PhilETaylor
PhilETaylor - comment - 29 Apr 2021

Replaced with #33409

Add a Comment

Login with GitHub to post a comment