Skip to content

Commit 0220b8b

Browse files
authored
Code simplify (#32538)
1 parent b11e957 commit 0220b8b

File tree

1 file changed

+19
-33
lines changed

1 file changed

+19
-33
lines changed

components/com_content/src/View/Article/HtmlView.php

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -126,47 +126,33 @@ public function display($tpl = null)
126126
$active = $app->getMenu()->getActive();
127127
$temp = clone $this->params;
128128

129-
// Check to see which parameters should take priority
130-
if ($active)
129+
// Check to see which parameters should take priority. If the active menu item link to the current article, then
130+
// the menu item params take priority
131+
if ($active
132+
&& $active->component == 'com_content'
133+
&& isset($active->query['view'], $active->query['id'])
134+
&& $active->query['view'] == 'article'
135+
&& $active->query['id'] == $item->id)
131136
{
132-
$currentLink = $active->link;
133-
134-
// If the current view is the active item and an article view for this article, then the menu item params take priority
135-
if (strpos($currentLink, 'view=article') && strpos($currentLink, '&id=' . (string) $item->id))
137+
// Load layout from active query (in case it is an alternative menu item)
138+
if (isset($active->query['layout']))
136139
{
137-
// Load layout from active query (in case it is an alternative menu item)
138-
if (isset($active->query['layout']))
139-
{
140-
$this->setLayout($active->query['layout']);
141-
}
142-
// Check for alternative layout of article
143-
elseif ($layout = $item->params->get('article_layout'))
144-
{
145-
$this->setLayout($layout);
146-
}
147-
148-
// $item->params are the article params, $temp are the menu item params
149-
// Merge so that the menu item params take priority
150-
$item->params->merge($temp);
140+
$this->setLayout($active->query['layout']);
151141
}
152-
else
142+
// Check for alternative layout of article
143+
elseif ($layout = $item->params->get('article_layout'))
153144
{
154-
// Current view is not a single article, so the article params take priority here
155-
// Merge the menu item params with the article params so that the article params take priority
156-
$temp->merge($item->params);
157-
$item->params = $temp;
158-
159-
// Check for alternative layouts (since we are not in a single-article menu item)
160-
// Single-article menu item layout takes priority over alt layout for an article
161-
if ($layout = $item->params->get('article_layout'))
162-
{
163-
$this->setLayout($layout);
164-
}
145+
$this->setLayout($layout);
165146
}
147+
148+
// $item->params are the article params, $temp are the menu item params
149+
// Merge so that the menu item params take priority
150+
$item->params->merge($temp);
166151
}
167152
else
168153
{
169-
// Merge so that article params take priority
154+
// The active menu item is not linked to this article, so the article params take priority here
155+
// Merge the menu item params with the article params so that the article params take priority
170156
$temp->merge($item->params);
171157
$item->params = $temp;
172158

0 commit comments

Comments
 (0)