J3.x

Difference between revisions of "Developing an MVC Component/Adding decorations to the backend"

From Joomla! Documentation

< J3.x:Developing an MVC Component
m
 
(41 intermediate revisions by 13 users not shown)
Line 1: Line 1:
{{:J3.2:Developing a MVC Component}}
+
<noinclude><languages /></noinclude>
 +
{{:J3.1:Developing an MVC Component/<translate><!--T:1-->
 +
en</translate>}}
 +
<translate>== Introduction == <!--T:2--></translate>
 +
<translate><!--T:3-->
 +
This tutorial is part of the [[S:MyLanguage/J3.2:Developing an MVC Component | Developing an MVC Component for Joomla! 3.2]] tutorial. You are encouraged to read the previous parts of the tutorial before reading this.</translate>
 +
<translate>
 +
<!--T:30-->
 +
The functionality covered in this step includes making the columns sortable, and you can find a tutorial describing this aspect at [[Adding_sortable_columns_to_a_table_in_a_component|Adding sortable columns to a table in a component]].</translate>
  
{{review}}
+
<translate><!--T:31--> You can watch a video associated with this step in the tutorial at [https://youtu.be/Fj2QsKT-lp0 Step 10, Adding Backend Decorations].</translate>
  
This is a multiple-article series of tutorials on how to develop a Model-View-Contoller [[Component]] for Joomla! Version {{JVer|{{CurrentSTSVer|minor}}}}.
+
{{#widget:YouTube|id=Fj2QsKT-lp0}}
  
== Introduction ==
+
<translate>== Adding some icons == <!--T:4--></translate>
This tutorial is part of the [[J3.2:Developing a MVC Component | Developing a MVC Component for Joomla! 3.2]] tutorial. You are encouraged to read the previous parts of the tutorial before reading this.
+
<translate><!--T:5-->
 +
With your favourite file manager put a 16x16 image and a 48x48 image (I choose ''Tux'') in a ''media/images/'' folder and add a ''media'' tag in your [[#helloworld.xml|install file]]. Modify the ''menu'' tag in order to use the new icon.</translate>
  
== Adding some icons ==
+
Tux-16x16.png
With your favorite file manager put a 16x16 image and a 48x48 image (I choose ''tux'') in a ''media/images/'' folder and add a ''media'' tag in your [[#helloworld.xml|install file]]. Modify the ''menu'' tag in order to use the new icon.
+
[[File:Tux-16x16.png]]
  
== Modifying the views ==
+
Tux-48x48.png
In the ''admin/views/helloworlds/view.html.php'' file put these lines:
+
[[File:Tux-48x48.png]]
 +
 
 +
<translate><!--T:6-->
 +
Note that default admin template (isis) disables menu icons ! One possible workaround is to use icoMoon in your language string:</translate>
 +
 
 +
<span id="admin/language/en-GB/en-GB.com_helloworld.sys.ini">
 +
<tt>admin/language/en-GB/en-GB.com_helloworld.sys.ini</tt>
 +
<source lang="ini">
 +
; Joomla! Project
 +
; Copyright (C) 2005 - 2018 Open Source Matters. All rights reserved.
 +
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
 +
; Note : All ini files need to be saved as UTF-8
 +
 
 +
COM_HELLOWORLD="Hello World!"
 +
COM_HELLOWORLD_DESCRIPTION="This is the Hello World description"
 +
COM_HELLOWORLD_HELLOWORLD_VIEW_DEFAULT_TITLE="Hello World"
 +
COM_HELLOWORLD_HELLOWORLD_VIEW_DEFAULT_DESC="This view displays a selected message"
 +
COM_HELLOWORLD_MENU=" <i class="icon-smiley-2"></i>Hello World!"
 +
 
 +
</source>
 +
</span>
 +
 
 +
<translate><!--T:7-->
 +
Icon list can be found here: [[S:MyLanguage/J3.x:Joomla_Standard_Icomoon_Fonts|Standard IcoMoon Fonts]].</translate>
 +
 
 +
<translate>== Modifying the views == <!--T:8--></translate>
 +
<translate><!--T:9-->
 +
In the <tt>admin/views/helloworlds/view.html.php</tt> file put these lines:</translate>
  
 
<span id="admin/views/helloworlds/view.html.php">
 
<span id="admin/views/helloworlds/view.html.php">
''admin/views/helloworlds/view.html.php''
+
<tt>admin/views/helloworlds/view.html.php</tt>
<source lang="php">
+
<source lang="php" highlight="29-32,36-40,50,55-57,69-76,78-89">
 
<?php
 
<?php
 +
/**
 +
* @package    Joomla.Administrator
 +
* @subpackage  com_helloworld
 +
*
 +
* @copyright  Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
 +
* @license    GNU General Public License version 2 or later; see LICENSE.txt
 +
*/
 +
 
// No direct access to this file
 
// No direct access to this file
 
defined('_JEXEC') or die('Restricted access');
 
defined('_JEXEC') or die('Restricted access');
 
// import Joomla view library
 
jimport('joomla.application.component.view');
 
  
 
/**
 
/**
 
  * HelloWorlds View
 
  * HelloWorlds View
 +
*
 +
* @since  0.0.1
 
  */
 
  */
 
class HelloWorldViewHelloWorlds extends JViewLegacy
 
class HelloWorldViewHelloWorlds extends JViewLegacy
 
{
 
{
 
/**
 
/**
* HelloWorlds view display method
+
* Display the Hello World view
* @return void
+
*
 +
* @param  string  $tpl  The name of the template file to parse; automatically searches through the template paths.
 +
*
 +
* @return void
 
*/
 
*/
function display($tpl = null)  
+
function display($tpl = null)
 
{
 
{
 +
 +
// Get application
 +
$app = JFactory::getApplication();
 +
$context = "helloworld.list.admin.helloworld";
 
// Get data from the model
 
// Get data from the model
$items = $this->get('Items');
+
$this->items = $this->get('Items');
$pagination = $this->get('Pagination');
+
$this->pagination = $this->get('Pagination');
 +
$this->state = $this->get('State');
 +
$this->filter_order = $app->getUserStateFromRequest($context.'filter_order', 'filter_order', 'greeting', 'cmd');
 +
$this->filter_order_Dir = $app->getUserStateFromRequest($context.'filter_order_Dir', 'filter_order_Dir', 'asc', 'cmd');
 +
$this->filterForm    = $this->get('FilterForm');
 +
$this->activeFilters = $this->get('ActiveFilters');
  
 
// Check for errors.
 
// Check for errors.
if (count($errors = $this->get('Errors')))  
+
if (count($errors = $this->get('Errors')))
 
{
 
{
 
JError::raiseError(500, implode('<br />', $errors));
 
JError::raiseError(500, implode('<br />', $errors));
 +
 
return false;
 
return false;
 
}
 
}
// Assign data to the view
 
$this->items = $items;
 
$this->pagination = $pagination;
 
  
 
// Set the toolbar and number of found items
 
// Set the toolbar and number of found items
$this->addToolBar($this->pagination->total);
+
$this->addToolBar();
  
 
// Display the template
 
// Display the template
Line 60: Line 113:
  
 
/**
 
/**
* Setting the toolbar
+
* Add the page title and toolbar.
 +
*
 +
* @return  void
 +
*
 +
* @since  1.6
 
*/
 
*/
protected function addToolBar($total=null)  
+
protected function addToolBar()
 
{
 
{
JToolBarHelper::title(JText::_('COM_HELLOWORLD_MANAGER_HELLOWORLDS').
+
$title = JText::_('COM_HELLOWORLD_MANAGER_HELLOWORLDS');
//Reflect number of items in title!
+
 
($total?' <span style="font-size: 0.5em; vertical-align: middle;">('.$total.')</span>':'')
+
if ($this->pagination->total)
, 'helloworld');
+
{
JToolBarHelper::deleteListX('', 'helloworlds.delete');
+
$title .= "<span style='font-size: 0.5em; vertical-align: middle;'>(" . $this->pagination->total . ")</span>";
JToolBarHelper::editListX('helloworld.edit');
+
}
JToolBarHelper::addNewX('helloworld.add');
+
 
 +
JToolBarHelper::title($title, 'helloworld');
 +
JToolBarHelper::deleteList('', 'helloworlds.delete');
 +
JToolBarHelper::editList('helloworld.edit');
 +
JToolBarHelper::addNew('helloworld.add');
 
}
 
}
 
/**
 
/**
Line 86: Line 147:
 
</span>
 
</span>
  
This view uses a second parameter for the ''JToolBarHelper::title'' function. It will be used to construct the css class for the title. The ''_setDocument'' method sets the browser title.
+
<translate><!--T:10-->
 +
<tt>$this->filter_order</tt> and <tt>$this->filter_order_Dir</tt> store the active sorting column and the sorting direction respectively.
 +
Those variables are retrieved from the app state variables.</translate>
 +
 
 +
<translate><!--T:11-->
 +
See [[S:MyLanguage/How to use user state variables|How to use user state variables]] for more information about the use of the state variables.</translate>
 +
 
 +
<translate><!--T:12-->
 +
This view uses a second parameter for the <tt>JToolBarHelper::title</tt> function. It will be used to construct the css class for the title. The ''_setDocument'' method sets the browser title.</translate>
 +
 
 +
<translate><!--T:13-->
 +
In the <tt>admin/views/helloworlds/tmpl/default.php</tt> file put these lines:</translate>
 +
 
 +
<span id="admin/views/helloworlds/tmpl/default.php">
 +
</tt>admin/views/helloworlds/tmpl/default.php</tt>
 +
<source lang="php" highlight="12-16,19-29,38,41,44,83,84">
 +
<?php
 +
/**
 +
* @package    Joomla.Administrator
 +
* @subpackage  com_helloworld
 +
*
 +
* @copyright  Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
 +
* @license    GNU General Public License version 2 or later; see LICENSE.txt
 +
*/
  
In ''admin/views/helloworld/view.html.php'', put these lines:
+
// No direct access to this file
 +
defined('_JEXEC') or die('Restricted Access');
 +
 
 +
JHtml::_('formbehavior.chosen', 'select');
 +
 
 +
$listOrder    = $this->escape($this->filter_order);
 +
$listDirn      = $this->escape($this->filter_order_Dir);
 +
?>
 +
<form action="index.php?option=com_helloworld&view=helloworlds" method="post" id="adminForm" name="adminForm">
 +
<div class="row-fluid">
 +
<div class="span6">
 +
<?php echo JText::_('COM_HELLOWORLD_HELLOWORLDS_FILTER'); ?>
 +
<?php
 +
echo JLayoutHelper::render(
 +
'joomla.searchtools.default',
 +
array('view' => $this)
 +
);
 +
?>
 +
</div>
 +
</div>
 +
<table class="table table-striped table-hover">
 +
<thead>
 +
<tr>
 +
<th width="1%"><?php echo JText::_('COM_HELLOWORLD_NUM'); ?></th>
 +
<th width="2%">
 +
<?php echo JHtml::_('grid.checkall'); ?>
 +
</th>
 +
<th width="90%">
 +
<?php echo JHtml::_('grid.sort', 'COM_HELLOWORLD_HELLOWORLDS_NAME', 'greeting', $listDirn, $listOrder); ?>
 +
</th>
 +
<th width="5%">
 +
<?php echo JHtml::_('grid.sort', 'COM_HELLOWORLD_PUBLISHED', 'published', $listDirn, $listOrder); ?>
 +
</th>
 +
<th width="2%">
 +
<?php echo JHtml::_('grid.sort', 'COM_HELLOWORLD_ID', 'id', $listDirn, $listOrder); ?>
 +
</th>
 +
</tr>
 +
</thead>
 +
<tfoot>
 +
<tr>
 +
<td colspan="5">
 +
<?php echo $this->pagination->getListFooter(); ?>
 +
</td>
 +
</tr>
 +
</tfoot>
 +
<tbody>
 +
<?php if (!empty($this->items)) : ?>
 +
<?php foreach ($this->items as $i => $row) :
 +
$link = JRoute::_('index.php?option=com_helloworld&task=helloworld.edit&id=' . $row->id);
 +
?>
 +
<tr>
 +
<td><?php echo $this->pagination->getRowOffset($i); ?></td>
 +
<td>
 +
<?php echo JHtml::_('grid.id', $i, $row->id); ?>
 +
</td>
 +
<td>
 +
<a href="<?php echo $link; ?>" title="<?php echo JText::_('COM_HELLOWORLD_EDIT_HELLOWORLD'); ?>">
 +
<?php echo $row->greeting; ?>
 +
</a>
 +
</td>
 +
<td align="center">
 +
<?php echo JHtml::_('jgrid.published', $row->published, $i, 'helloworlds.', true, 'cb'); ?>
 +
</td>
 +
<td align="center">
 +
<?php echo $row->id; ?>
 +
</td>
 +
</tr>
 +
<?php endforeach; ?>
 +
<?php endif; ?>
 +
</tbody>
 +
</table>
 +
<input type="hidden" name="task" value=""/>
 +
<input type="hidden" name="boxchecked" value="0"/>
 +
<input type="hidden" name="filter_order" value="<?php echo $listOrder; ?>"/>
 +
<input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>"/>
 +
<?php echo JHtml::_('form.token'); ?>
 +
</form>
 +
 
 +
</source>
 +
</span>
 +
 
 +
<translate><!--T:14-->
 +
In <tt>admin/views/helloworld/view.html.php</tt>, put these lines:</translate>
  
 
<span id="admin/views/helloworld/view.html.php">
 
<span id="admin/views/helloworld/view.html.php">
''admin/views/helloworld/view.html.php''
+
<tt>admin/views/helloworld/view.html.php</tt>
<source lang="php">
+
<source lang="php" highlight="54-56,91-102">
 
<?php
 
<?php
 +
/**
 +
* @package    Joomla.Administrator
 +
* @subpackage  com_helloworld
 +
*
 +
* @copyright  Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
 +
* @license    GNU General Public License version 2 or later; see LICENSE.txt
 +
*/
 +
 
// No direct access to this file
 
// No direct access to this file
 
defined('_JEXEC') or die('Restricted access');
 
defined('_JEXEC') or die('Restricted access');
 
// import Joomla view library
 
jimport('joomla.application.component.view');
 
  
 
/**
 
/**
 
  * HelloWorld View
 
  * HelloWorld View
 +
*
 +
* @since  0.0.1
 
  */
 
  */
 
class HelloWorldViewHelloWorld extends JViewLegacy
 
class HelloWorldViewHelloWorld extends JViewLegacy
Line 108: Line 281:
 
* View form
 
* View form
 
*
 
*
* @var form
+
* @var         form
 
*/
 
*/
 
protected $form = null;
 
protected $form = null;
  
 
/**
 
/**
* display method of Hello view
+
* Display the Hello World view
* @return void
+
*
 +
* @param  string  $tpl  The name of the template file to parse; automatically searches through the template paths.
 +
*
 +
* @return void
 
*/
 
*/
public function display($tpl = null)  
+
public function display($tpl = null)
 
{
 
{
// get the Data
+
// Get the Data
$form = $this->get('Form');
+
$this->form = $this->get('Form');
$item = $this->get('Item');
+
$this->item = $this->get('Item');
  
 
// Check for errors.
 
// Check for errors.
if (count($errors = $this->get('Errors')))  
+
if (count($errors = $this->get('Errors')))
 
{
 
{
 
JError::raiseError(500, implode('<br />', $errors));
 
JError::raiseError(500, implode('<br />', $errors));
 +
 
return false;
 
return false;
 
}
 
}
// Assign the Data
+
 
$this->form = $form;
 
$this->item = $item;
 
  
 
// Set the toolbar
 
// Set the toolbar
Line 143: Line 318:
  
 
/**
 
/**
* Setting the toolbar
+
* Add the page title and toolbar.
 +
*
 +
* @return  void
 +
*
 +
* @since  1.6
 
*/
 
*/
protected function addToolBar()  
+
protected function addToolBar()
{
+
{
 
$input = JFactory::getApplication()->input;
 
$input = JFactory::getApplication()->input;
 +
 +
// Hide Joomla Administrator Main menu
 
$input->set('hidemainmenu', true);
 
$input->set('hidemainmenu', true);
 +
 
$isNew = ($this->item->id == 0);
 
$isNew = ($this->item->id == 0);
JToolBarHelper::title($isNew ? JText::_('COM_HELLOWORLD_MANAGER_HELLOWORLD_NEW')
+
 
                            : JText::_('COM_HELLOWORLD_MANAGER_HELLOWORLD_EDIT'), 'helloworld');
+
if ($isNew)
 +
{
 +
$title = JText::_('COM_HELLOWORLD_MANAGER_HELLOWORLD_NEW');
 +
}
 +
else
 +
{
 +
$title = JText::_('COM_HELLOWORLD_MANAGER_HELLOWORLD_EDIT');
 +
}
 +
 
 +
JToolBarHelper::title($title, 'helloworld');
 
JToolBarHelper::save('helloworld.save');
 
JToolBarHelper::save('helloworld.save');
JToolBarHelper::cancel('helloworld.cancel', $isNew ? 'JTOOLBAR_CANCEL' : 'JTOOLBAR_CLOSE');
+
JToolBarHelper::cancel(
 +
'helloworld.cancel',
 +
$isNew ? 'JTOOLBAR_CANCEL' : 'JTOOLBAR_CLOSE'
 +
);
 
}
 
}
 
/**
 
/**
Line 164: Line 358:
 
$isNew = ($this->item->id < 1);
 
$isNew = ($this->item->id < 1);
 
$document = JFactory::getDocument();
 
$document = JFactory::getDocument();
$document->setTitle($isNew ? JText::_('COM_HELLOWORLD_HELLOWORLD_CREATING')
+
$document->setTitle($isNew ? JText::_('COM_HELLOWORLD_HELLOWORLD_CREATING') :
                          : JText::_('COM_HELLOWORLD_HELLOWORLD_EDITING'));
+
                JText::_('COM_HELLOWORLD_HELLOWORLD_EDITING'));
 +
}
 +
}
 +
 
 +
</source>
 +
</span>
 +
 
 +
<translate><!--T:15-->
 +
This view also uses the second parameter of the <tt>JToolBarHelper::title</tt> function and set the browser title.</translate>
 +
 
 +
<translate>
 +
== Adding the filters == <!--T:29-->
 +
</translate>
 +
 
 +
<translate><!--T:16-->
 +
In <tt>admin/models/helloworlds.php</tt>, put these lines:</translate>
 +
 
 +
<span id="admin/models/helloworlds.php">
 +
<tt>admin/models/helloworlds.php</tt>
 +
<source lang="php" highlight="19-40,56-82">
 +
<?php
 +
/**
 +
* @package    Joomla.Administrator
 +
* @subpackage  com_helloworld
 +
*
 +
* @copyright  Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
 +
* @license    GNU General Public License version 2 or later; see LICENSE.txt
 +
*/
 +
// No direct access to this file
 +
defined('_JEXEC') or die('Restricted access');
 +
 
 +
/**
 +
* HelloWorldList Model
 +
*
 +
* @since  0.0.1
 +
*/
 +
class HelloWorldModelHelloWorlds extends JModelList
 +
{
 +
/**
 +
* Constructor.
 +
*
 +
* @param  array  $config  An optional associative array of configuration settings.
 +
*
 +
* @see    JController
 +
* @since  1.6
 +
*/
 +
public function __construct($config = array())
 +
{
 +
if (empty($config['filter_fields']))
 +
{
 +
$config['filter_fields'] = array(
 +
'id',
 +
'greeting',
 +
'published'
 +
);
 +
}
 +
 
 +
parent::__construct($config);
 +
}
 +
 
 +
/**
 +
* Method to build an SQL query to load the list data.
 +
*
 +
* @return      string  An SQL query
 +
*/
 +
protected function getListQuery()
 +
{
 +
// Initialize variables.
 +
$db    = JFactory::getDbo();
 +
$query = $db->getQuery(true);
 +
 
 +
// Create the base select statement.
 +
$query->select('*')
 +
  ->from($db->quoteName('#__helloworld'));
 +
 
 +
// Filter: like / search
 +
$search = $this->getState('filter.search');
 +
 
 +
if (!empty($search))
 +
{
 +
$like = $db->quote('%' . $search . '%');
 +
$query->where('greeting LIKE ' . $like);
 +
}
 +
 
 +
// Filter by published state
 +
$published = $this->getState('filter.published');
 +
 
 +
if (is_numeric($published))
 +
{
 +
$query->where('published = ' . (int) $published);
 +
}
 +
elseif ($published === '')
 +
{
 +
$query->where('(published IN (0, 1))');
 +
}
 +
 
 +
// Add the list ordering clause.
 +
$orderCol = $this->state->get('list.ordering', 'greeting');
 +
$orderDirn = $this->state->get('list.direction', 'asc');
 +
 
 +
$query->order($db->escape($orderCol) . ' ' . $db->escape($orderDirn));
 +
 
 +
return $query;
 
}
 
}
 
}
 
}
 +
 
</source>
 
</source>
 
</span>
 
</span>
  
This view also uses the second parameter of the JToolBarHelper::title function and set the browser title
+
<translate><!--T:17-->
 +
With your favourite file manager and editor put a file <tt>admin/models/forms/filter_helloworlds.xml</tt> containing</translate>
 +
 
 +
<span id="admin/models/forms/filter_helloworlds.xml">
 +
<tt>admin/models/forms/filter_helloworlds.xml</tt>
 +
<source lang="xml">
 +
<?xml version="1.0" encoding="utf-8"?>
 +
<form>
 +
<fields name="filter">
 +
<field
 +
name="search"
 +
type="text"
 +
label="COM_BANNERS_SEARCH_IN_TITLE"
 +
hint="JSEARCH_FILTER"
 +
class="js-stools-search-string"
 +
/>
 +
<field
 +
name="published"
 +
type="status"
 +
label="JOPTION_SELECT_PUBLISHED"
 +
description="JOPTION_SELECT_PUBLISHED_DESC"
 +
onchange="this.form.submit();"
 +
>
 +
<option value="">JOPTION_SELECT_PUBLISHED</option>
 +
</field>
 +
</fields>
 +
<fields name="list">
 +
<field
 +
name="limit"
 +
type="limitbox"
 +
class="input-mini"
 +
default="25"
 +
label="COM_CONTENT_LIST_LIMIT"
 +
description="COM_HELLOWORLD_LIST_LIMIT_DESC"
 +
onchange="this.form.submit();"
 +
/>
 +
</fields>
 +
</form>
 +
 
 +
</source>
 +
</span>
  
== Modifying the main entry file ==
+
<translate>
In the ''admin/helloworld.php'' file, put these lines in order to use the 48x48 icon:
+
== Modifying the main entry file == <!--T:18-->
 +
</translate>
 +
<translate><!--T:19-->
 +
In the <tt>admin/helloworld.php</tt> file, put these lines in order to use the 48x48 icon:</translate>
  
 
<span id="admin/helloworld.php">
 
<span id="admin/helloworld.php">
<source lang="php">
+
<source lang="php" highlight="13-16">
 
<?php
 
<?php
 +
/**
 +
* @package    Joomla.Administrator
 +
* @subpackage  com_helloworld
 +
*
 +
* @copyright  Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
 +
* @license    GNU General Public License version 2 or later; see LICENSE.txt
 +
*/
 +
 
// No direct access to this file
 
// No direct access to this file
 
defined('_JEXEC') or die('Restricted access');
 
defined('_JEXEC') or die('Restricted access');
Line 184: Line 532:
 
// Set some global property
 
// Set some global property
 
$document = JFactory::getDocument();
 
$document = JFactory::getDocument();
$document->addStyleDeclaration('.icon-48-helloworld {background-image: url(../media/com_helloworld/images/tux-48x48.png);}');
+
$document->addStyleDeclaration('.icon-helloworld {background-image: url(../media/com_helloworld/images/Tux-16x16.png);}');
 
 
// import joomla controller library
 
jimport('joomla.application.component.controller');
 
  
 
// Get an instance of the controller prefixed by HelloWorld
 
// Get an instance of the controller prefixed by HelloWorld
Line 197: Line 542:
  
 
// Redirect if set by the controller
 
// Redirect if set by the controller
$controller->redirect();</source>
+
$controller->redirect();
 +
</source>
 
</span>
 
</span>
  
== Adding some strings in the language file==
+
<translate>
Modify the ''admin/language/en-GB/en-GB.com_helloworld.ini'' and put these lines
+
== Adding some strings in the language file== <!--T:20-->
 +
</translate>
 +
<translate><!--T:21-->
 +
Modify the <tt>admin/language/en-GB/en-GB.com_helloworld.ini</tt> and put these lines</translate>
  
 
<span id="admin/language/en-GB/en-GB.com_helloworld.ini">
 
<span id="admin/language/en-GB/en-GB.com_helloworld.ini">
''admin/language/en-GB/en-GB.com_helloworld.ini''
+
<tt>admin/language/en-GB/en-GB.com_helloworld.ini</tt>
<source lang="ini">
+
<source lang="ini" highlight="6,7,9,14-16,21-30">
 +
; Joomla! Project
 +
; Copyright (C) 2005 - 2018 Open Source Matters. All rights reserved.
 +
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
 +
; Note : All ini files need to be saved as UTF-8
 +
 
 
COM_HELLOWORLD_ADMINISTRATION="HelloWorld - Administration"
 
COM_HELLOWORLD_ADMINISTRATION="HelloWorld - Administration"
 +
 +
COM_HELLOWORLD_NUM="#"
 +
COM_HELLOWORLD_HELLOWORLDS_FILTER="Filters"
 +
COM_HELLOWORLD_PUBLISHED="Published"
 +
COM_HELLOWORLD_HELLOWORLDS_NAME="Name"
 +
COM_HELLOWORLD_ID="Id"
 +
 
COM_HELLOWORLD_HELLOWORLD_CREATING="HelloWorld - Creating"
 
COM_HELLOWORLD_HELLOWORLD_CREATING="HelloWorld - Creating"
 
COM_HELLOWORLD_HELLOWORLD_DETAILS="Details"
 
COM_HELLOWORLD_HELLOWORLD_DETAILS="Details"
Line 217: Line 578:
 
COM_HELLOWORLD_MANAGER_HELLOWORLD_NEW="HelloWorld manager: New Message"
 
COM_HELLOWORLD_MANAGER_HELLOWORLD_NEW="HelloWorld manager: New Message"
 
COM_HELLOWORLD_MANAGER_HELLOWORLDS="HelloWorld manager"
 
COM_HELLOWORLD_MANAGER_HELLOWORLDS="HelloWorld manager"
 +
COM_HELLOWORLD_EDIT_HELLOWORLD="Edit message"
 
COM_HELLOWORLD_N_ITEMS_DELETED_1="One message deleted"
 
COM_HELLOWORLD_N_ITEMS_DELETED_1="One message deleted"
 
COM_HELLOWORLD_N_ITEMS_DELETED_MORE="%d messages deleted"
 
COM_HELLOWORLD_N_ITEMS_DELETED_MORE="%d messages deleted"
 +
COM_HELLOWORLD_N_ITEMS_PUBLISHED="%d message(s) published"
 +
COM_HELLOWORLD_N_ITEMS_UNPUBLISHED="%d message(s) unpublished"
 +
COM_HELLOWORLD_HELLOWORLD_GREETING_LABEL="Greeting"
 +
COM_HELLOWORLD_HELLOWORLD_GREETING_DESC="Add Hello World Greeting"
 +
 
</source>
 
</source>
 
</span>
 
</span>
  
== Packaging the component ==
+
<translate>
 +
== Packaging the component == <!--T:22-->
 +
</translate>
  
Content of your code directory
+
<translate><!--T:23-->
 +
Content of your code directory.  Each file link below takes you to the step in the tutorial which has the latest version of that source code file. </translate>
 
* ''[[#helloworld.xml|helloworld.xml]]''
 
* ''[[#helloworld.xml|helloworld.xml]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|site/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_a_view_to_the_site_part#site/helloworld.php|site/helloworld.php]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_02#site/helloworld.php|site/helloworld.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|site/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_02#site/controller.php|site/controller.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_a_view_to_the_site_part#site/controller.php|site/controller.php]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|site/views/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|site/views/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|site/views/helloworld/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|site/views/helloworld/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_04#site/views/helloworld/view.html.php|site/views/helloworld/view.html.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_a_view_to_the_site_part#site/views/helloworld/view.html.php|site/views/helloworld/view.html.php]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|site/views/helloworld/tmpl/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|site/views/helloworld/tmpl/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_06#site/views/helloworld/tmpl/default.xml|site/views/helloworld/tmpl/default.xml]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Using_the_database#site/views/helloworld/tmpl/default.xml|site/views/helloworld/tmpl/default.xml]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_02#site/views/helloworld/tmpl/default.php|site/views/helloworld/tmpl/default.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_a_view_to_the_site_part#site/views/helloworld/tmpl/default.php|site/views/helloworld/tmpl/default.php]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|site/models/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|site/models/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_06#site/models/helloworld.php|site/models/helloworld.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Using_the_database#site/models/helloworld.php|site/models/helloworld.php]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|site/language/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|site/language/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|site/language/en-GB/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|site/language/en-GB/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_08#site/language/en-GB/en-GB.com_helloworld.ini|site/language/en-GB/en-GB.com_helloworld.ini]]''
+
* [[S:MyLanguage/J3.x:Developing an MVC Component/Adding language management#site.2Flanguage.2Fen-GB.2Fen-GB.com_helloworld.ini|site/language/en-GB/en-GB.com_helloworld.ini]]
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|admin/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/index.html]]''
* ''[[#admin/helloworld.php|admin/helloworld.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_decorations_to_the_backend#admin/helloworld.php|admin/helloworld.php]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_07#admin/controller.php|admin/controller.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Basic_backend#admin/controller.php|admin/controller.php]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|admin/sql/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/sql/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_06#admin/sql/install.mysql.utf8.sql|admin/sql/install.mysql.utf8.sql]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Using_the_database#admin/sql/install.mysql.utf8.sql|admin/sql/install.mysql.utf8.sql]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_06#admin/sql/uninstall.mysql.utf8.sql|admin/sql/uninstall.mysql.utf8.sql]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Using_the_database#admin/sql/uninstall.mysql.utf8.sql|admin/sql/uninstall.mysql.utf8.sql]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|admin/sql/updates/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/sql/updates/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|admin/sql/updates/mysql/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/sql/updates/mysql/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#admin/sql/updates/mysql/0.0.1.sql|admin/sql/updates/mysql/0.0.1.sql]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#admin/sql/updates/mysql/0.0.1.sql|admin/sql/updates/mysql/0.0.1.sql]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_06#admin/sql/install.mysql.utf8.sql|admin/sql/updates/mysql/0.0.6.sql]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Using_the_database#admin/sql/install.mysql.utf8.sql|admin/sql/updates/mysql/0.0.6.sql]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|admin/models/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/models/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|admin/models/fields/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/models/fields/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_06#admin/models/fields/helloworld.php|admin/models/fields/helloworld.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Using_the_database#admin/models/fields/helloworld.php|admin/models/fields/helloworld.php]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|admin/models/forms/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_decorations_to_the_backend#admin/models/helloworlds.php|admin/models/helloworlds.php]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_09#admin/models/forms/helloworld.xml|admin/models/forms/helloworld.xml]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_backend_actions#admin/models/helloworlds.php|admin/models/helloworld.php]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_09#admin/models/helloworld.php|admin/models/helloworld.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding decorations to the backend#admin/models/forms/filter_helloworlds.xml|admin/models/forms/filter_helloworlds.xml]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_07#admin/models/helloworlds.php|admin/models/helloworlds.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/models/forms/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|admin/views/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_backend_actions#admin/models/forms/helloworld.xml|admin/models/forms/helloworld.xml]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|admin/views/helloworlds/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_backend_actions#admin/controllers/helloworld.php|admin/controllers/helloworld.php]]''
* ''[[#admin/views/helloworlds/view.html.php|admin/views/helloworlds/view.html.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_backend_actions#admin/controllers/helloworlds.php|admin/controllers/helloworlds.php]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|admin/views/helloworlds/tmpl/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/controllers/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_09#admin/views/helloworlds/tmpl/default.php|admin/views/helloworlds/tmpl/default.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_07#admin/views/helloworlds/tmpl/default_head.php|admin/views/helloworlds/tmpl/default_head.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/helloworld/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_07#admin/views/helloworlds/tmpl/default_body.php|admin/views/helloworlds/tmpl/default_body.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_decorations_to_the_backend#admin/views/helloworld/view.html.php|admin/views/helloworld/view.html.php]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_07#admin/views/helloworlds/tmpl/default_foot.php|admin/views/helloworlds/tmpl/default_foot.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/helloworld/tmpl/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|admin/views/helloworld/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_backend_actions#admin/views/helloworld/tmpl/edit.php|admin/views/helloworld/tmpl/edit.php]]''
* ''[[#admin/views/helloworld/view.html.php|admin/views/helloworld/view.html.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/helloworlds/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|admin/views/helloworld/tmpl/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_decorations_to_the_backend#admin/views/helloworlds/view.html.php|admin/views/helloworlds/view.html.php]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_09#admin/views/helloworld/tmpl/edit.php|admin/views/helloworld/tmpl/edit.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/helloworlds/tmpl/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|admin/tables/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_decorations_to_the_backend#admin/views/helloworlds/tmpl/default.php|admin/views/helloworlds/tmpl/default.php]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_06#admin/tables/helloworld.php|admin/tables/helloworld.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/tables/index.html]]''
* ''[[#admin/language/en-GB/en-GB.com_helloworld.ini|admin/language/en-GB/en-GB.com_helloworld.ini]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Using_the_database#admin/tables/helloworld.php|admin/tables/helloworld.php]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_08#admin/language/en-GB/en-GB.com_helloworld.menu.ini|admin/language/en-GB/en-GB.com_helloworld.menu.ini]]''
+
* ''[[#admin/language/index.html|admin/language/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|admin/controllers/index.html]]''
+
* ''[[#admin/language/en-GB/index.html|admin/language/en-GB/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_09#admin/controllers/helloworld.php|admin/controllers/helloworld.php]]''
+
* ''[[S:MyLanguage/J3.x:Developing an MVC Component/Adding_decorations_to_the_backend#admin.2Flanguage.2Fen-GB.2Fen-GB.com_helloworld.ini|admin/language/en-GB/en-GB.com_helloworld.ini]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_09#admin/controllers/helloworlds.php|admin/controllers/helloworlds.php]]''
+
* ''[[S:MyLanguage/J3.x:Developing an MVC Component/Adding_decorations_to_the_backend#admin.2Flanguage.2Fen-GB.2Fen-GB.com_helloworld.sys.ini|admin/language/en-GB/en-GB.com_helloworld.sys.ini]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_08#language/en-GB/en-GB.ini|language/en-GB/en-GB.ini]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|media/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|media/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|media/images/index.html]]''
* ''[[Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_01#index.html|media/images/index.html]]''
+
* ''[[S:MyLanguage/J3.x:Developing_an_MVC_Component/Adding_decorations_to_the_backend#Adding_some_icons|media/images/Tux-16x16.png]]''
* ''media/images/tux-16x16.png''
+
* ''[[S:MyLanguage/J3.x:Developing_an_MVC_Component/Adding_decorations_to_the_backend#Adding_some_icons|media/images/Tux-48x48.png]]''
* ''media/images/tux-48x48.png''
 
  
Create a compressed file of this directory or directly download the [http://joomlacode.org/gf/download/frsrelease/11394/58408/com_helloworld-1.6-part10.zip archive] and install it using the extension manager of Joomla. You can add a menu item of this component using the menu manager in the backend.
+
<translate><!--T:24-->
 +
Create a compressed file of this directory [https://github.com/scionescire/Joomla-3.2-Hello-World-Component/archive/step-10-adding-decorations-to-the-backend.zip archive] or directly download the archive and install it using the extension manager of Joomla. You can add a menu item of this component using the menu manager in the backend.</translate>
  
 
<span id="helloworld.xml">
 
<span id="helloworld.xml">
''helloworld.xml''
+
<tt>helloworld.xml</tt>
<source lang="xml">
+
<source lang="xml" highlight="13,49-53,56">
 
<?xml version="1.0" encoding="utf-8"?>
 
<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="2.5.0" method="upgrade">
+
<extension type="component" version="3.0" method="upgrade">
  
<name>Hello World!</name>
+
<name>COM_HELLOWORLD</name>
 
<!-- The following elements are optional and free of formatting constraints -->
 
<!-- The following elements are optional and free of formatting constraints -->
<creationDate>January 2014</creationDate>
+
<creationDate>January 2018</creationDate>
 
<author>John Doe</author>
 
<author>John Doe</author>
 
<authorEmail>john.doe@example.org</authorEmail>
 
<authorEmail>john.doe@example.org</authorEmail>
Line 313: Line 683:
 
</sql>
 
</sql>
 
</uninstall>
 
</uninstall>
<update> <!-- Runs on update; New in 2.5 -->
+
<update> <!-- Runs on update; New since J2.5 -->
 
<schemas>
 
<schemas>
 
<schemapath type="mysql">sql/updates/mysql</schemapath>
 
<schemapath type="mysql">sql/updates/mysql</schemapath>
Line 329: Line 699:
 
<folder>views</folder>
 
<folder>views</folder>
 
<folder>models</folder>
 
<folder>models</folder>
<folder>language</folder>
 
 
</files>
 
</files>
 +
 +
        <languages folder="site/language">
 +
<language tag="en-GB">en-GB/en-GB.com_helloworld.ini</language>
 +
        </languages>
  
 
<media destination="com_helloworld" folder="media">
 
<media destination="com_helloworld" folder="media">
Line 339: Line 712:
 
<administration>
 
<administration>
 
<!-- Administration Menu Section -->
 
<!-- Administration Menu Section -->
<menu img="../media/com_helloworld/images/tux-16x16.png">COM_HELLOWORLD_MENU</menu>
+
<menu link='index.php?option=com_helloworld' img="../media/com_helloworld/images/Tux-16x16.png">COM_HELLOWORLD_MENU</menu>
 
<!-- Administration Main File Copy Section -->
 
<!-- Administration Main File Copy Section -->
 
<!-- Note the folder attribute: This attribute describes the folder
 
<!-- Note the folder attribute: This attribute describes the folder
Line 357: Line 730:
 
<!-- views files section -->
 
<!-- views files section -->
 
<folder>views</folder>
 
<folder>views</folder>
                        <!-- admin languages files section -->
 
                        <folder>language</folder>
 
 
<!-- controllers files section -->
 
<!-- controllers files section -->
 
<folder>controllers</folder>
 
<folder>controllers</folder>
 
</files>
 
</files>
 +
<languages folder="admin/language">
 +
        <language tag="en-GB">en-GB/en-GB.com_helloworld.ini</language>
 +
                        <language tag="en-GB">en-GB/en-GB.com_helloworld.sys.ini</language>
 +
</languages>
 
</administration>
 
</administration>
 +
 
</extension>
 
</extension>
 
</source>
 
</source>
 
</span>
 
</span>
  
{{:J3.2:Developing a MVC Component/Navigate
+
<translate>== Contributors == <!--T:25--></translate>
|prev=Adding backend actions <!-- previous article subpage name -->
 
 
 
|next=Adding verifications <!-- next article subpage name -->}}
 
 
 
== Contributors ==
 
 
*[[User:cdemko|Christophe Demko]]
 
*[[User:cdemko|Christophe Demko]]
 
*[[User:oaksu|Ozgur Aksu]]
 
*[[User:oaksu|Ozgur Aksu]]
 
*[[User:Onliner|Campergue Patrick]]
 
*[[User:Onliner|Campergue Patrick]]
 +
*[[User:Scionescire|Scionescire]]
  
[[Category:Joomla! 3.0]]
+
<div class="row">
[[Category:Joomla! 3.1]]
+
<div class="large-6 columns">{{Basic button|<translate><!--T:26-->
[[Category:Joomla! 3.2]]
+
S:MyLanguage/J3.x:Developing_an_MVC_Component/Adding backend actions|Prev: Adding backend actions</translate>|class=expand success}}</div>
[[Category:Beginner Development]]
+
<div class="large-6 columns">{{Basic button|<translate><!--T:27-->
[[Category:Component Development]]
+
S:MyLanguage/J3.x:Developing_an_MVC_Component/Adding verifications|Next: Adding verifications</translate>|class=expand}}</div>
 +
</div>
 +
__NOTOC__
 +
<noinclude>
 +
[[Category:Joomla! 3.x{{#translation:}}]]
 +
[[Category:Joomla! 3.0{{#translation:}}]]
 +
[[Category:Joomla! 3.1{{#translation:}}]]
 +
[[Category:Joomla! 3.2{{#translation:}}]]
 +
[[Category:Joomla! 3.3{{#translation:}}]]
 +
[[Category:Joomla! 3.4{{#translation:}}]]
 +
[[Category:Beginner Development{{#translation:}}]]
 +
[[Category:Component Development{{#translation:}}]]
 +
[[Category:Tutorials{{#translation:}}]]
 +
[[Category:Tutorials in a Series{{#translation:}}]]
 +
</noinclude>

Latest revision as of 11:42, 1 April 2019

Other languages:
English • ‎español • ‎français • ‎العربية • ‎中文(台灣)‎
Joomla! 
3.x
Tutorial
Developing an MVC Component



This is a multiple-article series of tutorials on how to develop a Model-View-Controller Component for Joomla! VersionJoomla 3.x.

Begin with the Introduction, and navigate the articles in this series by using the navigation button at the bottom or the box to the right (the Articles in this series).



Introduction[edit]

This tutorial is part of the Developing an MVC Component for Joomla! 3.2 tutorial. You are encouraged to read the previous parts of the tutorial before reading this. The functionality covered in this step includes making the columns sortable, and you can find a tutorial describing this aspect at Adding sortable columns to a table in a component.

You can watch a video associated with this step in the tutorial at Step 10, Adding Backend Decorations.

Adding some icons[edit]

With your favourite file manager put a 16x16 image and a 48x48 image (I choose Tux) in a media/images/ folder and add a media tag in your install file. Modify the menu tag in order to use the new icon.

Tux-16x16.png Tux-16x16.png

Tux-48x48.png Tux-48x48.png

Note that default admin template (isis) disables menu icons ! One possible workaround is to use icoMoon in your language string:

admin/language/en-GB/en-GB.com_helloworld.sys.ini

; Joomla! Project
; Copyright (C) 2005 - 2018 Open Source Matters. All rights reserved.
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
; Note : All ini files need to be saved as UTF-8

COM_HELLOWORLD="Hello World!"
COM_HELLOWORLD_DESCRIPTION="This is the Hello World description"
COM_HELLOWORLD_HELLOWORLD_VIEW_DEFAULT_TITLE="Hello World"
COM_HELLOWORLD_HELLOWORLD_VIEW_DEFAULT_DESC="This view displays a selected message"
COM_HELLOWORLD_MENU=" <i class="icon-smiley-2"></i>Hello World!"

Icon list can be found here: Standard IcoMoon Fonts.

Modifying the views[edit]

In the admin/views/helloworlds/view.html.php file put these lines:

admin/views/helloworlds/view.html.php

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

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

/**
 * HelloWorlds View
 *
 * @since  0.0.1
 */
class HelloWorldViewHelloWorlds extends JViewLegacy
{
	/**
	 * Display the Hello World view
	 *
	 * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
	 *
	 * @return  void
	 */
	function display($tpl = null)
	{
		
		// Get application
		$app = JFactory::getApplication();
		$context = "helloworld.list.admin.helloworld";
		// Get data from the model
		$this->items			= $this->get('Items');
		$this->pagination		= $this->get('Pagination');
		$this->state			= $this->get('State');
		$this->filter_order 	= $app->getUserStateFromRequest($context.'filter_order', 'filter_order', 'greeting', 'cmd');
		$this->filter_order_Dir = $app->getUserStateFromRequest($context.'filter_order_Dir', 'filter_order_Dir', 'asc', 'cmd');
		$this->filterForm    	= $this->get('FilterForm');
		$this->activeFilters 	= $this->get('ActiveFilters');

		// Check for errors.
		if (count($errors = $this->get('Errors')))
		{
			JError::raiseError(500, implode('<br />', $errors));

			return false;
		}

		// Set the toolbar and number of found items
		$this->addToolBar();

		// Display the template
		parent::display($tpl);

		// Set the document
		$this->setDocument();
	}

	/**
	 * Add the page title and toolbar.
	 *
	 * @return  void
	 *
	 * @since   1.6
	 */
	protected function addToolBar()
	{
		$title = JText::_('COM_HELLOWORLD_MANAGER_HELLOWORLDS');

		if ($this->pagination->total)
		{
			$title .= "<span style='font-size: 0.5em; vertical-align: middle;'>(" . $this->pagination->total . ")</span>";
		}

		JToolBarHelper::title($title, 'helloworld');
		JToolBarHelper::deleteList('', 'helloworlds.delete');
		JToolBarHelper::editList('helloworld.edit');
		JToolBarHelper::addNew('helloworld.add');
	}
	/**
	 * Method to set up the document properties
	 *
	 * @return void
	 */
	protected function setDocument() 
	{
		$document = JFactory::getDocument();
		$document->setTitle(JText::_('COM_HELLOWORLD_ADMINISTRATION'));
	}
}

$this->filter_order and $this->filter_order_Dir store the active sorting column and the sorting direction respectively. Those variables are retrieved from the app state variables.

See How to use user state variables for more information about the use of the state variables.

This view uses a second parameter for the JToolBarHelper::title function. It will be used to construct the css class for the title. The _setDocument method sets the browser title.

In the admin/views/helloworlds/tmpl/default.php file put these lines:

admin/views/helloworlds/tmpl/default.php

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

// No direct access to this file
defined('_JEXEC') or die('Restricted Access');

JHtml::_('formbehavior.chosen', 'select');

$listOrder     = $this->escape($this->filter_order);
$listDirn      = $this->escape($this->filter_order_Dir);
?>
<form action="index.php?option=com_helloworld&view=helloworlds" method="post" id="adminForm" name="adminForm">
	<div class="row-fluid">
		<div class="span6">
			<?php echo JText::_('COM_HELLOWORLD_HELLOWORLDS_FILTER'); ?>
			<?php
				echo JLayoutHelper::render(
					'joomla.searchtools.default',
					array('view' => $this)
				);
			?>
		</div>
	</div>
	<table class="table table-striped table-hover">
		<thead>
		<tr>
			<th width="1%"><?php echo JText::_('COM_HELLOWORLD_NUM'); ?></th>
			<th width="2%">
				<?php echo JHtml::_('grid.checkall'); ?>
			</th>
			<th width="90%">
				<?php echo JHtml::_('grid.sort', 'COM_HELLOWORLD_HELLOWORLDS_NAME', 'greeting', $listDirn, $listOrder); ?>
			</th>
			<th width="5%">
				<?php echo JHtml::_('grid.sort', 'COM_HELLOWORLD_PUBLISHED', 'published', $listDirn, $listOrder); ?>
			</th>
			<th width="2%">
				<?php echo JHtml::_('grid.sort', 'COM_HELLOWORLD_ID', 'id', $listDirn, $listOrder); ?>
			</th>
		</tr>
		</thead>
		<tfoot>
			<tr>
				<td colspan="5">
					<?php echo $this->pagination->getListFooter(); ?>
				</td>
			</tr>
		</tfoot>
		<tbody>
			<?php if (!empty($this->items)) : ?>
				<?php foreach ($this->items as $i => $row) :
					$link = JRoute::_('index.php?option=com_helloworld&task=helloworld.edit&id=' . $row->id);
				?>
					<tr>
						<td><?php echo $this->pagination->getRowOffset($i); ?></td>
						<td>
							<?php echo JHtml::_('grid.id', $i, $row->id); ?>
						</td>
						<td>
							<a href="<?php echo $link; ?>" title="<?php echo JText::_('COM_HELLOWORLD_EDIT_HELLOWORLD'); ?>">
								<?php echo $row->greeting; ?>
							</a>
						</td>
						<td align="center">
							<?php echo JHtml::_('jgrid.published', $row->published, $i, 'helloworlds.', true, 'cb'); ?>
						</td>
						<td align="center">
							<?php echo $row->id; ?>
						</td>
					</tr>
				<?php endforeach; ?>
			<?php endif; ?>
		</tbody>
	</table>
	<input type="hidden" name="task" value=""/>
	<input type="hidden" name="boxchecked" value="0"/>
	<input type="hidden" name="filter_order" value="<?php echo $listOrder; ?>"/>
	<input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>"/>
	<?php echo JHtml::_('form.token'); ?>
</form>

In admin/views/helloworld/view.html.php, put these lines:

admin/views/helloworld/view.html.php

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

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

/**
 * HelloWorld View
 *
 * @since  0.0.1
 */
class HelloWorldViewHelloWorld extends JViewLegacy
{
	/**
	 * View form
	 *
	 * @var         form
	 */
	protected $form = null;

	/**
	 * Display the Hello World view
	 *
	 * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
	 *
	 * @return  void
	 */
	public function display($tpl = null)
	{
		// Get the Data
		$this->form = $this->get('Form');
		$this->item = $this->get('Item');

		// Check for errors.
		if (count($errors = $this->get('Errors')))
		{
			JError::raiseError(500, implode('<br />', $errors));

			return false;
		}


		// Set the toolbar
		$this->addToolBar();

		// Display the template
		parent::display($tpl);

		// Set the document
		$this->setDocument();
	}

	/**
	 * Add the page title and toolbar.
	 *
	 * @return  void
	 *
	 * @since   1.6
	 */
	protected function addToolBar()
	{
		$input = JFactory::getApplication()->input;

		// Hide Joomla Administrator Main menu
		$input->set('hidemainmenu', true);

		$isNew = ($this->item->id == 0);

		if ($isNew)
		{
			$title = JText::_('COM_HELLOWORLD_MANAGER_HELLOWORLD_NEW');
		}
		else
		{
			$title = JText::_('COM_HELLOWORLD_MANAGER_HELLOWORLD_EDIT');
		}

		JToolBarHelper::title($title, 'helloworld');
		JToolBarHelper::save('helloworld.save');
		JToolBarHelper::cancel(
			'helloworld.cancel',
			$isNew ? 'JTOOLBAR_CANCEL' : 'JTOOLBAR_CLOSE'
		);
	}
	/**
	 * Method to set up the document properties
	 *
	 * @return void
	 */
	protected function setDocument() 
	{
		$isNew = ($this->item->id < 1);
		$document = JFactory::getDocument();
		$document->setTitle($isNew ? JText::_('COM_HELLOWORLD_HELLOWORLD_CREATING') :
                JText::_('COM_HELLOWORLD_HELLOWORLD_EDITING'));
	}
}

This view also uses the second parameter of the JToolBarHelper::title function and set the browser title.

Adding the filters[edit]

In admin/models/helloworlds.php, put these lines:

admin/models/helloworlds.php

<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_helloworld
 *
 * @copyright   Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

/**
 * HelloWorldList Model
 *
 * @since  0.0.1
 */
class HelloWorldModelHelloWorlds extends JModelList
{
	/**
	 * Constructor.
	 *
	 * @param   array  $config  An optional associative array of configuration settings.
	 *
	 * @see     JController
	 * @since   1.6
	 */
	public function __construct($config = array())
	{
		if (empty($config['filter_fields']))
		{
			$config['filter_fields'] = array(
				'id',
				'greeting',
				'published'
			);
		}

		parent::__construct($config);
	}

	/**
	 * Method to build an SQL query to load the list data.
	 *
	 * @return      string  An SQL query
	 */
	protected function getListQuery()
	{
		// Initialize variables.
		$db    = JFactory::getDbo();
		$query = $db->getQuery(true);

		// Create the base select statement.
		$query->select('*')
			  ->from($db->quoteName('#__helloworld'));

		// Filter: like / search
		$search = $this->getState('filter.search');

		if (!empty($search))
		{
			$like = $db->quote('%' . $search . '%');
			$query->where('greeting LIKE ' . $like);
		}

		// Filter by published state
		$published = $this->getState('filter.published');

		if (is_numeric($published))
		{
			$query->where('published = ' . (int) $published);
		}
		elseif ($published === '')
		{
			$query->where('(published IN (0, 1))');
		}

		// Add the list ordering clause.
		$orderCol	= $this->state->get('list.ordering', 'greeting');
		$orderDirn 	= $this->state->get('list.direction', 'asc');

		$query->order($db->escape($orderCol) . ' ' . $db->escape($orderDirn));

		return $query;
	}
}

With your favourite file manager and editor put a file admin/models/forms/filter_helloworlds.xml containing

admin/models/forms/filter_helloworlds.xml

<?xml version="1.0" encoding="utf-8"?>
<form>
	<fields name="filter">
		<field
			name="search"
			type="text"
			label="COM_BANNERS_SEARCH_IN_TITLE"
			hint="JSEARCH_FILTER"
			class="js-stools-search-string"
		/>
		<field
			name="published"
			type="status"
			label="JOPTION_SELECT_PUBLISHED"
			description="JOPTION_SELECT_PUBLISHED_DESC"
			onchange="this.form.submit();"
			>
			<option value="">JOPTION_SELECT_PUBLISHED</option>
		</field>
	</fields>
	<fields name="list">
		<field
			name="limit"
			type="limitbox"
			class="input-mini"
			default="25"
			label="COM_CONTENT_LIST_LIMIT"
			description="COM_HELLOWORLD_LIST_LIMIT_DESC"
			onchange="this.form.submit();"
		/>
	</fields>
</form>

Modifying the main entry file[edit]

In the admin/helloworld.php file, put these lines in order to use the 48x48 icon:

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

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// Set some global property
$document = JFactory::getDocument();
$document->addStyleDeclaration('.icon-helloworld {background-image: url(../media/com_helloworld/images/Tux-16x16.png);}');

// Get an instance of the controller prefixed by HelloWorld
$controller = JControllerLegacy::getInstance('HelloWorld');

// Perform the Request task
$input = JFactory::getApplication()->input;
$controller->execute($input->getCmd('task'));

// Redirect if set by the controller
$controller->redirect();

Adding some strings in the language file[edit]

Modify the admin/language/en-GB/en-GB.com_helloworld.ini and put these lines

admin/language/en-GB/en-GB.com_helloworld.ini

; Joomla! Project
; Copyright (C) 2005 - 2018 Open Source Matters. All rights reserved.
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
; Note : All ini files need to be saved as UTF-8

COM_HELLOWORLD_ADMINISTRATION="HelloWorld - Administration"

COM_HELLOWORLD_NUM="#"
COM_HELLOWORLD_HELLOWORLDS_FILTER="Filters"
COM_HELLOWORLD_PUBLISHED="Published"
COM_HELLOWORLD_HELLOWORLDS_NAME="Name"
COM_HELLOWORLD_ID="Id"

COM_HELLOWORLD_HELLOWORLD_CREATING="HelloWorld - Creating"
COM_HELLOWORLD_HELLOWORLD_DETAILS="Details"
COM_HELLOWORLD_HELLOWORLD_EDITING="HelloWorld - Editing"
COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_DESC="This message will be displayed"
COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_LABEL="Message"
COM_HELLOWORLD_HELLOWORLD_HEADING_GREETING="Greeting"
COM_HELLOWORLD_HELLOWORLD_HEADING_ID="Id"
COM_HELLOWORLD_MANAGER_HELLOWORLD_EDIT="HelloWorld manager: Edit Message"
COM_HELLOWORLD_MANAGER_HELLOWORLD_NEW="HelloWorld manager: New Message"
COM_HELLOWORLD_MANAGER_HELLOWORLDS="HelloWorld manager"
COM_HELLOWORLD_EDIT_HELLOWORLD="Edit message"
COM_HELLOWORLD_N_ITEMS_DELETED_1="One message deleted"
COM_HELLOWORLD_N_ITEMS_DELETED_MORE="%d messages deleted"
COM_HELLOWORLD_N_ITEMS_PUBLISHED="%d message(s) published"
COM_HELLOWORLD_N_ITEMS_UNPUBLISHED="%d message(s) unpublished"
COM_HELLOWORLD_HELLOWORLD_GREETING_LABEL="Greeting"
COM_HELLOWORLD_HELLOWORLD_GREETING_DESC="Add Hello World Greeting"

Packaging the component[edit]

Content of your code directory. Each file link below takes you to the step in the tutorial which has the latest version of that source code file.

Create a compressed file of this directory archive or directly download the archive and install it using the extension manager of Joomla. You can add a menu item of this component using the menu manager in the backend.

helloworld.xml

<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="3.0" method="upgrade">

	<name>COM_HELLOWORLD</name>
	<!-- The following elements are optional and free of formatting constraints -->
	<creationDate>January 2018</creationDate>
	<author>John Doe</author>
	<authorEmail>john.doe@example.org</authorEmail>
	<authorUrl>http://www.example.org</authorUrl>
	<copyright>Copyright Info</copyright>
	<license>License Info</license>
	<!--  The version string is recorded in the components table -->
	<version>0.0.10</version>
	<!-- The description is optional and defaults to the name -->
	<description>COM_HELLOWORLD_DESCRIPTION</description>

	<install> <!-- Runs on install -->
		<sql>
			<file driver="mysql" charset="utf8">sql/install.mysql.utf8.sql</file>
		</sql>
	</install>
	<uninstall> <!-- Runs on uninstall -->
		<sql>
			<file driver="mysql" charset="utf8">sql/uninstall.mysql.utf8.sql</file>
		</sql>
	</uninstall>
	<update> <!-- Runs on update; New since J2.5 -->
		<schemas>
			<schemapath type="mysql">sql/updates/mysql</schemapath>
		</schemas>
	</update>

	<!-- Site Main File Copy Section -->
	<!-- Note the folder attribute: This attribute describes the folder
		to copy FROM in the package to install therefore files copied
		in this section are copied from /site/ in the package -->
	<files folder="site">
		<filename>index.html</filename>
		<filename>helloworld.php</filename>
		<filename>controller.php</filename>
		<folder>views</folder>
		<folder>models</folder>
	</files>

        <languages folder="site/language">
		<language tag="en-GB">en-GB/en-GB.com_helloworld.ini</language>
        </languages>

	<media destination="com_helloworld" folder="media">
		<filename>index.html</filename>
		<folder>images</folder>
	</media>

	<administration>
		<!-- Administration Menu Section -->
		<menu link='index.php?option=com_helloworld' img="../media/com_helloworld/images/Tux-16x16.png">COM_HELLOWORLD_MENU</menu>
		<!-- Administration Main File Copy Section -->
		<!-- Note the folder attribute: This attribute describes the folder
			to copy FROM in the package to install therefore files copied
			in this section are copied from /admin/ in the package -->
		<files folder="admin">
			<!-- Admin Main File Copy Section -->
			<filename>index.html</filename>
			<filename>helloworld.php</filename>
			<filename>controller.php</filename>
			<!-- SQL files section -->
			<folder>sql</folder>
			<!-- tables files section -->
			<folder>tables</folder>
			<!-- models files section -->
			<folder>models</folder>
			<!-- views files section -->
			<folder>views</folder>
			<!-- controllers files section -->
			<folder>controllers</folder>
		</files>
		<languages folder="admin/language">
        		<language tag="en-GB">en-GB/en-GB.com_helloworld.ini</language>
                        <language tag="en-GB">en-GB/en-GB.com_helloworld.sys.ini</language>
		</languages>
	</administration>

</extension>

Contributors[edit]