How can I get the associated articles programmatically in my custom component function?
I have my custom component and I am creating a new article for a multilingual site, so I need to associate articles of different languages.
You can use JLanguageAssociations::getAssociations
. This function will return an array containing associated items. You can also check if the language filter Items Associations parameter is enabled using JLanguageAssociations::isEnabled()
.
Here's an example from ROOT/administrator/components/com_content/models/article.php:
// Load associated content items
$app = JFactory::getApplication();
$assoc = JLanguageAssociations::isEnabled();
if ($assoc)
{
$item->associations = array();
if ($item->id != null)
{
$associations = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $item->id);
foreach ($associations as $tag => $association)
{
$item->associations[$tag] = $association->id;
}
}
}
return $item;