-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Add method to set document head (meta) data #19234
Changes from 5 commits
d7c0df7
3210416
7dba3bd
b0e9847
16c0047
13d9601
a755e1c
5cfdf9b
61629ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,10 @@ | |
|
||
namespace Joomla\CMS\MVC\View; | ||
|
||
use Joomla\CMS\Application\ApplicationHelper; | ||
use Joomla\CMS\Factory; | ||
use Joomla\Registry\Registry; | ||
|
||
defined('JPATH_PLATFORM') or die; | ||
|
||
/** | ||
|
@@ -744,8 +748,8 @@ public function loadHelper($hlp = null) | |
*/ | ||
protected function _setPath($type, $path) | ||
{ | ||
$component = \JApplicationHelper::getComponentName(); | ||
$app = \JFactory::getApplication(); | ||
$component = ApplicationHelper::getComponentName(); | ||
$app = Factory::getApplication(); | ||
|
||
// Clear out the prior search dirs | ||
$this->_path[$type] = array(); | ||
|
@@ -872,4 +876,67 @@ public function setDocumentTitle($title) | |
|
||
$this->document->setTitle($title); | ||
} | ||
|
||
/** | ||
* Method to add some document head data from view's $params property | ||
* | ||
* @return void | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
protected function setDocumentHeadDatas() | ||
{ | ||
if (isset($this->params) && $this->params instanceof Registry) | ||
{ | ||
/* @var Registry $params */ | ||
$params = $this->params; | ||
$app = Factory::getApplication(); | ||
|
||
$title = $params->get('page_title'); | ||
|
||
// Check for empty title and add site name if param is set | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace lines 897-911 with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is my intention to have these lines of code in the method. If this is accepted, we can set all these head data within single method, no need for using setDocumentTitle method anymore |
||
if (empty($title)) | ||
{ | ||
$title = $app->get('sitename'); | ||
} | ||
elseif ($app->get('sitename_pagetitles', 0) == 1) | ||
{ | ||
$title = \JText::sprintf('JPAGETITLE', $app->get('sitename'), $title); | ||
} | ||
elseif ($app->get('sitename_pagetitles', 0) == 2) | ||
{ | ||
$title = \JText::sprintf('JPAGETITLE', $title, $app->get('sitename')); | ||
} | ||
|
||
$this->document->setTitle($title); | ||
|
||
if ($params->get('menu-meta_description')) | ||
{ | ||
$this->document->setDescription($params->get('menu-meta_description')); | ||
} | ||
|
||
if ($params->get('menu-meta_keywords')) | ||
{ | ||
$this->document->setMetadata('keywords', $params->get('menu-meta_keywords')); | ||
} | ||
|
||
if ($params->get('robots')) | ||
{ | ||
$this->document->setMetadata('robots', $params->get('robots')); | ||
} | ||
|
||
$metaData = $this->params->get('metadata'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where can I set this data? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can pass it before calling this method. For your information, we are using it here https://github.com/joomla/joomla-cms/blob/staging/components/com_content/views/category/view.html.php#L250-L258 |
||
|
||
if (is_array($metaData)) | ||
{ | ||
// Remove empty value | ||
$metaData = array_filter($metaData); | ||
|
||
foreach ($metaData as $k => $v) | ||
{ | ||
$this->document->setMetadata($k, $v); | ||
} | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Data
is considered singular/plural. Perhaps change it tosetDocumentHeadData
.