Multilingual Associations/Developers
From Joomla! Documentation
< J3.x:Multilingual Associations
Developers
Articles in this Series
Developers[edit]
Introduction[edit]
If your extension can support association and you would like it to be available in the Associations Manager, you'll have to provide a helper class.
Basically, you need to create a file associations.php in your component administrator helper directory. If your component is named Example the helper class should be named ExampleAssociationsHelper and this class needs to extend JAssociationExtensionHelper.
Add three protected variables[edit]
/**
* The extension name
*
* @var array $extension
*
* @since 3.7.0
*/
protected $extension = 'com_example';
/**
* Array of item types
*
* @var array $itemTypes
*
* @since 3.7.0
*/
protected $itemTypes = array('item');
/**
* Has the extension association support
*
* @var boolean $associationsSupport
*
* @since 3.7.0
*/
protected $associationsSupport = true;
Add three public functions[edit]
Method getAssociations[edit]
This function should return an array of associated items.
/**
* Get the associated items for an item
*
* @param string $typeName The item type
* @param int $id The id of item for which we need the associated items
*
* @return array
*
* @since 3.7.0
*/
public function getAssociations($typeName, $id)
{
// The code goes here.
}
Method getItem[edit]
This function should return a JTable Object for the type and id. Don't forget something like JTable::addIncludePath(__DIR__ . '/../tables'); so that the class can be found.
/**
* Get item information
*
* @param string $typeName The item type
* @param int $id The id of item for which we need the associated items
*
* @return JTable|null
*
* @since 3.7.0
*/
public function getItem($typeName, $id)
{
// The code goes here.
}
Method getType[edit]
This function should return an array of item types.
/**
* Get information about the type
*
* @param string $typeName The item type
*
* @return array Array of item types
*
* @since 3.7.0
*/
public function getType($typeName = '')
{
// The code goes here.
}
Here you set up information per type, the function returns an array.
array(
'fields' => $fields,
'support' => $support,
'tables' => $tables,
'joins' => $joins,
'title' => $title,
);
For fields and support we have a template function that set defaults so you only have to overwrite what is different in your extension. Please make sure that $fields['title'] and $fields['state'] are set correctly.
Example of Implementation[edit]
You can find an example for integrating multilingual associations in a component at GitHub.
For more information about the feature itself please have a look into the Pull Request for this feature.
If you have problems implementing the side-by-side view in com̞_associations please have a look into the Github Issue.