Add custom parameter fields to Joomla 2.5.x modules and article without core hacking

Joomla is loaded with system overrides that makes it super flexible but it is to know the hooks to manipulate the system that makes it usable.

See Demo At FloridaBadminton.com

The first module in the right column is collapsible and is color split. The module below it has the title linked and is sub-title split with color assigned to the sub. The Photo Highlights in the main column is wrapped in a fieldset element so the legend element serves as the title container. The videos at the bottom uses an image for the title.

If you use the big name frameworks or a super function filled template, they pretty much have added all the plugs in demand, and attempting to include this customization will only cause you headaches. This here thingy is suitable for those who have created a template all by themselves and looking for some enhancements.

This guide assumes you understand Joomla's template override system. You will not break your website attempting this override.

The plugin adds fields globally to each module parameter. It does not literally write anything to the module's coding but uses Joomla's form system to plug in the fields.

What you get is this

cmse-custom-params

and for the article custom params, additional fields are inserted to add article class suffix (really great use) and a text field that can serve numerous valuable purposes.

The new article parameter fields are located under the Article Options tab when adding an article

article-params

 

subtitle

 

splitcolor

 

fieldset

 

imgtitle

 

Let's jump into the plan to make it work within your template

Joomla is loaded with system overrides that makes it super flexible but it is to know the hooks to manipulate the system that makes it usable.

See Demo At FloridaBadminton.com

The first module in the right column is collapsible and is color split. The module below it has the title linked and is sub-title split with color assigned to the sub. The Photo Highlights in the main column is wrapped in a fieldset element so the legend element serves as the title container. The videos at the bottom uses an image for the title.

If you use the big name frameworks or a super function filled template, they pretty much have added all the plugs in demand, and attempting to include this customization will only cause you headaches. This here thingy is suitable for those who have created a template all by themselves and looking for some enhancements.

This guide assumes you understand Joomla's template override system. You will not break your website attempting this override.

The plugin adds fields globally to each module parameter. It does not literally write anything to the module's coding but uses Joomla's form system to plug in the fields.

What you get is this

cmse-custom-params

and for the article custom params, additional fields are inserted to add article class suffix (really great use) and a text field that can serve numerous valuable purposes.

The new article parameter fields are located under the Article Options tab when adding an article

article-params

 

subtitle

 

splitcolor

 

fieldset

 

imgtitle

 

Let's jump into the plan to make it work within your template

the-coding-method

To make this plugin work is a bit more than just installing it. The fields will display immediately after installation but submission will not do jack! Template overrides are needed.

The first 7 parameters occur within the file modules.php. It may already exist in your template so check if there is a directory called html and see if the file exists. Make a copy of the file before editing just so you can restore it if you get it wrong or do not like the results. There is really no way to get it wrong.

Again, this guide assumes you understand Joomla's template override system. You will not break your website attempting this override.

Add this whole block of code at the end of the modules.php file.

 

