@@ -1223,6 +1223,7 @@ public function save($data)
12231223 $ dispatcher = \JEventDispatcher::getInstance ();
12241224 $ table = $ this ->getTable ();
12251225 $ context = $ this ->option . '. ' . $ this ->name ;
1226+ $ app = \JFactory::getApplication ();
12261227
12271228 if (!empty ($ data ['tags ' ]) && $ data ['tags ' ][0 ] != '' )
12281229 {
@@ -1322,7 +1323,7 @@ public function save($data)
13221323 // Show a warning if the item isn't assigned to a language but we have associations.
13231324 if ($ associations && $ table ->language === '* ' )
13241325 {
1325- \JFactory:: getApplication () ->enqueueMessage (
1326+ $ app ->enqueueMessage (
13261327 \JText::_ (strtoupper ($ this ->option ) . '_ERROR_ALL_LANGUAGE_ASSOCIATED ' ),
13271328 'warning '
13281329 );
@@ -1379,6 +1380,86 @@ public function save($data)
13791380 }
13801381 }
13811382
1383+ if ($ app ->input ->get ('task ' ) == 'editAssociations ' )
1384+ {
1385+ $ id = $ data ['id ' ];
1386+
1387+ // Deal with categories associations
1388+ if ($ this ->text_prefix === 'COM_CATEGORIES ' )
1389+ {
1390+ $ extension = $ app ->input ->get ('extension ' , 'com_content ' );
1391+ $ this ->typeAlias = $ extension . '.category ' ;
1392+ $ component = strtolower ($ this ->text_prefix );
1393+ $ view = 'category ' ;
1394+ }
1395+ else
1396+ {
1397+ $ aliasArray = explode ('. ' , $ this ->typeAlias );
1398+ $ component = $ aliasArray [0 ];
1399+ $ view = $ aliasArray [1 ];
1400+ $ extension = '' ;
1401+ }
1402+
1403+ // Menu item redirect needs admin client
1404+ $ client = $ component === 'com_menus ' ? '&client_id=0 ' : '' ;
1405+
1406+ if ($ id == 0 )
1407+ {
1408+ $ app ->enqueueMessage (\JText::_ ('JGLOBAL_ASSOCIATIONS_NEW_ITEM_WARNING ' ), 'error ' );
1409+ $ app ->redirect (
1410+ \JRoute::_ ('index.php?option= ' . $ component . '&view= ' . $ view . $ client . '&layout=edit&id= ' . $ id . $ extension , false )
1411+ );
1412+
1413+ return false ;
1414+ }
1415+
1416+ if ($ data ['language ' ] === '* ' )
1417+ {
1418+ $ app ->enqueueMessage (\JText::_ ('JGLOBAL_ASSOC_NOT_POSSIBLE ' ), 'notice ' );
1419+ $ app ->redirect (
1420+ \JRoute::_ ('index.php?option= ' . $ component . '&view= ' . $ view . $ client . '&layout=edit&id= ' . $ id . $ extension , false )
1421+ );
1422+
1423+ return false ;
1424+ }
1425+
1426+ $ languages = LanguageHelper::getContentLanguages (array (0 , 1 ));
1427+ $ target = '' ;
1428+
1429+ /* If the site contains only 2 languages and an association exists for the item
1430+ load directly the associated target item in the side by side view
1431+ otherwise select already the target language
1432+ */
1433+ if (count ($ languages ) === 2 )
1434+ {
1435+ foreach ($ languages as $ language )
1436+ {
1437+ $ lang_code [] = $ language ->lang_code ;
1438+ }
1439+
1440+ $ refLang = array ($ data ['language ' ]);
1441+ $ targetLang = array_diff ($ lang_code , $ refLang );
1442+ $ targetLang = implode (', ' , $ targetLang );
1443+ $ targetId = $ data ['associations ' ][$ targetLang ];
1444+
1445+ if ($ targetId )
1446+ {
1447+ $ target = '&target= ' . $ targetLang . '%3A ' . $ targetId . '%3Aedit ' ;
1448+ }
1449+ else
1450+ {
1451+ $ target = '&target= ' . $ targetLang . '%3A0%3Aadd ' ;
1452+ }
1453+ }
1454+
1455+ $ app ->redirect (
1456+ \JRoute::_ (
1457+ 'index.php?option=com_associations&view=association&layout=edit&itemtype= ' . $ this ->typeAlias
1458+ . '&task=association.edit&id= ' . $ id . $ target , false
1459+ )
1460+ );
1461+ }
1462+
13821463 return true ;
13831464 }
13841465
@@ -1608,90 +1689,12 @@ public function initBatch()
16081689 * @return boolean True if successful, false otherwise.
16091690 *
16101691 * @since 3.9.0
1692+ *
1693+ * @deprecated 5.0 It is handled by regular save method now.
16111694 */
16121695 public function editAssociations ($ data )
16131696 {
16141697 // Save the item
16151698 $ this ->save ($ data );
1616-
1617- $ app = \JFactory::getApplication ();
1618- $ id = $ data ['id ' ];
1619-
1620- // Deal with categories associations
1621- if ($ this ->text_prefix === 'COM_CATEGORIES ' )
1622- {
1623- $ extension = $ app ->input ->get ('extension ' , 'com_content ' );
1624- $ this ->typeAlias = $ extension . '.category ' ;
1625- $ component = strtolower ($ this ->text_prefix );
1626- $ view = 'category ' ;
1627- }
1628- else
1629- {
1630- $ aliasArray = explode ('. ' , $ this ->typeAlias );
1631- $ component = $ aliasArray [0 ];
1632- $ view = $ aliasArray [1 ];
1633- $ extension = '' ;
1634- }
1635-
1636- // Menu item redirect needs admin client
1637- $ client = $ component === 'com_menus ' ? '&client_id=0 ' : '' ;
1638-
1639- if ($ id == 0 )
1640- {
1641- $ app ->enqueueMessage (\JText::_ ('JGLOBAL_ASSOCIATIONS_NEW_ITEM_WARNING ' ), 'error ' );
1642- $ app ->redirect (
1643- \JRoute::_ ('index.php?option= ' . $ component . '&view= ' . $ view . $ client . '&layout=edit&id= ' . $ id . $ extension , false )
1644- );
1645-
1646- return false ;
1647- }
1648-
1649- if ($ data ['language ' ] === '* ' )
1650- {
1651- $ app ->enqueueMessage (\JText::_ ('JGLOBAL_ASSOC_NOT_POSSIBLE ' ), 'notice ' );
1652- $ app ->redirect (
1653- \JRoute::_ ('index.php?option= ' . $ component . '&view= ' . $ view . $ client . '&layout=edit&id= ' . $ id . $ extension , false )
1654- );
1655-
1656- return false ;
1657- }
1658-
1659- $ languages = LanguageHelper::getContentLanguages (array (0 , 1 ));
1660- $ target = '' ;
1661-
1662- /* If the site contains only 2 languages and an association exists for the item
1663- load directly the associated target item in the side by side view
1664- otherwise select already the target language
1665- */
1666- if (count ($ languages ) === 2 )
1667- {
1668- foreach ($ languages as $ language )
1669- {
1670- $ lang_code [] = $ language ->lang_code ;
1671- }
1672-
1673- $ refLang = array ($ data ['language ' ]);
1674- $ targetLang = array_diff ($ lang_code , $ refLang );
1675- $ targetLang = implode (', ' , $ targetLang );
1676- $ targetId = $ data ['associations ' ][$ targetLang ];
1677-
1678- if ($ targetId )
1679- {
1680- $ target = '&target= ' . $ targetLang . '%3A ' . $ targetId . '%3Aedit ' ;
1681- }
1682- else
1683- {
1684- $ target = '&target= ' . $ targetLang . '%3A0%3Aadd ' ;
1685- }
1686- }
1687-
1688- $ app ->redirect (
1689- \JRoute::_ (
1690- 'index.php?option=com_associations&view=association&layout=edit&itemtype= ' . $ this ->typeAlias
1691- . '&task=association.edit&id= ' . $ id . $ target , false
1692- )
1693- );
1694-
1695- return true ;
16961699 }
16971700}
0 commit comments