antonydoyle
6/28/2013 - 8:44 PM

Using plugins and mods for CCK in Joomla 3

Using plugins and mods for CCK in Joomla 3

I'm trying to use the Joomla core as much as possible. Now to say that I'm using ONLY core would be untrue, since technically I'm creating and installing some plugins to accomplish this, but they certainly aren't 'heavy duty' components like K2, seblod, or some of the other Joomla CCKs out there. 

Site I just built using this concept
https://github.com/drmmr763/sofi

## write some plugins
https://github.com/drmmr763/sofi/tree/master/plugins/content/sofimap

This sofimap plugin loads an XML file into the backend of ```com content``` that lets me store extra field data in my own table. So the process here is to use all the plugin events for ```com content``` to load the form, load form data, save form data, delete form data, and even display saved data in the front end. 

## display your extra field content
https://github.com/drmmr763/sofi/tree/master/modules/mod_sofimap

The site I just built uses an entirely module based layout. There isn't a single 'component' being loaded on the front end! My template doens't even have the <jdoc:include type="component" in it anywhere. Now clearly this is a unique use-case. In this case to display my extra fields I use this getItems method:

https://github.com/drmmr763/sofi/blob/master/modules/mod_sofimap/helper.php#L36

which automatically loads all the extra field data from my plugin code! The attributes are available in the object as encoded JSON parameters. I access them in my view like this:

 ```<?php foreach ($list as $item) :?>
       <?php $attributes = json_decode($item->attribs); ?>

    <div style="position: absolute; top:<?php echo $attributes->map_top; ?>px; left: <?php echo $attributes->map_left ?>px;">
        <a href="javascript::void()"
           class="hasPopover"
           data-toggle="popover"
           title='<?php echo $item->title; ?>'
           data-content='<?php echo $item->introtext; ?><img src="<?php echo $attributes->map_logo; ?>"/>'
           data-html="true">
            <img src="<?php echo $attributes->map_icon; ?>" />
        </a>
    </div>
    <?php endforeach; ?>
</div>```

https://github.com/drmmr763/sofi/blob/master/modules/mod_sofimap/tmpl/default.php#L6

Now if you were using com content as a component on the front end, you would need to do template overrides to do this, but the process would be very much the same. Your plugin should load the extra field data into the object making the field data available to the view, and then you just print it out and format as you wish!

You can get more complex with this as needed. You'll notice this plugin approach applies to all categories of content, with some tweaks to the plugin code you could add a parameter for assigning to specific categories that owuld allow you to have different categories have different content types. I'm sure one day soon if I keep going down this path I'll end up doing that as well. I've also created 'shell components' that load content in a completely custom manner, this starts to get further away from using com content alone, but it's cool nonetheless!