Add Module ID Parameter to Advanced Options in module and modules#12473
Add Module ID Parameter to Advanced Options in module and modules#12473coolcat-creations wants to merge 3 commits intojoomla:stagingfrom coolcat-creations:add-id-mod_custom
Conversation
Add Language String Add Module ID output for custom and newsflash module
|
Can we use something other than the term module id. It's going to get On 19 Oct 2016 1:54 p.m., "coolcat-creations" notifications@github.com
|
|
@coolcat-creations although this might be somehow useful for frontend devs, I'll say is not needed, because you already have control over the class. So instead of IMHO Joomla should go away from id's (it's an extra tag if you already have a tag class, which is true most of the times) |
|
@DGT41 Thanks for your Feedback - For my Argument with scripting i absolutely agree, but for OnePager and "Scrolling" it´s still useful and often used these days. I understand and agree on removing params as much as possible but i think it´s good to add more power for Overrides and Chrome. |
|
@brianteeman Thank you, that´s right. I changed to Module CSS ID ? |
|
The place where you added the field contains parameter for the module chromes, which are a template thing. To be consistent (and make sense) this would have to be supported by the template module chromes if the field is declared in this spot. Since you do the actual support of the parameter in the module itself, the parameter should be defined in the module XML instead. This would also reduce confusion for the user when he wants to use that new parameter with a (3rd party) module that doesn't support it. |
That won't work if you have the same module appearing twice in a page |
For that it doesn't matter where the field is declared. |
|
As @Bakual mentioned there is other place where you can do that, This is not as flexible as that PR but can work for all modules by one change. <<?php echo $moduleTag; ?> class="moduletable<?php echo htmlspecialchars($params->get('moduleclass_sfx'), ENT_COMPAT, 'UTF-8') . $moduleClass; ?>">to: <<?php echo $moduleTag; ?> id="mod_<?php echo $module->position, '_', $module->id;?>" class="moduletable<?php echo htmlspecialchars($params->get('moduleclass_sfx'), ENT_COMPAT, 'UTF-8') . $moduleClass; ?>"> |
|
I think the best way for this is to patch the module helper to either create on the fly the Id or create a unique class, something like |
|
@DGT41 nice suggestion. i think position-id might be even enough ? What do you all think? |
|
Just patch and the |
Sounds good. Offers a solution for one page web sites without the need of any extra fields. |
|
And here is some code: $moduleId = $params->get('moduleclass_sfx') . ' ' . preg_replace('/[^A-Z0-9_\.-]/i', '', $module->position). '-' . $module->id;and https://github.com/joomla/joomla-cms/blob/staging/templates/protostar/html/modules.php#L47 echo '<' . $moduleTag . ' class="well ' . htmlspecialchars($params->get('moduleclass_sfx'), ENT_COMPAT, 'UTF-8') . $moduleClass . '" id="' . $moduleId . '">';@coolcat-creations is that any good? |
|
When you're going to change the module chromes to generate a CSS ID, you could as well add that parameter to the XML like done in this PR and use that value instead of calculating the id. Imho automatically creating some CSS ID isn't the best idea. |
|
@Bakual as I wrote before the static value will not work in many cases where a module is populated more than once in a page. So the id needs to be dynamic. Think of a module that brings articles by category, someone could reuse that module in the same page to have different sections with different categories. In such case the static id will be wrong as all the instances will point to the same id. Honestly this is down to the front-end devs and doesn't even need to be part of the core (who uses protostar anyways?) |
That's obvious and when it's an optional parameter it is in the responsibility of the administrator to use it right.
Then it is a new instance of the module with different parameters and thus also a different ID (if needed). |
|
Some modules already have a unique Id field to address the issue of On 19 Oct 2016 6:32 p.m., "Thomas Hunziker" notifications@github.com
|
|
The problem is indeed that for example the menu module has it´s own id, so when i add this into Chrome i have two ids for one module. Nice solution would be maybe to have also custom fields available for modules so everyone can build the additional parameter they want to have. |
|
@coolcat-creations so with the following code: function modChrome_id($module, &$params, &$attribs)
{
$moduleTag = $params->get('module_tag', 'div');
$bootstrapSize = (int) $params->get('bootstrap_size', 0);
$moduleClass = $bootstrapSize != 0 ? ' span' . $bootstrapSize : '';
$headerTag = htmlspecialchars($params->get('header_tag', 'h3'), ENT_COMPAT, 'UTF-8');
$headerClass = htmlspecialchars($params->get('header_class', 'page-header'), ENT_COMPAT, 'UTF-8');
$moduleId = $params->get('moduleclass_sfx') . ' ' . preg_replace('/[^A-Z0-9_\.-]/i', '', $module->position). '-' . $module->id;
if ($module->content)
{
echo '<' . $moduleTag . ' class="well ' . htmlspecialchars($params->get('moduleclass_sfx'), ENT_COMPAT, 'UTF-8') . $moduleClass . '" id="' . $moduleId . '">';
if ($module->showtitle)
{
echo '<' . $headerTag . ' class="' . $headerClass . '">' . $module->title . '</' . $headerTag . '>';
}
echo $module->content;
echo '</' . $moduleTag . '>';
}
}in The only problem in this case is only if you don't want the module to be encapsulated in a div, then the problem with the conflicting ids needs to be solved (pre_replace ??), but is also doable. Hope it helps |
I always thought it would be nice if templates could define some module chrome parameters. That would allow a lot of nice stuff for the templates. |
|
And here is the other one that will not encapsulate the module in a div: function modChrome_id_raw($module, &$params, &$attribs)
{
$moduleId = $params->get('moduleclass_sfx') . ' ' . preg_replace('/[^A-Z0-9_\.-]/i', '', $module->position). '-' . $module->id;
echo preg_replace("#id=\".+\"#", $moduleId, $module->content);
}This one is not tested, but it should work 😛 EDIT: it needs an if statement, if id exists the replace it else append after the first space |
|
We already display all the chromes for a module in the advanced tab On 24 October 2016 at 14:22, Thomas Hunziker notifications@github.com
Brian Teeman |
|
@brianteeman - this was not related to this dropdown field ;) I meant to add (more) custom parameters. |
|
What is the status of this PR @coolcat-creations This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12473. |
|
i understood that it´s out of discussion having a field parameter for the id and that the user could add a chrome by himself. If i misunderstood that i´m happy to discuss further or changing the PR. |
|
@coolcat-creations Is this PR still valid now that we are getting custom fields for modules? This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12473. |
|
@roland-d thats not confirmed yet |
|
@brianteeman Ok thanks. I see there is a lot of conflicts as well that need to be resolved before we can test this. |
|
I agree that custom fields will make this redundant so Its probably best to wait to hear on a decision about the custom fields |
|
Referencing #17490 (Custom Fields for Modules) |
|
@coolcat-creations can this be closed in favor of #17490? |
|
yes, ok @franz-wohlkoenig |


Summary of Changes
This PR adds a Module ID Parameter in the Advanced Tab from Modules.
This param is very useful to add IDs to module-containers in case of OnePagers/anchors or as target of a script. It improves Design-abilities so you don´t have to handle IDs inside the module-content or create overrides/Chromes for each ID.
Testing Instructions
Define Module ID in mod_custom or mod_newsflash and see if it works
Documentation Changes Required