function modChrome_mag($module, &$params, &$attribs) {

$hlevel				= $params->get('headertag');
$usefieldset		= $params->get('usefieldset');
$titlesize			= $params->get('titlesize');
$titlecolor			= $params->get('titlecolor');
$titlesplit			= $params->get('titlesplit');
$titleimage			= $params->get('titleimage');
$linkmodtitle		= $params->get('linkmodtitle');
$modtitle			= $module->title;
$addcollapse		= $params->get('addcollapse');
$collapsehandle='';
$collapsecontainer='';
$deftitle='';

//accordion classes to be inserted when enabled
	if($addcollapse) {
		$collapsehandle = 'colhandle" style="cursor:pointer';
		$collapsecontainer = 'colcontainer';
	}


//Add a hyperlink to the module title just as done for articles with a difference of adding any URL
	if(!empty($linkmodtitle)) {
		$modtitle = '<a href="'.$linkmodtitle.'">'.$modtitle.'</a>';
	}

	if($titlesplit != 'no' && empty($titleimage)) {
		if(strpos($modtitle, "|")) {
			$subtitle = explode("|", $modtitle);
			if($titlesplit == 'modsubtitle') {
				$subtitle[1] = '<span class="modsubtitle" style="display:block;font-size:'.$titlesize.';color:#'.$titlecolor.';">'.$subtitle[1].'</span>';
			}else
			if($titlesplit == 'colorsplit') {
				$subtitle[1] = '<span class="titlecolor" style="color:#'.$titlecolor.';">'.$subtitle[1].'</span>';
			}
			$modtitle = implode("|", $subtitle);
		}
	}

	$modtitle = str_replace("|", "", $modtitle);

//Add font sizing and color to the title
	if($titlesplit == 'no' && empty($titleimage) && !empty($titlesize)) {$deftitle = 'style="font-size:'.$titlesize.';color:#'.$titlecolor.';" ';}
	if(!empty($titleimage)) {
		if(!empty($linkmodtitle)) {
		$modtitle = '<span style="display:none;">'.$modtitle.'</span><a href="'.$linkmodtitle.'"><img src="'.$titleimage.'" /></a>';
		}else{
		$modtitle = '<span style="display:none;">'.$modtitle.'</span><img src="'.$titleimage.'" />';
		}
	}

//the output
	if (!empty ($module->content)) { ?>
		<<?php if($usefieldset == 1) {echo 'fieldset';}else{echo 'div';} ?> class="m1<?php echo htmlspecialchars($params->get('moduleclass_sfx')); ?>">
		<?php if ($module->showtitle != 0) { ?>
			<?php if($usefieldset == 1) {echo '<legend>';}else{} ?>
				<h<?php echo $hlevel; ?> class="m2 <?php echo $collapsehandle; ?>">
					<span <?php echo $deftitle; ?>><?php echo $modtitle; ?></span>
				</h<?php echo $hlevel; ?>>
			<?php if($usefieldset == 1) {echo '</legend>';}else{} ?>
		<?php } ?>
			<div class="m3 <?php echo $collapsecontainer; ?>"><?php echo $module->content; ?></div>
		</<?php if($usefieldset == 1) {echo 'fieldset';}else{echo 'div';} ?>>
	<?php
	}
}

 

 

Alter the elements and class names as desired. You will then add the modChrome_mag to new positions or change those in use, within your template's index.php. You could also opt to merge the code into your existing modChrome_style.

 

<jdoc:include type="modules" name="topcontent" style="mag" />

Just plan accordingly based on what you want the result to be.

Download the plugin

module-overrides

Like the template position override, the extension overrides are placed in the template's html directory.

For each module that you wish to add Pre-Text and Post-Text output, copy the module's default.php file to the corresponding directory within your template.

Example using mod_footer

Create directory mod_footer inside your default template so the path is yourtemplate/html/mod_footer/default.php

The end result

