Showing posts with label component. Show all posts
Showing posts with label component. Show all posts

Thursday, July 26, 2012

HTML is stripped in Joomla component configuration / parameters filter

If you are looking to add HTML anywhere in Joomla and 'text filtering' option in 'global configuration' is failing then here is what you need to do

You need to add a filter='safehtml' in your field tag be it your component field or parameter e.g.

<field menu="hide" name="sharethisbtncode" type="textarea"  filter="SAFEHTML" label="Sharethis Buttons Code" description="HTML buttons code of the buttons needed to be displayed" />

Without it Joomla will use the default and strip HTML.

Also know that it will only work for simple HTML like in this example buttons code, if you are looking for including something like javascript like header of analytics or some other you will need to use filter="RAW"

Following is the list of all the filter options:


case 'RULES': // Used for permissions etc
case 'UNSET': // Does nothing.
case 'RAW': // No Filter.
case 'SAFEHTML': // Filter safe HTML.
case 'SERVER_UTC': // Convert a date to UTC based on the server timezone offset.
case 'USER_UTC': // Convert a date to UTC based on the user timezone offset.
default: // Check for a custom callback filter that you can write


For more details refer to:
http://docs.joomla.org/API16:JForm/filter

Tuesday, July 3, 2012

[Solution] You are not permitted to use that link to directly access that page Joomla 2.5 Error

If you are having the error "You are not permitted to use that link to directly access that page" on clicking on 'cancel' button in joomla admin inside a component then try the following:


Try selecting a row with a check box and then click edit, once the page loads click cancels, if this doesn't give the error and adding a look to title to edit, something like 


index.php?option=com_myschool&view=student&layout=edit&id=1


and clicking on this and then pressing cancel gives you the error then the following is the quick and easy solution, replace the layout edit with task=subcontrollername.edit and leave rest the same, e.g.

index.php?option=com_myschool&view=student&task=student.edit&id=1
or this also works
index.php?option=com_myschool&task=student.edit&id=1

Note: You will be in a view with plural like views/students/tmpl/default.php but you have to use the subcontroller name of the single one i.e. student.

Wednesday, June 20, 2012

Joomla 2.5 extend jgrid.published column in custom component


Ever wanted to have a column/field like published in articles for your own component? Well here is how you can make one.
If you go to com_content and see how it is done there you will see that for published it uses the following line of code in views/articles/tmpl/default.php

<?php echo JHtml::_('jgrid.published', $item->state, $i, 'articles.', $canChange, 'cb', $item->publish_up, $item->publish_down); ?>


Simplying it you can use it as

<?php echo JHtml::_('jgrid.published', $item->state, $i, 'articles.'); ?>

Which is

<?php echo JHtml::_('jgrid.published', $item->yourFieldName, $i, 'classPrefix.'); ?>

If you just put this one line you will be able to see that your Boolean field will start showing correctly, and especially if you field name is ‘published’ then you are done and you can click on it to toggle between publish and un publish, however if your field name is something other than published e.g. approved or available then you have some work to do.
First you will need to create a new class in com_componentName/helpers/html/className.php
This will be a JFieldClassName class having code like this
<?php
defined('_JEXEC') or die;
abstract class JHtmlClassName
{
                static function approved($value = 0, $i)
                {
                                $states = array(0=> array('disabled.png','tableName.approved','’,'Toggle to approve'),
                    1=> array('tick.png',    'tableName.unapproved', ',        'Toggle to unapprove'), );
                                $state   = JArrayHelper::getValue($states, (int) $value, $states[1]);
                                $html    = JHtml::_('image', 'admin/'.$state[0], JText::_($state[2]), NULL, true);                                                  $html    = '<a href="#" onclick="return listItemTask(\'cb'.$i.'\',\''.$state[1].'\')" title="'.JText::_($state[3]).'">'. $html.'</a>';
                }
                return $html;
                }
} ?>
Now to call this you will have to first register it for both approved/unapproved in controller’s contruct
com_componentName/controllers/classNames.php
                public function __construct($config = array())
                {
                                parent::__construct($config);
                                $this->registerTask('unapproved', 'approved');
                }
Followed by the function which will call the model to update the status:
        function approved()
        {
                                $ids        = JRequest::getVar('cid', array(), '', 'array');
                                $values = array('approved' => 1, 'unapproved' => 0);
                                $task     = $this->getTask();
                                $value   = JArrayHelper::getValue($values, $task, 0, 'int');
                                $model = $this->getModel();
                                if (!$model->approved($ids, $value)) {
                                                                JError::raiseWarning(500, $model->getError());
                                }
                                $this->setRedirect(url to get you back to the same page);
        }
Now its all up are ready and you can just create a function in your respective model which takes the value (which will be 0 or 1) and id and update the status , and finally you can use it by writing the following line in default.php
<?php echo JHtml::_('className.approved', $item->approved, $i, 'tableName.'); ?>
You will need to include the html helper file you created first by putting the following like at the top of default.php
JHtml::addIncludePath(JPATH_COMPONENT.'/helpers/html');