Création d'une barre d'outils pour votre composant.

From Joomla! Documentation

This page is a translated version of the page Creating a toolbar for your component and the translation is 100% complete.
Other languages:
Deutsch • ‎English • ‎Nederlands • ‎español • ‎français
Joomla! 
3.x

Note : ceci s'applique lors de l'utilisation d'une structure MVC.

Par défaut, la barre d'outils Joomla! propose les boutons Supprimer, Modifier, Nouveau, Publier, Dépublier et Paramètres. Pour les utiliser dans votre composant, vous devez écrire le code ci-dessous dans le view.html.php de votre fichier de vue (en dessous de votre fonction d'affichage).

      JToolBarHelper::title(string $title, string $icon);
      JToolBarHelper::deleteList(string  $msg, string  $task, string  $alt); // Will call the task/function $task in your controller
      JToolBarHelper::editList(string  $task, string  $alt); // Will call the task/function $task in your controller
      JToolBarHelper::addNew(string $task, string $alt, boolean  $check); // Will call the task/function $task in your controller
      JToolBarHelper::publish(string $task, string $alt, boolean $check); // Will call the task/function $task in your controller
      JToolBarHelper::unpublish(string $task, string $alt, boolean $check); // Will call the task/function $task in your controller
      JToolBarHelper::preferences(string $component, integer $height, integer $width, string $alt, string $path);
  • string $title    The title.
  • string $msg    Postscript for the 'are you sure' message.
  • string $task    An override for the task: 'controller.function'.
  • string $alt    An override for the alt text.
  • boolean $check    True if required to check that a standard list item is checked.
  • string $component    The name of the component, eg, com_content.

Ainsi, votre code devrait ressembler à ceci :

 class HelloViewHellos extends JView
 {
   function display($tpl = null) {
      JToolBarHelper::title( 'Hello Component', 'generic.png' );
      JToolBarHelper::deleteList('hellos.delete');
      JToolBarHelper::editList('hellos.edit');
      JToolBarHelper::addNew('hellos.add');
      JToolBarHelper::publish();
      JToolBarHelper::unpublish();
      JToolBarHelper::preferences('com_hello', '500');

Un exemple de création d'un bouton personnalisé dans la liste des dossiers de votre composant Joomla 3.x peut être : administrator/views/hellos/view.html.php

	public function display($tpl = null)
	{

		$this->state		= $this->get('State');
		$this->items		= $this->get('Items');
		$this->pagination	= $this->get('Pagination');

		// Check for errors.
		if (count($errors = $this->get('Errors'))) {
			JError::raiseError(500, implode("\n", $errors));
			return false;
		}

		$this->addToolbar();
        
        	$this->sidebar = JHtmlSidebar::render();
		parent::display($tpl);

	}

	protected function addToolbar()
	{
		// assuming you have other toolbar buttons ...

		JToolBarHelper::custom('hellos.extrahello', 'extrahello.png', 'extrahello_f2.png', 'Extra Hello', true);

	}

administrator/controllers/hellos.php

    public function extrahello()
	{

		// Get the input
		$input = JFactory::getApplication()->input;
		$pks = $input->post->get('cid', array(), 'array');

		// Sanitize the input
		JArrayHelper::toInteger($pks);

		// Get the model
		$model = $this->getModel();

		$return = $model->extrahello($pks);

		// Redirect to the list screen.
		$this->setRedirect(JRoute::_('index.php?option=com_hello&view=hellos', false));

	}

administrator/models/hello.php (notez le modèle au singulier)

    public function extrahello($pks)
	{

		// perform whatever you want on each item checked in the list

		return true;

	}

Explications utiles concernant la JToolBarHelper/custom : - http://docs.joomla.org/JToolBarHelper/custom