diff --git a/administrator/components/com_categories/views/category/view.html.php b/administrator/components/com_categories/views/category/view.html.php index c24b32c1444d7..842643e67a40e 100644 --- a/administrator/components/com_categories/views/category/view.html.php +++ b/administrator/components/com_categories/views/category/view.html.php @@ -207,6 +207,11 @@ protected function addToolbar() JToolbarHelper::versions($typeAlias, $this->item->id); } + if (JLanguageAssociations::isEnabled() && JComponentHelper::isEnabled('com_associations')) + { + JToolbarHelper::custom('category.editAssociations', 'contract', 'contract', 'JTOOLBAR_ASSOCIATIONS', false, false); + } + JToolbarHelper::cancel('category.cancel', 'JTOOLBAR_CLOSE'); } diff --git a/administrator/components/com_contact/views/contact/view.html.php b/administrator/components/com_contact/views/contact/view.html.php index 1e109067633ed..e3907ceda5c0d 100644 --- a/administrator/components/com_contact/views/contact/view.html.php +++ b/administrator/components/com_contact/views/contact/view.html.php @@ -139,6 +139,11 @@ protected function addToolbar() JToolbarHelper::versions('com_contact.contact', $this->item->id); } + if (JLanguageAssociations::isEnabled() && JComponentHelper::isEnabled('com_associations')) + { + JToolbarHelper::custom('contact.editAssociations', 'contract', 'contract', 'JTOOLBAR_ASSOCIATIONS', false, false); + } + JToolbarHelper::cancel('contact.cancel', 'JTOOLBAR_CLOSE'); } diff --git a/administrator/components/com_content/views/article/view.html.php b/administrator/components/com_content/views/article/view.html.php index f0bfabc687c40..0032ce50ce6e5 100644 --- a/administrator/components/com_content/views/article/view.html.php +++ b/administrator/components/com_content/views/article/view.html.php @@ -150,6 +150,11 @@ protected function addToolbar() JToolbarHelper::versions('com_content.article', $this->item->id); } + if (JLanguageAssociations::isEnabled() && JComponentHelper::isEnabled('com_associations')) + { + JToolbarHelper::custom('article.editAssociations', 'contract', 'contract', 'JTOOLBAR_ASSOCIATIONS', false, false); + } + JToolbarHelper::cancel('article.cancel', 'JTOOLBAR_CLOSE'); } diff --git a/administrator/components/com_menus/views/item/view.html.php b/administrator/components/com_menus/views/item/view.html.php index 95bb7d06c4b03..b9733eff03655 100644 --- a/administrator/components/com_menus/views/item/view.html.php +++ b/administrator/components/com_menus/views/item/view.html.php @@ -140,6 +140,11 @@ protected function addToolbar() JToolbarHelper::save2copy('item.save2copy'); } + if (!$isNew && JLanguageAssociations::isEnabled() && JComponentHelper::isEnabled('com_associations')) + { + JToolbarHelper::custom('item.editAssociations', 'contract', 'contract', 'JTOOLBAR_ASSOCIATIONS', false, false); + } + if ($isNew) { JToolbarHelper::cancel('item.cancel'); diff --git a/administrator/components/com_newsfeeds/views/newsfeed/view.html.php b/administrator/components/com_newsfeeds/views/newsfeed/view.html.php index 286f360c80670..b885098c9fb42 100644 --- a/administrator/components/com_newsfeeds/views/newsfeed/view.html.php +++ b/administrator/components/com_newsfeeds/views/newsfeed/view.html.php @@ -117,6 +117,11 @@ protected function addToolbar() JToolbarHelper::save2copy('newsfeed.save2copy'); } + if (!$isNew && JLanguageAssociations::isEnabled() && JComponentHelper::isEnabled('com_associations')) + { + JToolbarHelper::custom('newsfeed.editAssociations', 'contract', 'contract', 'JTOOLBAR_ASSOCIATIONS', false, false); + } + if (empty($this->item->id)) { JToolbarHelper::cancel('newsfeed.cancel'); diff --git a/administrator/language/en-GB/en-GB.ini b/administrator/language/en-GB/en-GB.ini index bd1b795573078..f02158db9d492 100644 --- a/administrator/language/en-GB/en-GB.ini +++ b/administrator/language/en-GB/en-GB.ini @@ -281,6 +281,7 @@ JGLOBAL_ARTICLE_ORDER_DESC="The order that articles will show in." JGLOBAL_ARTICLE_ORDER_LABEL="Article Order" JGLOBAL_ARTICLES="Articles" JGLOBAL_ASSOC_NOT_POSSIBLE="To define associations, please make sure the item language is not set to 'All'." +JGLOBAL_ASSOCIATIONS_NEW_ITEM_WARNING="To create associations, first save the item." JGLOBAL_ASSOCIATIONS_RESET_WARNING="The language has been changed. If you save this item again it will reset the available associations. If this was not intended, close the item." JGLOBAL_AUTH_ACCESS_DENIED="Access Denied" JGLOBAL_AUTH_ACCESS_GRANTED="Access Granted" @@ -912,6 +913,7 @@ JTOGGLE_SHOW_SIDEBAR="Show the sidebar" JTOOLBAR_APPLY="Save" JTOOLBAR_ARCHIVE="Archive" JTOOLBAR_ASSIGN="Assign" +JTOOLBAR_ASSOCIATIONS="Associations" JTOOLBAR_BACK="Back" JTOOLBAR_BATCH="Batch" JTOOLBAR_BULK_IMPORT="Bulk Import" diff --git a/libraries/src/MVC/Controller/FormController.php b/libraries/src/MVC/Controller/FormController.php index 27d532a5d00b8..e45b4353ebfe0 100644 --- a/libraries/src/MVC/Controller/FormController.php +++ b/libraries/src/MVC/Controller/FormController.php @@ -921,4 +921,22 @@ public function reload($key = null, $urlVar = null) $this->setRedirect($redirectUrl); $this->redirect(); } + + /** + * Load item to edit associations in com_associations + * + * @return void + * + * @since __DEPLOY_VERSION__ + */ + public function editAssociations() + { + // Initialise variables. + $app = \JFactory::getApplication(); + $input = $app->input; + $model = $this->getModel(); + + $data = $input->get('jform', array(), 'array'); + $model->editAssociations($data); + } } diff --git a/libraries/src/MVC/Model/AdminModel.php b/libraries/src/MVC/Model/AdminModel.php index 1055717b59b91..55f04ea32b43d 100644 --- a/libraries/src/MVC/Model/AdminModel.php +++ b/libraries/src/MVC/Model/AdminModel.php @@ -13,6 +13,7 @@ use Joomla\Registry\Registry; use Joomla\String\StringHelper; use Joomla\Utilities\ArrayHelper; +use Joomla\CMS\Language\LanguageHelper; /** * Prototype admin model. @@ -1531,4 +1532,99 @@ public function initBatch() $this->tagsObserver = $this->table->getObserverOfClass('Joomla\CMS\Table\Observer\Tags'); } } + + /** + * Method to load an item in com_associations. + * + * @param array $data The form data. + * + * @return boolean True if successful, false otherwise. + * + * @since __DEPLOY_VERSION__ + */ + public function editAssociations($data) + { + // Save the item + $this->save($data); + + $app = \JFactory::getApplication(); + $id = $data['id']; + + // Deal with categories associations + if ($this->text_prefix === 'COM_CATEGORIES') + { + $extension = $app->input->get('extension', 'com_content'); + $this->typeAlias = $extension . '.category'; + $component = strtolower($this->text_prefix); + $view = 'category'; + } + else + { + $aliasArray = explode('.', $this->typeAlias); + $component = $aliasArray[0]; + $view = $aliasArray[1]; + $extension = ''; + } + + // Menu item redirect needs admin client + $client = $component === 'com_menus' ? '&client_id=0' : ''; + + if ($id == 0) + { + $app->enqueueMessage(\JText::_('JGLOBAL_ASSOCIATIONS_NEW_ITEM_WARNING'), 'error'); + $app->redirect( + \JRoute::_('index.php?option=' . $component . '&view=' . $view . $client . '&layout=edit&id=' . $id . $extension, false) + ); + + return false; + } + + if ($data['language'] === '*') + { + $app->enqueueMessage(\JText::_('JGLOBAL_ASSOC_NOT_POSSIBLE'), 'notice'); + $app->redirect( + \JRoute::_('index.php?option=' . $component . '&view=' . $view . $client . '&layout=edit&id=' . $id . $extension, false) + ); + + return false; + } + + $languages = LanguageHelper::getContentLanguages(array(0, 1)); + $target = ''; + + /* If the site contains only 2 languages and an association exists for the item + load directly the associated target item in the side by side view + otherwise select already the target language + */ + if (count($languages) === 2) + { + foreach ($languages as $language) + { + $lang_code[] = $language->lang_code; + } + + $refLang = array($data['language']); + $targetLang = array_diff($lang_code, $refLang); + $targetLang = implode(',', $targetLang); + $targetId = $data['associations'][$targetLang]; + + if ($targetId) + { + $target = '&target=' . $targetLang . '%3A' . $targetId . '%3Aedit'; + } + else + { + $target = '&target=' . $targetLang . '%3A0%3Aadd'; + } + } + + $app->redirect( + \JRoute::_( + 'index.php?option=com_associations&view=association&layout=edit&itemtype=' . $this->typeAlias + . '&task=association.edit&id=' . $id . $target, false + ) + ); + + return true; + } }