Back to AdminModel class

Method redirectToAssociations

protected bool
redirectToAssociations
(mixed $data)
Method to load an item in com_associations.
Parameters
  • array $data The form data.
Returns
  • bool True if successful, false otherwise.
Since
  • 3.9.17
-
  • \Exception
Class: AdminModel
Project: Joomla

Method redirectToAssociations - Source code

/**
 * Method to load an item in com_associations.
 *
 * @param   array  $data  The form data.
 *
 * @return  boolean  True if successful, false otherwise.
 *
 * @throws \Exception
 * @since   3.9.17
 */
protected function redirectToAssociations($data)
{
    $app = Factory::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(Text::_('JGLOBAL_ASSOCIATIONS_NEW_ITEM_WARNING'), 'error');
        $app->redirect(Route::_('index.php?option=' . $component . '&view=' . $view . $client . '&layout=edit&id=' . $id . $extension, false));
        return false;
    }
    if ($data['language'] === '*') {
        $app->enqueueMessage(Text::_('JGLOBAL_ASSOC_NOT_POSSIBLE'), 'notice');
        $app->redirect(Route::_('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(Route::_('index.php?option=com_associations&view=association&layout=edit&itemtype=' . $this->typeAlias . '&task=association.edit&id=' . $id . $target, false));
    return true;
}