[4.0] Cassiopeia - update card mod chrome#30716
[4.0] Cassiopeia - update card mod chrome#30716Scrabble96 wants to merge 20 commits intojoomla:4.0-devfrom
Conversation
1. Move mod-id to module container to display mod-id whether header/title shown or not 2. Remove h4 from $headerTag 3. Remove h3 from render code
1. Move mod-id to module container so that mod-id is shown whether or not header/title is shown 2. Removed 'h4' from $headerTag
This option can be used instead of "style-none" in the index.php to allow modules that generally do not have their header/title shown, e.g. main menu, search, but will add an id to the module - which can be used as anchors - and also include any module class suffix added to the module's setup advanced tab.
|
@Scrabble96 You should change your editor's settings so it shows spaces and tabs, so you can see what kind of white space is used. |
Co-authored-by: Richard Fath <richard67@users.noreply.github.com>
Co-authored-by: Richard Fath <richard67@users.noreply.github.com>
|
Honestly, I don't think we need a new chrome "noTitle". Hiding a title is possible with each module chrome already. There is an option for just that. |
Added correct $headerTag element
Added $headerTag
In that case, I don't see the reason for having any of the modules as Perhaps all the modules currently given |
That's exactly the purpose of "none". To have only the module output without any chrome around it. |
Perhaps 'default' should be renamed as 'unstyled'. |
Nah, unstyled is wrong as well, as there certainly are styles applied. Actually "default" applies a "card" styling. And I don't even see the difference to "cardGrey". |
Removed second content check
"cardGrey" has a light grey background in the class "card-header". "card-header" is assigned to the default.php as well, but doesn't seem to be applied. I can't work out why. I can't see any other differences.
|
|
Ok. What's wrong with my code this time? |
@Scrabble96 You can check that yourself. At the bottom of the PR where the tests are shown, use the "Details" link at the right side or a failed test. In this case drone failed. The "Details" link brings you to a page where on the left hand side is a list of test steps, failed ones in red. In your case now it is "PHPCS", which means PHP code style. Click this and you get on the right hand side the details on this page: https://ci.joomla.org/joomla/joomla-cms/35590/1/8. You will see that the problem is that you use spaces instead of tabs to indent certain lines. So please follow my advise from above, set up your editor so you can see tabs and spaces and so can distinguish them. And in addition switch off any automatic indent or formatting in your editor (or IDE) settings, or adjust them in a way so that they meet the code style standards documented e.g. here for PHP: https://developer.joomla.org/coding-standards/php-code.html. |
Added aria-labelledby back in for module with title and corrected and aria-labelledby to aria-label for no-title modules
Edit: if I use tabs and specify the number of spaces that the tab uses, in which case, is it 4? On looking at the original code, it looks like it. Thank you. |
@Scrabble96 If the code style says you have to use tabs then you have to use tabs. 1 tab means one level of indent. 4 spaces are not the same as 1 tab, it only can be made that it looks the same by editor settings. The drone PHPCS log for which I have pasted the link https://ci.joomla.org/joomla/joomla-cms/35590/1/8 and of which I have explained you how to find it clearly tells the line numbers where tabs have to be used. |
Added aria-labelledby back in for module with title and corrected and aria-labelledby to aria-label for no-title modules Tabs instead of spaces
Added aria-labelledby back in for module with title and corrected and aria-labelledby to aria-label for no-title modules Corrected spaces to tabs
|
PHPCS is fine now. Thanks @Scrabble96 . |
Thank you. But I'm confused as to why cardGrey has passed checks but default has not. The ONLY difference in the code is line 25 - the class 'card-grey' does not appear in default.php |
@Llewellynvdm |
|
Shall I change and submit the new code? If so, perhaps the #id should be on the module container, regardless of whether the title is displayed or not. In which case, how should I best handle the ‘aria-label’ and ‘aria-labelledby’ aspects? Do we need both? |
I see no way how to do this. ymmv |
|
If you have the same template position multiple times, or manually load a module multiple times, then you get duplicate IDs. |
Why would you do that?
How? By using a pseudo 'before' class? |
|
I have modified the chrome (locally, only) to include the module position in the id and it works. But this is based on the assumption that module positions are only used once. I'll post it here if anyone is interested. [I do, however, get this message on Firefox: "Layout was forced before the page was fully loaded. If stylesheets are not yet loaded this may cause a flash of unstyled content." but not on Chrome or Edge. ] Edit: I refreshed the .htaccess file and this seems to have cleared the problem. |
|
See comment from Harald why a position may be present more than once. |
|
Funny, I got a link to this document today by a customer: https://www.w3.org/TR/WCAG20-TECHS/H93.html IDs have to be unique. |
But you can't use it for URL anchors which was one of the two reasons I wanted to add an ID to all modules. |
|
Technically it should be possible to inject the file and line position of the into the module attributes and generate a unique id per module and position. That would invalidate our module caching if it's loaded twice on the same page. That can be solved in 2 ways.
The relevant starting point for a PR is in libraries/src/Document/HtmlDocument.php:849 |
|
Probably the simplest approach is to just create your own chrome for your own installation where you need the anchor. There you can make sure that module with that chrome is only showing once per page. For a module chrome shipped with the CMS we just can't be sure that the ID will be unique. By the way, a PR which tried to achieve a similar thing with a different approach was #12473 |
For those who would like it, I am happy to share my chrome code which shows both the module position and the module id, but, as @Bakual says, obviously taking into account that any id should be shown only once per page: <?php
/**
* @package Joomla.Site
* @subpackage Templates.cassiopeia
*
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
use Joomla\Utilities\ArrayHelper;
$module = $displayData['module'];
$params = $displayData['params'];
$attribs = $displayData['attribs'];
if ($module->content === null || $module->content === '')
{
return;
}
$moduleTag = $params->get('module_tag', 'div');
$modId = $module->id;
$modPos = $module->position;
$moduleAttribs = [];
$moduleAttribs['id'] = $modPos . '-' . $modId;
$moduleAttribs['class'] = $module->position . ' card ' . htmlspecialchars($params->get('moduleclass_sfx'), ENT_QUOTES, 'UTF-8');
$headerTag = htmlspecialchars($params->get('header_tag', 'h4'), ENT_QUOTES, 'UTF-8');
$headerClass = 'card-header ' . htmlspecialchars($params->get('header_class', ''), ENT_QUOTES, 'UTF-8');
$headerAttribs = [];
$headerAttribs['class'] = $headerClass;
if ($module->showtitle) :
else:
$moduleAttribs['aria-label'] = $module->title;
endif;
$header = '<' . $headerTag . ' ' . ArrayHelper::toString($headerAttribs) . '>' . $module->title . '</' . $headerTag . '>';
?>
<<?php echo $moduleTag; ?> <?php echo ArrayHelper::toString($moduleAttribs); ?>>
<?php if ($module->showtitle && $headerClass !== 'card-title') : ?>
<?php echo $header; ?>
<?php endif; ?>
<div class="card-body">
<?php echo $module->content; ?>
</div>
</<?php echo $moduleTag; ?>>The html looks like this with title: And like this without a title:
As pointed out earlier, the current 'card' chrome includes a module ID, but only if the title is shown.
I hadn't spotted this as it isn't J4. EDIT by hleithner: updated the code highlighting |
|
Tested successfully on localhost |
|
@HLeithner @Bakual @infograf768 What shall we do with this one? It has 2 good tests, but these seems to be some unresolved discussion? Shall I set discussion status in the issue tracker? |
|
I have tested this item ✅ successfully on 64bde14 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/30716. |
|
#30716 (comment) Option 1 is the way to go. |
|
@richard67 you got the answer a week ago |
|
@Gostn We don't need trolls here. |
true |
@Gostn this PR was effectively put on hold due to the use of IDs in the chrome which would create duplicate IDs if the same module was used twice on the page, which is not allowed in good website page setup. There was a suggestion to add the 'discussion' tag to this PR, but that hasn't happened. I don't have the authority to do that. My original reason for opening this PR was two-fold: that the ID could be used for in-page anchors and that the ID would be shown whether the title was shown or not. Due to the problem with duplicate IDs this PR doesn't seem viable as it stands. Frustratingly, before HTML5 the name attribute could be used in for anchors in links but it has now been deprecated in favour of the use of IDs, which brings us back to square one. I wonder when they (whoever 'they' are) deprecated its use whether they considered the possibility of duplicate IDs on a page? |
|
@Scrabble96 thanks for your friendly information. |
|
@Scrabble96 This PR of your seems to have a merge conflict and cannot be merged into Joomla. I have a suggestion. joomla-cms/templates/cassiopeia/html/layouts/chromes/card.php Lines 24 to 25 in 3b82bf1 To make sure a module always has an Two prevent duplicate ID's we have to adjust a second part of this file too: joomla-cms/templates/cassiopeia/html/layouts/chromes/card.php Lines 36 to 45 in 3b82bf1 To prevent duplicate ID's we have to adjust the name of the id for the header into: With these two changes based on the current implementation of template/cassiopeia/html/layouts/chromes/card.php the PR is good to go I think. |
|
As already mentioned if the module is cached (and if I'm not wrong) the id is still duplicated. |
@hans2103 I'll have a look in the next few days but, as @HLeithner says, there is a problem with cached modules so I don't think this is going to work. |
|
I'm going to close this PR due to the cache conflict. |


Pull Request for Issue #30678 (second attempt) .
Summary of Changes
Updated html > layouts > chromes > card.php (renamed from 'default', see #30729) to display mod-id as the containing element's (address, div, section, etc)
#idinstead of just in the title so that the id displays whether the title is shown or not.Testing Instructions
Result: See section "Actual result BEFORE applying this Pull Request" below.
See section "Actual result AFTER applying this Pull Request" below.
Actual result BEFORE applying this Pull Request
module
#idonly appears if title is shownExpected result AFTER applying this Pull Request
#idalways applied to Cassiopeia modules using Cassiopeia 'card' chromeNo visible difference on front end for website visitors
Documentation Changes Required
Note to highlight change