<?php
/**
 * @package		Joomla.Site
 * @subpackage	mod_footer
 * @copyright	Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

// no direct access
defined('_JEXEC') or die;
?>
<?php if(!is_null($params->get('pretext'))) { ?>
	<div><?php echo $params->get('pretext'); ?></div>
<?php } ?>
<div><?php echo $lineone; ?></div>
<?php if(!is_null($params->get('posttext'))) { ?>
	<div><?php echo $params->get('posttext'); ?></div>
<?php } ?>

Now when the footer module is published you can use the pre and/or post textareas to add content as either plain text or HTML-ized. Follow the similar steps to create overrides per module as needed. Note that not all modules are created equal so some may not follow the construct standard for Joomla and may not include a tmpl directory with a default.php. Those modules cannot be overridden.

adding-article-override

To use the new inserted parameter fields labeled Article Class and Article Lead, you will add some coding to your template. The fields will be located under Article Options tab when adding an article.

First, understanding the purpose and determine if you need it.

The scenario
You have a category loaded with articles and you correctly have a menu item assigned to the category. All the articles in the category display the same as far as colors, font size etc. You could assign a pageclass suffix via the menu item but that will apply to all the articles. Now you want just this one article in that category to display with a green background and the text color in neon yellow. You could do it with some php conditional coding but Oh rass that gets ridiculous. The article_class parameter makes it simple.

 

The Article Lead gives the ability to inject text or HTML at any point you place the hook. This was necessary to avoid improper display in Category Blog view since Joomla's default function will grab the first x amount of text or words of an article to use as intro text. We needed the specially formatted top section of an article not to show in the intro text but be visible in the article full text.

This is how the page displays

article-lead-sample
See it at WebsiteDons.com Packages

Only you can determine if you have use for this function.

 

Putting it all together programmatically

For the article_class you will add the code to your template's index.php

In the php initializer at the top of the file, add the following code

 

if ($app->input->get('option') == "com_content" && $app->input->get('view') == "article") {
	$artid = $app->input->get('id');
	$db	= JFactory::getDBO();
	$query = 'SELECT attribs FROM #__content WHERE id = '.$artid;
	$db->setQuery($query);
	$art = trim($db->loadResult());
	if (preg_match("#['|\"]article_class['|\"]:['|\"](.*?)['|\"]#i", $art, $matches)) {
		$article_class = $matches[1];
	}
}

 

Then in the <body> tag add the hook $article_class alongside other classes that exist. Include a space between existing class.

<body class="<?php if(isset($article_class)) echo $article_class; ?>">

Now whenever an article with a style class is being viewed, its class will be inserted to the body tag and the styling will be as you wish.

 

Now we do stuff to the article override file

In yourtemplate/html/com_content/article/default.php is where you will add the article_lead hook.

If you want to use it as a leader text, add the code to the existing text hook

<?php 
if ( !is_null($params->get('article_lead') ) {
echo $params->get('article_lead'); 
}
//this is the original joomla system article text hook
echo $this->item->text; 
?>

 You can insert the hook anywhere you deem suitable.

Download the Plugin

other-things-to-know

The module fields titled Specific Device Display Controller will not do anything. It is applicable to templates distributed by WebsiteDons.com which are RESS/Device Adaptive designed.

You can remove that function by editing the file in the plugin named modulefields.xml and remove the fields.

Usage

Now that you have made all the coding adaptations. This is how you use the plugin.

When editing a module, the parameter tabs will show a new tab labeled CMSE Custom Parameters. Click the tab to open it.

  • The default header tag is H2
  • URL To Title
    Insert a complete or relative URL to make the module's title a hyperlink to the destination
  • Title Font Size will add inline CSS to the title span tag. This has no effect when using Color Split.
  • Title Color will add inline CSS to color the title text. It will determine the color of the split for word color or subtitle.
  • Title Split
    Word Color Split will allow for styling of word(s) in the title following a vertical bar | . eg "The Great| Module Title" will appear as "The Great Module Title"
    Subtitle Split will allow for breaking the line and showing smaller text for word(s) following a vertical bar | . eg "The Great Module Title| Is What We Need Today" will appear as
    "The Great Module Title
    Is What We Need Today"
  • Title Image allows for the use of an image as the title. The title text will still be visible to searchbots tho hidden to human. Using this will override all but the URL field. Which means you can use an image and hyperlink it.
  • Wrap In Fieldset will use the fieldset element to wrap the content and use the legend element for the title. This option is especially valuable for grouping modules when using {loadposition} or {loadmodule} or even the Modules Anywhere extension.
  • Enable Module Collapse will load the javascript in the head to initialize the accordion function and add class suffix to both the title and the content of the module. For this reason, the title of the module using this function, must be set to show. The module will then hide its content but show the title which is clickable and will reveal the content when clicked.

...and as Andrew Ashmeade would say... "a hit dat!"

For assistance, suggestions and comments, post at The Plugin Page | Download

{jcomments off}

 

Copyright © 2019 CMSEnergizer.com. All Rights Reserved.
This website is powered by the Joomla!©™ 3 Website Framework | File download and article manager component by CMSE Custom Fields | Advanced Module Manager and Modules Anywhere by NoNumber Elements | Website hosting and development by WebsiteDons

CMSEnergizer.com is owned and operated by Emuzement Net Inc, Tampa, Florida USA