API16

API16:JToolBar/loadButtonType

From Joomla! Documentation

Revision as of 02:13, 25 March 2017 by JoomlaWikiBot (talk | contribs) (preparing for archive only)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Description

Loads a button type.



Syntax

loadButtonType($type, $new=false)
Parameter Name Default Value Description
$type buttonType
$new false

Returns

object

Defined in

libraries/joomla/html/toolbar.php

Importing

jimport( 'joomla.html.toolbar' );

Source Body

public function loadButtonType($type, $new = false)
{
        $signature = md5($type);
        if (isset ($this->_buttons[$signature]) && $new === false) {
                return $this->_buttons[$signature];
        }

        if (!class_exists('JButton'))
        {
                JError::raiseWarning('SOME_ERROR_CODE', 'Could not load button base class.');
                return false;
        }

        $buttonClass = 'JButton'.$type;
        if (!class_exists($buttonClass))
        {
                if (isset ($this->_buttonPath)) {
                        $dirs = $this->_buttonPath;
                } else {
                        $dirs = array ();
                }

                $file = JFilterInput::getInstance()->clean(str_replace('_', DS, strtolower($type)).'.php', 'path');

                jimport('joomla.filesystem.path');
                if ($buttonFile = JPath::find($dirs, $file)) {
                        include_once $buttonFile;
                } else {
                        JError::raiseWarning('SOME_ERROR_CODE', "Could not load module $buttonClass ($buttonFile).");
                        return false;
                }
        }

        if (!class_exists($buttonClass))
        {
                //return        JError::raiseError('SOME_ERROR_CODE', "Module file $buttonFile does not contain class $buttonClass.");
                return false;
        }
        $this->_buttons[$signature] = new $buttonClass($this);

        return $this->_buttons[$signature];
}



Examples

Code Examples