Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[com_content] Correctly adding layout to links #20211

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ abstract class CategoryHelperAssociation
*
* @param integer $id Id of the item
* @param string $extension Name of the component
* @param string $layout Category layout
*
* @return array Array of associations for the component categories
*
* @since 3.0
*/
public static function getCategoryAssociations($id = 0, $extension = 'com_content')
public static function getCategoryAssociations($id = 0, $extension = 'com_content', $layout = null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it correct that this is hardcoded to com_content? if it is then the docblock is now wong

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a default value, not a hardcoded lock.

Copy link
Contributor Author

@Septdir Septdir Apr 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brianteeman No, I did this not only for com_content, but for the subsequent move in all components to pass layout to form the correct reference.
For example, in com_contacts or in third-party extensions that use com_categories
And it's isn't a hardcoded lock

As I wrote earlier this foundation. @mbabker is right if layout is used in menu items, it must be in links.

{
$return = array();

Expand All @@ -46,11 +47,11 @@ public static function getCategoryAssociations($id = 0, $extension = 'com_conten
{
if (class_exists($helperClassname) && is_callable(array($helperClassname, 'getCategoryRoute')))
{
$return[$tag] = $helperClassname::getCategoryRoute($item, $tag);
$return[$tag] = $helperClassname::getCategoryRoute($item, $tag, $layout);
}
else
{
$return[$tag] = 'index.php?option=' . $extension . '&view=category&id=' . $item;
$return[$tag] = 'index.php?option=' . $extension . '&view=category&id=' . $item . '&layout=' . $layout;
}
}
}
Expand Down
30 changes: 7 additions & 23 deletions components/com_content/helpers/association.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ abstract class ContentHelperAssociation extends CategoryHelperAssociation
/**
* Method to get the associations for a given item
*
* @param integer $id Id of the item
* @param string $view Name of the view
* @param integer $id Id of the item
* @param string $view Name of the view
* @param string $layout View layout
*
* @return array Array of associations for the item
*
* @since 3.0
*/
public static function getAssociations($id = 0, $view = null)
public static function getAssociations($id = 0, $view = null, $layout = null)
{
$jinput = JFactory::getApplication()->input;
$view = $view === null ? $jinput->get('view') : $view;
$layout = $layout === null ? $jinput->get('layout', '', 'string') : $layout;
$id = empty($id) ? $jinput->getInt('id') : $id;
$user = JFactory::getUser();
$groups = implode(',', $user->getAuthorisedViewLevels());

if ($view === 'article')
{
Expand All @@ -50,23 +50,7 @@ public static function getAssociations($id = 0, $view = null)
{
if ($item->language != JFactory::getLanguage()->getTag())
{
$arrId = explode(':', $item->id);
$assocId = $arrId[0];

$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->qn('state'))
->from($db->qn('#__content'))
->where($db->qn('id') . ' = ' . (int) ($assocId))
->where('access IN (' . $groups . ')');
$db->setQuery($query);

$result = (int) $db->loadResult();

if ($result > 0)
{
$return[$tag] = ContentHelperRoute::getArticleRoute($item->id, (int) $item->catid, $item->language);
}
$return[$tag] = ContentHelperRoute::getArticleRoute($item->id, (int) $item->catid, $item->language, $layout);
}
}

Expand All @@ -76,7 +60,7 @@ public static function getAssociations($id = 0, $view = null)

if ($view === 'category' || $view === 'categories')
{
return self::getCategoryAssociations($id, 'com_content');
return self::getCategoryAssociations($id, 'com_content', $layout);
}

return array();
Expand Down
16 changes: 10 additions & 6 deletions components/com_content/helpers/route.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ abstract class ContentHelperRoute
* @param integer $id The route of the content item.
* @param integer $catid The category ID.
* @param integer $language The language code.
* @param string $layout The Article layout
*
* @return string The article route.
*
* @since 1.5
*/
public static function getArticleRoute($id, $catid = 0, $language = 0)
public static function getArticleRoute($id, $catid = 0, $language = 0, $layout = null)
{
// Create the link
$link = 'index.php?option=com_content&view=article&id=' . $id;
Expand All @@ -42,6 +43,11 @@ public static function getArticleRoute($id, $catid = 0, $language = 0)
$link .= '&lang=' . $language;
}

if ($layout)
{
$link .= '&layout=' . $layout;
}

return $link;
}

Expand All @@ -50,12 +56,13 @@ public static function getArticleRoute($id, $catid = 0, $language = 0)
*
* @param integer $catid The category ID.
* @param integer $language The language code.
* @param string $layout The category layout
*
* @return string The article route.
*
* @since 1.5
*/
public static function getCategoryRoute($catid, $language = 0)
public static function getCategoryRoute($catid, $language = 0, $layout = null)
{
if ($catid instanceof JCategoryNode)
{
Expand All @@ -79,10 +86,7 @@ public static function getCategoryRoute($catid, $language = 0)
$link .= '&lang=' . $language;
}

$jinput = JFactory::getApplication()->input;
$layout = $jinput->get('layout');

if ($layout !== '')
if ($layout)
{
$link .= '&layout=' . $layout;
}
Expand Down