mirror of https://github.com/joomla/joomla-cms.git
Introduce a document aware interface (#40662)
* Introduce a document aware interface * cs ---------
This commit is contained in:
parent
2d9fb9875b
commit
f593ab782d
|
@ -318,7 +318,7 @@ class HtmlView extends BaseHtmlView
|
|||
* Let's put the target src into a variable to use in the javascript code
|
||||
* to avoid race conditions when the reference iframe loads.
|
||||
*/
|
||||
$this->document->addScriptOptions('targetSrc', Route::_($this->editUri . '&task=' . $task . '&id=' . (int) $this->targetId));
|
||||
$this->getDocument()->addScriptOptions('targetSrc', Route::_($this->editUri . '&task=' . $task . '&id=' . (int) $this->targetId));
|
||||
$this->form->setValue('itemlanguage', '', $this->targetLanguage . ':' . $this->targetId . ':' . $this->targetAction);
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ class RawView extends BaseHtmlView
|
|||
throw new GenericDataException(implode("\n", $errors), 500);
|
||||
}
|
||||
|
||||
$this->document->setMimeEncoding($mimeType);
|
||||
$this->getDocument()->setMimeEncoding($mimeType);
|
||||
|
||||
/** @var CMSApplication $app */
|
||||
$app = Factory::getApplication();
|
||||
|
|
|
@ -188,7 +188,7 @@ class HtmlView extends BaseHtmlView
|
|||
|
||||
// Load specific css component
|
||||
/** @var \Joomla\CMS\WebAsset\WebAssetManager $wa */
|
||||
$wa = $this->document->getWebAssetManager();
|
||||
$wa = $this->getDocument()->getWebAssetManager();
|
||||
$wa->getRegistry()->addExtensionRegistryFile($component);
|
||||
|
||||
if ($wa->assetExists('style', $component . '.admin-categories')) {
|
||||
|
|
|
@ -173,7 +173,7 @@ class HtmlView extends BaseHtmlView
|
|||
|
||||
// Load specific css component
|
||||
/** @var \Joomla\CMS\WebAsset\WebAssetManager $wa */
|
||||
$wa = $this->document->getWebAssetManager();
|
||||
$wa = $this->getDocument()->getWebAssetManager();
|
||||
$wa->getRegistry()->addExtensionRegistryFile($component);
|
||||
|
||||
if ($wa->assetExists('style', $component . '.admin-categories')) {
|
||||
|
|
|
@ -53,8 +53,8 @@ class XmlView extends AbstractView
|
|||
$requestId = $model->getState($model->getName() . '.request_id');
|
||||
|
||||
// This document should always be downloaded
|
||||
$this->document->setDownload(true);
|
||||
$this->document->setName('export-request-' . $requestId);
|
||||
$this->getDocument()->setDownload(true);
|
||||
$this->getDocument()->setName('export-request-' . $requestId);
|
||||
|
||||
echo PrivacyHelper::renderDataAsXml($exportData);
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ class JsonapiView extends BaseApiView
|
|||
|
||||
$items = array_splice($items, $offset, $limit);
|
||||
|
||||
$this->document->addMeta('total-pages', $totalPagesAvailable)
|
||||
$this->getDocument()->addMeta('total-pages', $totalPagesAvailable)
|
||||
->addLink('self', (string) $currentUrl);
|
||||
|
||||
// Check for first and previous pages
|
||||
|
@ -76,7 +76,7 @@ class JsonapiView extends BaseApiView
|
|||
$previousPageQuery['offset'] = $previousOffset >= 0 ? $previousOffset : 0;
|
||||
$previousPage->setVar('page', $previousPageQuery);
|
||||
|
||||
$this->document->addLink('first', $this->queryEncode((string) $firstPage))
|
||||
$this->getDocument()->addLink('first', $this->queryEncode((string) $firstPage))
|
||||
->addLink('previous', $this->queryEncode((string) $previousPage));
|
||||
}
|
||||
|
||||
|
@ -93,16 +93,16 @@ class JsonapiView extends BaseApiView
|
|||
$lastPageQuery['offset'] = ($totalPagesAvailable - 1) * $limit;
|
||||
$lastPage->setVar('page', $lastPageQuery);
|
||||
|
||||
$this->document->addLink('next', $this->queryEncode((string) $nextPage))
|
||||
$this->getDocument()->addLink('next', $this->queryEncode((string) $nextPage))
|
||||
->addLink('last', $this->queryEncode((string) $lastPage));
|
||||
}
|
||||
|
||||
$collection = (new Collection($items, new JoomlaSerializer($this->type)));
|
||||
|
||||
// Set the data into the document and render it
|
||||
$this->document->setData($collection);
|
||||
$this->getDocument()->setData($collection);
|
||||
|
||||
return $this->document->render();
|
||||
return $this->getDocument()->render();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -72,7 +72,7 @@ class JsonapiView extends BaseApiView
|
|||
|
||||
$items = array_splice($items, $offset, $limit);
|
||||
|
||||
$this->document->addMeta('total-pages', $totalPagesAvailable)
|
||||
$this->getDocument()->addMeta('total-pages', $totalPagesAvailable)
|
||||
->addLink('self', (string) $currentUrl);
|
||||
|
||||
// Check for first and previous pages
|
||||
|
@ -88,7 +88,7 @@ class JsonapiView extends BaseApiView
|
|||
$previousPageQuery['offset'] = $previousOffset >= 0 ? $previousOffset : 0;
|
||||
$previousPage->setVar('page', $previousPageQuery);
|
||||
|
||||
$this->document->addLink('first', $this->queryEncode((string) $firstPage))
|
||||
$this->getDocument()->addLink('first', $this->queryEncode((string) $firstPage))
|
||||
->addLink('previous', $this->queryEncode((string) $previousPage));
|
||||
}
|
||||
|
||||
|
@ -105,16 +105,16 @@ class JsonapiView extends BaseApiView
|
|||
$lastPageQuery['offset'] = ($totalPagesAvailable - 1) * $limit;
|
||||
$lastPage->setVar('page', $lastPageQuery);
|
||||
|
||||
$this->document->addLink('next', $this->queryEncode((string) $nextPage))
|
||||
$this->getDocument()->addLink('next', $this->queryEncode((string) $nextPage))
|
||||
->addLink('last', $this->queryEncode((string) $lastPage));
|
||||
}
|
||||
|
||||
$collection = (new Collection($items, new JoomlaSerializer($this->type)));
|
||||
|
||||
// Set the data into the document and render it
|
||||
$this->document->setData($collection);
|
||||
$this->getDocument()->setData($collection);
|
||||
|
||||
return $this->document->render();
|
||||
return $this->getDocument()->render();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -77,9 +77,9 @@ class JsonapiView extends BaseApiView
|
|||
->fields([$this->type => $this->fieldsToRenderList]);
|
||||
|
||||
// Set the data into the document and render it
|
||||
$this->document->setData($collection);
|
||||
$this->getDocument()->setData($collection);
|
||||
|
||||
return $this->document->render();
|
||||
return $this->getDocument()->render();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -178,7 +178,7 @@ class JsonapiView extends BaseApiView
|
|||
$collection = (new Collection($items, new JoomlaSerializer('menutypes')));
|
||||
|
||||
// Set the data into the document and render it
|
||||
$this->document->addMeta('total-pages', $totalPagesAvailable)
|
||||
$this->getDocument()->addMeta('total-pages', $totalPagesAvailable)
|
||||
->setData($collection)
|
||||
->addLink('self', (string) $currentUrl)
|
||||
->addLink('first', (string) $firstPage)
|
||||
|
@ -186,7 +186,7 @@ class JsonapiView extends BaseApiView
|
|||
->addLink('previous', (string) $previousPage)
|
||||
->addLink('last', (string) $lastPage);
|
||||
|
||||
return $this->document->render();
|
||||
return $this->getDocument()->render();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -112,9 +112,9 @@ class JsonapiView extends BaseApiView
|
|||
$element = (new Resource($displayItem, $serializer))
|
||||
->fields([$this->type => $this->fieldsToRenderItem]);
|
||||
|
||||
$this->document->setData($element);
|
||||
$this->document->addLink('self', Uri::current());
|
||||
$this->getDocument()->setData($element);
|
||||
$this->getDocument()->addLink('self', Uri::current());
|
||||
|
||||
return $this->document->render();
|
||||
return $this->getDocument()->render();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,9 +65,9 @@ class JsonapiView extends BaseApiView
|
|||
$serializer = new JoomlaSerializer('export');
|
||||
$element = (new Resource($exportData, $serializer));
|
||||
|
||||
$this->document->setData($element);
|
||||
$this->document->addLink('self', Uri::current());
|
||||
$this->getDocument()->setData($element);
|
||||
$this->getDocument()->addLink('self', Uri::current());
|
||||
|
||||
return $this->document->render();
|
||||
return $this->getDocument()->render();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -121,11 +121,11 @@ class HtmlView extends BaseHtmlView
|
|||
$this->setDocumentTitle($params->get('page_title', ''));
|
||||
|
||||
if ($params->get('menu-meta_description')) {
|
||||
$this->document->setDescription($params->get('menu-meta_description'));
|
||||
$this->getDocument()->setDescription($params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($params->get('robots')) {
|
||||
$this->document->setMetaData('robots', $params->get('robots'));
|
||||
$this->getDocument()->setMetaData('robots', $params->get('robots'));
|
||||
}
|
||||
|
||||
// Escape strings for HTML output
|
||||
|
|
|
@ -94,7 +94,7 @@ class HtmlView extends BaseHtmlView
|
|||
$view = $factory->createView('Style', 'Administrator', 'Json');
|
||||
$view->setModel($factory->createModel('Style', 'Administrator'), true);
|
||||
|
||||
$view->document = $this->document;
|
||||
$view->document = $this->getDocument();
|
||||
|
||||
$json = $view->display();
|
||||
|
||||
|
@ -141,11 +141,11 @@ class HtmlView extends BaseHtmlView
|
|||
$this->setDocumentTitle($params->get('page_title', ''));
|
||||
|
||||
if ($params->get('menu-meta_description')) {
|
||||
$this->document->setDescription($params->get('menu-meta_description'));
|
||||
$this->getDocument()->setDescription($params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($params->get('robots')) {
|
||||
$this->document->setMetaData('robots', $params->get('robots'));
|
||||
$this->getDocument()->setMetaData('robots', $params->get('robots'));
|
||||
}
|
||||
|
||||
// Escape strings for HTML output
|
||||
|
|
|
@ -447,20 +447,20 @@ class HtmlView extends BaseHtmlView
|
|||
$this->setDocumentTitle($title);
|
||||
|
||||
if ($this->item->metadesc) {
|
||||
$this->document->setDescription($this->item->metadesc);
|
||||
$this->getDocument()->setDescription($this->item->metadesc);
|
||||
} elseif ($this->params->get('menu-meta_description')) {
|
||||
$this->document->setDescription($this->params->get('menu-meta_description'));
|
||||
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots')) {
|
||||
$this->document->setMetaData('robots', $this->params->get('robots'));
|
||||
$this->getDocument()->setMetaData('robots', $this->params->get('robots'));
|
||||
}
|
||||
|
||||
$mdata = $this->item->metadata->toArray();
|
||||
|
||||
foreach ($mdata as $k => $v) {
|
||||
if ($v) {
|
||||
$this->document->setMetaData($k, $v);
|
||||
$this->getDocument()->setMetaData($k, $v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ class VcfView extends AbstractView
|
|||
throw new GenericDataException(implode("\n", $errors), 500);
|
||||
}
|
||||
|
||||
$this->document->setMimeEncoding('text/directory', true);
|
||||
$this->getDocument()->setMimeEncoding('text/directory', true);
|
||||
|
||||
// Compute lastname, firstname and middlename
|
||||
$item->name = trim($item->name);
|
||||
|
|
|
@ -163,11 +163,11 @@ class HtmlView extends BaseHtmlView
|
|||
$this->setDocumentTitle($this->params->get('page_title', ''));
|
||||
|
||||
if ($this->params->get('menu-meta_description')) {
|
||||
$this->document->setDescription($this->params->get('menu-meta_description'));
|
||||
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots')) {
|
||||
$this->document->setMetaData('robots', $this->params->get('robots'));
|
||||
$this->getDocument()->setMetaData('robots', $this->params->get('robots'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -164,15 +164,15 @@ class HtmlView extends BaseHtmlView
|
|||
$pathway->addItem($title, '');
|
||||
|
||||
if ($this->params->get('menu-meta_description')) {
|
||||
$this->document->setDescription($this->params->get('menu-meta_description'));
|
||||
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('menu-meta_keywords')) {
|
||||
$this->document->setMetaData('keywords', $this->params->get('menu-meta_keywords'));
|
||||
$this->getDocument()->setMetaData('keywords', $this->params->get('menu-meta_keywords'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots')) {
|
||||
$this->document->setMetaData('robots', $this->params->get('robots'));
|
||||
$this->getDocument()->setMetaData('robots', $this->params->get('robots'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -245,11 +245,11 @@ class HtmlView extends BaseHtmlView
|
|||
$this->setDocumentTitle($this->params->get('page_title', ''));
|
||||
|
||||
if ($this->params->get('menu-meta_description')) {
|
||||
$this->document->setDescription($this->params->get('menu-meta_description'));
|
||||
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots')) {
|
||||
$this->document->setMetaData('robots', $this->params->get('robots'));
|
||||
$this->getDocument()->setMetaData('robots', $this->params->get('robots'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -310,25 +310,25 @@ class HtmlView extends BaseHtmlView
|
|||
$this->setDocumentTitle($title);
|
||||
|
||||
if ($this->item->metadesc) {
|
||||
$this->document->setDescription($this->item->metadesc);
|
||||
$this->getDocument()->setDescription($this->item->metadesc);
|
||||
} elseif ($this->params->get('menu-meta_description')) {
|
||||
$this->document->setDescription($this->params->get('menu-meta_description'));
|
||||
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots')) {
|
||||
$this->document->setMetaData('robots', $this->params->get('robots'));
|
||||
$this->getDocument()->setMetaData('robots', $this->params->get('robots'));
|
||||
}
|
||||
|
||||
if ($app->get('MetaAuthor') == '1') {
|
||||
$author = $this->item->created_by_alias ?: $this->item->author;
|
||||
$this->document->setMetaData('author', $author);
|
||||
$this->getDocument()->setMetaData('author', $author);
|
||||
}
|
||||
|
||||
$mdata = $this->item->metadata->toArray();
|
||||
|
||||
foreach ($mdata as $k => $v) {
|
||||
if ($v) {
|
||||
$this->document->setMetaData($k, $v);
|
||||
$this->getDocument()->setMetaData($k, $v);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -341,7 +341,7 @@ class HtmlView extends BaseHtmlView
|
|||
}
|
||||
|
||||
if ($this->print) {
|
||||
$this->document->setMetaData('robots', 'noindex, nofollow');
|
||||
$this->getDocument()->setMetaData('robots', 'noindex, nofollow');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -154,13 +154,13 @@ class HtmlView extends CategoryView
|
|||
$this->setDocumentTitle($title);
|
||||
|
||||
if ($this->category->metadesc) {
|
||||
$this->document->setDescription($this->category->metadesc);
|
||||
$this->getDocument()->setDescription($this->category->metadesc);
|
||||
} elseif ($this->params->get('menu-meta_description')) {
|
||||
$this->document->setDescription($this->params->get('menu-meta_description'));
|
||||
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots')) {
|
||||
$this->document->setMetaData('robots', $this->params->get('robots'));
|
||||
$this->getDocument()->setMetaData('robots', $this->params->get('robots'));
|
||||
}
|
||||
|
||||
if (!is_object($this->category->metadata)) {
|
||||
|
@ -168,14 +168,14 @@ class HtmlView extends CategoryView
|
|||
}
|
||||
|
||||
if (($app->get('MetaAuthor') == '1') && $this->category->get('author', '')) {
|
||||
$this->document->setMetaData('author', $this->category->get('author', ''));
|
||||
$this->getDocument()->setMetaData('author', $this->category->get('author', ''));
|
||||
}
|
||||
|
||||
$mdata = $this->category->metadata->toArray();
|
||||
|
||||
foreach ($mdata as $k => $v) {
|
||||
if ($v) {
|
||||
$this->document->setMetaData($k, $v);
|
||||
$this->getDocument()->setMetaData($k, $v);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ class FeedView extends AbstractView
|
|||
$feedEmail = $app->get('feed_email', 'none');
|
||||
$siteEmail = $app->get('mailfrom');
|
||||
|
||||
$this->document->link = Route::_('index.php?option=com_content&view=featured');
|
||||
$this->getDocument()->link = Route::_('index.php?option=com_content&view=featured');
|
||||
|
||||
// Get some data from the model
|
||||
$app->getInput()->set('limit', $app->get('feed_limit'));
|
||||
|
@ -109,7 +109,7 @@ class FeedView extends AbstractView
|
|||
$item->description = '<div class="feed-description">' . $description . '</div>';
|
||||
|
||||
// Loads item info into rss array
|
||||
$this->document->addItem($item);
|
||||
$this->getDocument()->addItem($item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -229,20 +229,20 @@ class HtmlView extends BaseHtmlView
|
|||
$this->setDocumentTitle($this->params->get('page_title', ''));
|
||||
|
||||
if ($this->params->get('menu-meta_description')) {
|
||||
$this->document->setDescription($this->params->get('menu-meta_description'));
|
||||
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots')) {
|
||||
$this->document->setMetaData('robots', $this->params->get('robots'));
|
||||
$this->getDocument()->setMetaData('robots', $this->params->get('robots'));
|
||||
}
|
||||
|
||||
// Add feed links
|
||||
if ($this->params->get('show_feed_link', 1)) {
|
||||
$link = '&format=feed&limitstart=';
|
||||
$attribs = ['type' => 'application/rss+xml', 'title' => htmlspecialchars($this->document->getTitle())];
|
||||
$this->document->addHeadLink(Route::_($link . '&type=rss'), 'alternate', 'rel', $attribs);
|
||||
$attribs = ['type' => 'application/atom+xml', 'title' => htmlspecialchars($this->document->getTitle())];
|
||||
$this->document->addHeadLink(Route::_($link . '&type=atom'), 'alternate', 'rel', $attribs);
|
||||
$attribs = ['type' => 'application/rss+xml', 'title' => htmlspecialchars($this->getDocument()->getTitle())];
|
||||
$this->getDocument()->addHeadLink(Route::_($link . '&type=rss'), 'alternate', 'rel', $attribs);
|
||||
$attribs = ['type' => 'application/atom+xml', 'title' => htmlspecialchars($this->getDocument()->getTitle())];
|
||||
$this->getDocument()->addHeadLink(Route::_($link . '&type=atom'), 'alternate', 'rel', $attribs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -223,11 +223,11 @@ class HtmlView extends BaseHtmlView
|
|||
$app->getPathway()->addItem($title);
|
||||
|
||||
if ($this->params->get('menu-meta_description')) {
|
||||
$this->document->setDescription($this->params->get('menu-meta_description'));
|
||||
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots')) {
|
||||
$this->document->setMetaData('robots', $this->params->get('robots'));
|
||||
$this->getDocument()->setMetaData('robots', $this->params->get('robots'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,11 +59,11 @@ class FeedView extends BaseHtmlView
|
|||
|
||||
// Configure the document description.
|
||||
if (!empty($explained)) {
|
||||
$this->document->setDescription(html_entity_decode(strip_tags($explained), ENT_QUOTES, 'UTF-8'));
|
||||
$this->getDocument()->setDescription(html_entity_decode(strip_tags($explained), ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
// Set the document link.
|
||||
$this->document->link = Route::_($query->toUri());
|
||||
$this->getDocument()->link = Route::_($query->toUri());
|
||||
|
||||
// If we don't have any results, we are done.
|
||||
if (empty($results)) {
|
||||
|
@ -82,7 +82,7 @@ class FeedView extends BaseHtmlView
|
|||
$item->date = (int) $result->start_date ? HTMLHelper::_('date', $result->start_date, 'U') : $result->indexdate;
|
||||
|
||||
// Loads item info into RSS array
|
||||
$this->document->addItem($item);
|
||||
$this->getDocument()->addItem($item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -295,13 +295,13 @@ class HtmlView extends BaseHtmlView implements SiteRouterAwareInterface
|
|||
// Configure the document meta-description.
|
||||
if (!empty($this->explained)) {
|
||||
$explained = $this->escape(html_entity_decode(strip_tags($this->explained), ENT_QUOTES, 'UTF-8'));
|
||||
$this->document->setDescription($explained);
|
||||
$this->getDocument()->setDescription($explained);
|
||||
} elseif ($this->params->get('menu-meta_description')) {
|
||||
$this->document->setDescription($this->params->get('menu-meta_description'));
|
||||
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots')) {
|
||||
$this->document->setMetaData('robots', $this->params->get('robots'));
|
||||
$this->getDocument()->setMetaData('robots', $this->params->get('robots'));
|
||||
}
|
||||
|
||||
// Check for OpenSearch
|
||||
|
@ -310,7 +310,7 @@ class HtmlView extends BaseHtmlView implements SiteRouterAwareInterface
|
|||
'opensearch_name',
|
||||
Text::_('COM_FINDER_OPENSEARCH_NAME') . ' ' . $app->get('sitename')
|
||||
);
|
||||
$this->document->addHeadLink(
|
||||
$this->getDocument()->addHeadLink(
|
||||
Uri::getInstance()->toString(['scheme', 'host', 'port']) . Route::_('index.php?option=com_finder&view=search&format=opensearch'),
|
||||
'search',
|
||||
'rel',
|
||||
|
@ -321,14 +321,14 @@ class HtmlView extends BaseHtmlView implements SiteRouterAwareInterface
|
|||
// Add feed link to the document head.
|
||||
if ($this->params->get('show_feed_link', 1) == 1) {
|
||||
// Add the RSS link.
|
||||
$props = ['type' => 'application/rss+xml', 'title' => htmlspecialchars($this->document->getTitle())];
|
||||
$props = ['type' => 'application/rss+xml', 'title' => htmlspecialchars($this->getDocument()->getTitle())];
|
||||
$route = Route::_($this->query->toUri() . '&format=feed&type=rss');
|
||||
$this->document->addHeadLink($route, 'alternate', 'rel', $props);
|
||||
$this->getDocument()->addHeadLink($route, 'alternate', 'rel', $props);
|
||||
|
||||
// Add the ATOM link.
|
||||
$props = ['type' => 'application/atom+xml', 'title' => htmlspecialchars($this->document->getTitle())];
|
||||
$props = ['type' => 'application/atom+xml', 'title' => htmlspecialchars($this->getDocument()->getTitle())];
|
||||
$route = Route::_($this->query->toUri() . '&format=feed&type=atom');
|
||||
$this->document->addHeadLink($route, 'alternate', 'rel', $props);
|
||||
$this->getDocument()->addHeadLink($route, 'alternate', 'rel', $props);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,8 +42,8 @@ class OpensearchView extends AbstractView
|
|||
$app = Factory::getApplication();
|
||||
|
||||
$params = ComponentHelper::getParams('com_finder');
|
||||
$this->document->setShortName($params->get('opensearch_name', $app->get('sitename', '')));
|
||||
$this->document->setDescription($params->get('opensearch_description', $app->get('MetaDesc', '')));
|
||||
$this->getDocument()->setShortName($params->get('opensearch_name', $app->get('sitename', '')));
|
||||
$this->getDocument()->setDescription($params->get('opensearch_description', $app->get('MetaDesc', '')));
|
||||
|
||||
// Prevent any output when OpenSearch Support is disabled
|
||||
if (!$params->get('opensearch', 1)) {
|
||||
|
@ -64,26 +64,26 @@ class OpensearchView extends AbstractView
|
|||
// Add the HTML result view
|
||||
$htmlSearch = new OpensearchUrl();
|
||||
$htmlSearch->template = $baseUrl . Route::_($searchUri, false);
|
||||
$this->document->addUrl($htmlSearch);
|
||||
$this->getDocument()->addUrl($htmlSearch);
|
||||
|
||||
// Add the RSS result view
|
||||
$htmlSearch = new OpensearchUrl();
|
||||
$htmlSearch->template = $baseUrl . Route::_($searchUri . '&format=feed&type=rss', false);
|
||||
$htmlSearch->type = 'application/rss+xml';
|
||||
$this->document->addUrl($htmlSearch);
|
||||
$this->getDocument()->addUrl($htmlSearch);
|
||||
|
||||
// Add the Atom result view
|
||||
$htmlSearch = new OpensearchUrl();
|
||||
$htmlSearch->template = $baseUrl . Route::_($searchUri . '&format=feed&type=atom', false);
|
||||
$htmlSearch->type = 'application/atom+xml';
|
||||
$this->document->addUrl($htmlSearch);
|
||||
$this->getDocument()->addUrl($htmlSearch);
|
||||
|
||||
// Add suggestions URL
|
||||
if ($params->get('show_autosuggest', 1)) {
|
||||
$htmlSearch = new OpensearchUrl();
|
||||
$htmlSearch->template = $baseUrl . Route::_($suggestionsUri, false);
|
||||
$htmlSearch->type = 'application/x-suggestions+json';
|
||||
$this->document->addUrl($htmlSearch);
|
||||
$this->getDocument()->addUrl($htmlSearch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -281,24 +281,24 @@ class HtmlView extends BaseHtmlView
|
|||
$this->setDocumentTitle($title);
|
||||
|
||||
if ($this->item->metadesc) {
|
||||
$this->document->setDescription($this->item->metadesc);
|
||||
$this->getDocument()->setDescription($this->item->metadesc);
|
||||
} elseif ($this->params->get('menu-meta_description')) {
|
||||
$this->document->setDescription($this->params->get('menu-meta_description'));
|
||||
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots')) {
|
||||
$this->document->setMetaData('robots', $this->params->get('robots'));
|
||||
$this->getDocument()->setMetaData('robots', $this->params->get('robots'));
|
||||
}
|
||||
|
||||
if ($app->get('MetaAuthor') == '1') {
|
||||
$this->document->setMetaData('author', $this->item->author);
|
||||
$this->getDocument()->setMetaData('author', $this->item->author);
|
||||
}
|
||||
|
||||
$mdata = $this->item->metadata->toArray();
|
||||
|
||||
foreach ($mdata as $k => $v) {
|
||||
if ($v) {
|
||||
$this->document->setMetaData($k, $v);
|
||||
$this->getDocument()->setMetaData($k, $v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,11 +114,11 @@ class HtmlView extends BaseHtmlView
|
|||
$this->setDocumentTitle($this->params->get('page_title', ''));
|
||||
|
||||
if ($this->params->get('menu-meta_description')) {
|
||||
$this->document->setDescription($this->params->get('menu-meta_description'));
|
||||
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots')) {
|
||||
$this->document->setMetaData('robots', $this->params->get('robots'));
|
||||
$this->getDocument()->setMetaData('robots', $this->params->get('robots'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,11 +114,11 @@ class HtmlView extends BaseHtmlView
|
|||
$this->setDocumentTitle($this->params->get('page_title', ''));
|
||||
|
||||
if ($this->params->get('menu-meta_description')) {
|
||||
$this->document->setDescription($this->params->get('menu-meta_description'));
|
||||
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots')) {
|
||||
$this->document->setMetaData('robots', $this->params->get('robots'));
|
||||
$this->getDocument()->setMetaData('robots', $this->params->get('robots'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,11 +123,11 @@ class HtmlView extends BaseHtmlView
|
|||
$this->setDocumentTitle($this->params->get('page_title', ''));
|
||||
|
||||
if ($this->params->get('menu-meta_description')) {
|
||||
$this->document->setDescription($this->params->get('menu-meta_description'));
|
||||
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots')) {
|
||||
$this->document->setMetaData('robots', $this->params->get('robots'));
|
||||
$this->getDocument()->setMetaData('robots', $this->params->get('robots'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,17 +53,17 @@ class FeedView extends BaseHtmlView
|
|||
$i++;
|
||||
}
|
||||
|
||||
$this->document->link = Route::_('index.php?option=com_tags&view=tag&' . $tagIds);
|
||||
$this->getDocument()->link = Route::_('index.php?option=com_tags&view=tag&' . $tagIds);
|
||||
|
||||
$app->getInput()->set('limit', $app->get('feed_limit'));
|
||||
$siteEmail = $app->get('mailfrom');
|
||||
$fromName = $app->get('fromname');
|
||||
$feedEmail = $app->get('feed_email', 'none');
|
||||
|
||||
$this->document->editor = $fromName;
|
||||
$this->getDocument()->editor = $fromName;
|
||||
|
||||
if ($feedEmail !== 'none') {
|
||||
$this->document->editorEmail = $siteEmail;
|
||||
$this->getDocument()->editorEmail = $siteEmail;
|
||||
}
|
||||
|
||||
// Get some data from the model
|
||||
|
@ -96,7 +96,7 @@ class FeedView extends BaseHtmlView
|
|||
}
|
||||
|
||||
// Loads item info into RSS array
|
||||
$this->document->addItem($feeditem);
|
||||
$this->getDocument()->addItem($feeditem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -279,30 +279,30 @@ class HtmlView extends BaseHtmlView
|
|||
|
||||
foreach ($this->item as $itemElement) {
|
||||
if ($itemElement->metadesc) {
|
||||
$this->document->setDescription($itemElement->metadesc);
|
||||
$this->getDocument()->setDescription($itemElement->metadesc);
|
||||
} elseif ($this->params->get('menu-meta_description')) {
|
||||
$this->document->setDescription($this->params->get('menu-meta_description'));
|
||||
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots')) {
|
||||
$this->document->setMetaData('robots', $this->params->get('robots'));
|
||||
$this->getDocument()->setMetaData('robots', $this->params->get('robots'));
|
||||
}
|
||||
}
|
||||
|
||||
if (count($this->item) === 1) {
|
||||
foreach ($this->item[0]->metadata->toArray() as $k => $v) {
|
||||
if ($v) {
|
||||
$this->document->setMetaData($k, $v);
|
||||
$this->getDocument()->setMetaData($k, $v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->params->get('show_feed_link', 1) == 1) {
|
||||
$link = '&format=feed&limitstart=';
|
||||
$attribs = ['type' => 'application/rss+xml', 'title' => htmlspecialchars($this->document->getTitle())];
|
||||
$this->document->addHeadLink(Route::_($link . '&type=rss'), 'alternate', 'rel', $attribs);
|
||||
$attribs = ['type' => 'application/atom+xml', 'title' => htmlspecialchars($this->document->getTitle())];
|
||||
$this->document->addHeadLink(Route::_($link . '&type=atom'), 'alternate', 'rel', $attribs);
|
||||
$attribs = ['type' => 'application/rss+xml', 'title' => htmlspecialchars($this->getDocument()->getTitle())];
|
||||
$this->getDocument()->addHeadLink(Route::_($link . '&type=rss'), 'alternate', 'rel', $attribs);
|
||||
$attribs = ['type' => 'application/atom+xml', 'title' => htmlspecialchars($this->getDocument()->getTitle())];
|
||||
$this->getDocument()->addHeadLink(Route::_($link . '&type=atom'), 'alternate', 'rel', $attribs);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,18 +35,18 @@ class FeedView extends BaseHtmlView
|
|||
*/
|
||||
public function display($tpl = null)
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$this->document->link = Route::_('index.php?option=com_tags&view=tags');
|
||||
$app = Factory::getApplication();
|
||||
$this->getDocument()->link = Route::_('index.php?option=com_tags&view=tags');
|
||||
|
||||
$app->getInput()->set('limit', $app->get('feed_limit'));
|
||||
$siteEmail = $app->get('mailfrom');
|
||||
$fromName = $app->get('fromname');
|
||||
$feedEmail = $app->get('feed_email', 'none');
|
||||
|
||||
$this->document->editor = $fromName;
|
||||
$this->getDocument()->editor = $fromName;
|
||||
|
||||
if ($feedEmail !== 'none') {
|
||||
$this->document->editorEmail = $siteEmail;
|
||||
$this->getDocument()->editorEmail = $siteEmail;
|
||||
}
|
||||
|
||||
// Get some data from the model
|
||||
|
@ -80,7 +80,7 @@ class FeedView extends BaseHtmlView
|
|||
}
|
||||
|
||||
// Loads item info into RSS array
|
||||
$this->document->addItem($feeditem);
|
||||
$this->getDocument()->addItem($feeditem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -151,23 +151,23 @@ class HtmlView extends BaseHtmlView
|
|||
|
||||
// Set metadata for all tags menu item
|
||||
if ($this->params->get('menu-meta_description')) {
|
||||
$this->document->setDescription($this->params->get('menu-meta_description'));
|
||||
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots')) {
|
||||
$this->document->setMetaData('robots', $this->params->get('robots'));
|
||||
$this->getDocument()->setMetaData('robots', $this->params->get('robots'));
|
||||
}
|
||||
|
||||
// Respect configuration Sitename Before/After for TITLE in views All Tags.
|
||||
$this->setDocumentTitle($this->document->getTitle());
|
||||
$this->setDocumentTitle($this->getDocument()->getTitle());
|
||||
|
||||
// Add alternative feed link
|
||||
if ($this->params->get('show_feed_link', 1) == 1) {
|
||||
$link = '&format=feed&limitstart=';
|
||||
$attribs = ['type' => 'application/rss+xml', 'title' => htmlspecialchars($this->document->getTitle())];
|
||||
$this->document->addHeadLink(Route::_($link . '&type=rss'), 'alternate', 'rel', $attribs);
|
||||
$attribs = ['type' => 'application/atom+xml', 'title' => htmlspecialchars($this->document->getTitle())];
|
||||
$this->document->addHeadLink(Route::_($link . '&type=atom'), 'alternate', 'rel', $attribs);
|
||||
$attribs = ['type' => 'application/rss+xml', 'title' => htmlspecialchars($this->getDocument()->getTitle())];
|
||||
$this->getDocument()->addHeadLink(Route::_($link . '&type=rss'), 'alternate', 'rel', $attribs);
|
||||
$attribs = ['type' => 'application/atom+xml', 'title' => htmlspecialchars($this->getDocument()->getTitle())];
|
||||
$this->getDocument()->addHeadLink(Route::_($link . '&type=atom'), 'alternate', 'rel', $attribs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,11 +149,11 @@ class HtmlView extends BaseHtmlView
|
|||
$this->setDocumentTitle($this->params->get('page_title', ''));
|
||||
|
||||
if ($this->params->get('menu-meta_description')) {
|
||||
$this->document->setDescription($this->params->get('menu-meta_description'));
|
||||
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots')) {
|
||||
$this->document->setMetaData('robots', $this->params->get('robots'));
|
||||
$this->getDocument()->setMetaData('robots', $this->params->get('robots'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -179,11 +179,11 @@ class HtmlView extends BaseHtmlView
|
|||
$this->setDocumentTitle($this->params->get('page_title', ''));
|
||||
|
||||
if ($this->params->get('menu-meta_description')) {
|
||||
$this->document->setDescription($this->params->get('menu-meta_description'));
|
||||
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots')) {
|
||||
$this->document->setMetaData('robots', $this->params->get('robots'));
|
||||
$this->getDocument()->setMetaData('robots', $this->params->get('robots'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -151,11 +151,11 @@ class HtmlView extends BaseHtmlView
|
|||
$this->setDocumentTitle($this->params->get('page_title', ''));
|
||||
|
||||
if ($this->params->get('menu-meta_description')) {
|
||||
$this->document->setDescription($this->params->get('menu-meta_description'));
|
||||
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots')) {
|
||||
$this->document->setMetaData('robots', $this->params->get('robots'));
|
||||
$this->getDocument()->setMetaData('robots', $this->params->get('robots'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,11 +116,11 @@ class HtmlView extends BaseHtmlView
|
|||
$this->setDocumentTitle($this->params->get('page_title', ''));
|
||||
|
||||
if ($this->params->get('menu-meta_description')) {
|
||||
$this->document->setDescription($this->params->get('menu-meta_description'));
|
||||
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots')) {
|
||||
$this->document->setMetaData('robots', $this->params->get('robots'));
|
||||
$this->getDocument()->setMetaData('robots', $this->params->get('robots'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -122,11 +122,11 @@ class HtmlView extends BaseHtmlView
|
|||
$this->setDocumentTitle($this->params->get('page_title', ''));
|
||||
|
||||
if ($this->params->get('menu-meta_description')) {
|
||||
$this->document->setDescription($this->params->get('menu-meta_description'));
|
||||
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots')) {
|
||||
$this->document->setMetaData('robots', $this->params->get('robots'));
|
||||
$this->getDocument()->setMetaData('robots', $this->params->get('robots'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,11 +68,11 @@ class HtmlView extends BaseHtmlView
|
|||
$this->setDocumentTitle($params->get('page_title', ''));
|
||||
|
||||
if ($params->get('menu-meta_description')) {
|
||||
$this->document->setDescription($params->get('menu-meta_description'));
|
||||
$this->getDocument()->setDescription($params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($params->get('robots')) {
|
||||
$this->document->setMetaData('robots', $params->get('robots'));
|
||||
$this->getDocument()->setMetaData('robots', $params->get('robots'));
|
||||
}
|
||||
|
||||
$wrapper = new \stdClass();
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Joomla! Content Management System
|
||||
*
|
||||
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\CMS\Document;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Interface to be implemented by classes depending on a document.
|
||||
*
|
||||
* @since __DEPLOY_VERSION__
|
||||
*/
|
||||
interface DocumentAwareInterface
|
||||
{
|
||||
/**
|
||||
* Set the document to use.
|
||||
*
|
||||
* @param Document $document The document to use.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since __DEPLOY_VERSION__
|
||||
*/
|
||||
public function setDocument(Document $document): void;
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Joomla! Content Management System
|
||||
*
|
||||
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\CMS\Document;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Defines the trait for a document aware class.
|
||||
*
|
||||
* @since __DEPLOY_VERSION__
|
||||
*/
|
||||
trait DocumentAwareTrait
|
||||
{
|
||||
/**
|
||||
* Document
|
||||
*
|
||||
* @var Document
|
||||
* @since __DEPLOY_VERSION__
|
||||
*/
|
||||
private $document;
|
||||
|
||||
/**
|
||||
* Get the Document.
|
||||
*
|
||||
* @return Document
|
||||
*
|
||||
* @since __DEPLOY_VERSION__
|
||||
* @throws \UnexpectedValueException May be thrown if the document has not been set.
|
||||
*/
|
||||
protected function getDocument(): Document
|
||||
{
|
||||
if ($this->document) {
|
||||
return $this->document;
|
||||
}
|
||||
|
||||
throw new \UnexpectedValueException('Document not set in ' . __CLASS__);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the document to use.
|
||||
*
|
||||
* @param Document $document The document to use
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since __DEPLOY_VERSION__
|
||||
*/
|
||||
public function setDocument(Document $document): void
|
||||
{
|
||||
$this->document = $document;
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ namespace Joomla\CMS\MVC\Controller;
|
|||
|
||||
use Joomla\CMS\Application\CMSApplication;
|
||||
use Joomla\CMS\Cache\Exception\CacheExceptionInterface;
|
||||
use Joomla\CMS\Document\DocumentAwareInterface;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Filesystem\Path;
|
||||
use Joomla\CMS\Filter\InputFilter;
|
||||
|
@ -613,7 +614,15 @@ class BaseController implements ControllerInterface, DispatcherAwareInterface
|
|||
$view->setModel($model, true);
|
||||
}
|
||||
|
||||
$view->document = $document;
|
||||
if ($view instanceof DocumentAwareInterface && $document) {
|
||||
$view->setDocument($this->app->getDocument());
|
||||
} else {
|
||||
@trigger_error(
|
||||
'View should implement document aware interface.',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
$view->document = $document;
|
||||
}
|
||||
|
||||
// Display the view
|
||||
if ($cachable && $viewType !== 'feed' && $this->app->get('caching') >= 1) {
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
namespace Joomla\CMS\MVC\View;
|
||||
|
||||
use Joomla\CMS\Document\Document;
|
||||
use Joomla\CMS\Document\DocumentAwareInterface;
|
||||
use Joomla\CMS\Document\DocumentAwareTrait;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
|
||||
|
@ -30,7 +32,7 @@ use Joomla\Event\EventInterface;
|
|||
*
|
||||
* @since 2.5.5
|
||||
*/
|
||||
abstract class AbstractView extends CMSObject implements ViewInterface, DispatcherAwareInterface
|
||||
abstract class AbstractView extends CMSObject implements ViewInterface, DispatcherAwareInterface, DocumentAwareInterface
|
||||
{
|
||||
use DispatcherAwareTrait;
|
||||
|
||||
|
@ -39,6 +41,9 @@ abstract class AbstractView extends CMSObject implements ViewInterface, Dispatch
|
|||
*
|
||||
* @var Document
|
||||
* @since 3.0
|
||||
*
|
||||
* @deprecated __DEPLOY_VERSION__ will be removed in 6.0
|
||||
* Use $this->getDocument() instead
|
||||
*/
|
||||
public $document;
|
||||
|
||||
|
@ -234,6 +239,37 @@ abstract class AbstractView extends CMSObject implements ViewInterface, Dispatch
|
|||
return $this->_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Document.
|
||||
*
|
||||
* @return Document
|
||||
*
|
||||
* @since __DEPLOY_VERSION__
|
||||
* @throws \UnexpectedValueException May be thrown if the document has not been set.
|
||||
*/
|
||||
protected function getDocument(): Document
|
||||
{
|
||||
if ($this->document) {
|
||||
return $this->document;
|
||||
}
|
||||
|
||||
throw new \UnexpectedValueException('Document not set in ' . __CLASS__);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the document to use.
|
||||
*
|
||||
* @param Document $document The document to use
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since __DEPLOY_VERSION__
|
||||
*/
|
||||
public function setDocument(Document $document): void
|
||||
{
|
||||
$this->document = $document;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatches the given event on the internal dispatcher, does a fallback to the global one.
|
||||
*
|
||||
|
|
|
@ -122,11 +122,11 @@ class CategoriesView extends HtmlView
|
|||
$this->setDocumentTitle($this->params->get('page_title', ''));
|
||||
|
||||
if ($this->params->get('menu-meta_description')) {
|
||||
$this->document->setDescription($this->params->get('menu-meta_description'));
|
||||
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots')) {
|
||||
$this->document->setMetaData('robots', $this->params->get('robots'));
|
||||
$this->getDocument()->setMetaData('robots', $this->params->get('robots'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ class CategoryFeedView extends HtmlView
|
|||
public function display($tpl = null)
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$document = Factory::getDocument();
|
||||
$document = $this->getDocument();
|
||||
|
||||
$extension = $app->getInput()->getString('option');
|
||||
$contentType = $extension . '.' . $this->viewName;
|
||||
|
|
|
@ -286,11 +286,11 @@ class CategoryView extends HtmlView
|
|||
$this->setDocumentTitle($this->params->get('page_title', ''));
|
||||
|
||||
if ($this->params->get('menu-meta_description')) {
|
||||
$this->document->setDescription($this->params->get('menu-meta_description'));
|
||||
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots')) {
|
||||
$this->document->setMetaData('robots', $this->params->get('robots'));
|
||||
$this->getDocument()->setMetaData('robots', $this->params->get('robots'));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -305,10 +305,10 @@ class CategoryView extends HtmlView
|
|||
{
|
||||
if ($this->params->get('show_feed_link', 1) == 1) {
|
||||
$link = '&format=feed&limitstart=';
|
||||
$attribs = ['type' => 'application/rss+xml', 'title' => htmlspecialchars($this->document->getTitle())];
|
||||
$this->document->addHeadLink(Route::_($link . '&type=rss'), 'alternate', 'rel', $attribs);
|
||||
$attribs = ['type' => 'application/atom+xml', 'title' => htmlspecialchars($this->document->getTitle())];
|
||||
$this->document->addHeadLink(Route::_($link . '&type=atom'), 'alternate', 'rel', $attribs);
|
||||
$attribs = ['type' => 'application/rss+xml', 'title' => htmlspecialchars($this->getDocument()->getTitle())];
|
||||
$this->getDocument()->addHeadLink(Route::_($link . '&type=rss'), 'alternate', 'rel', $attribs);
|
||||
$attribs = ['type' => 'application/atom+xml', 'title' => htmlspecialchars($this->getDocument()->getTitle())];
|
||||
$this->getDocument()->addHeadLink(Route::_($link . '&type=atom'), 'alternate', 'rel', $attribs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -590,6 +590,6 @@ class HtmlView extends AbstractView implements CurrentUserInterface
|
|||
$title = Text::sprintf('JPAGETITLE', $title, $app->get('sitename'));
|
||||
}
|
||||
|
||||
$this->document->setTitle($title);
|
||||
$this->getDocument()->setTitle($title);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -142,7 +142,7 @@ abstract class JsonApiView extends JsonView
|
|||
// Set up links for pagination
|
||||
$totalItemsCount = ($pagination->pagesTotal * $pagination->limit);
|
||||
|
||||
$this->document->addMeta('total-pages', $pagination->pagesTotal)
|
||||
$this->getDocument()->addMeta('total-pages', $pagination->pagesTotal)
|
||||
->addLink('self', (string) $currentUrl);
|
||||
|
||||
// Check for first and previous pages
|
||||
|
@ -158,7 +158,7 @@ abstract class JsonApiView extends JsonView
|
|||
$previousPageQuery['offset'] = $previousOffset >= 0 ? $previousOffset : 0;
|
||||
$previousPage->setVar('page', $previousPageQuery);
|
||||
|
||||
$this->document->addLink('first', $this->queryEncode((string) $firstPage))
|
||||
$this->getDocument()->addLink('first', $this->queryEncode((string) $firstPage))
|
||||
->addLink('previous', $this->queryEncode((string) $previousPage));
|
||||
}
|
||||
|
||||
|
@ -175,7 +175,7 @@ abstract class JsonApiView extends JsonView
|
|||
$lastPageQuery['offset'] = ($pagination->pagesTotal - 1) * $pagination->limit;
|
||||
$lastPage->setVar('page', $lastPageQuery);
|
||||
|
||||
$this->document->addLink('next', $this->queryEncode((string) $nextPage))
|
||||
$this->getDocument()->addLink('next', $this->queryEncode((string) $nextPage))
|
||||
->addLink('last', $this->queryEncode((string) $lastPage));
|
||||
}
|
||||
|
||||
|
@ -193,9 +193,9 @@ abstract class JsonApiView extends JsonView
|
|||
}
|
||||
|
||||
// Set the data into the document and render it
|
||||
$this->document->setData($collection);
|
||||
$this->getDocument()->setData($collection);
|
||||
|
||||
return $this->document->render();
|
||||
return $this->getDocument()->render();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -246,10 +246,10 @@ abstract class JsonApiView extends JsonView
|
|||
$element->with($eventResult->getAllRelationsToRender());
|
||||
}
|
||||
|
||||
$this->document->setData($element);
|
||||
$this->document->addLink('self', Uri::current());
|
||||
$this->getDocument()->setData($element);
|
||||
$this->getDocument()->addLink('self', Uri::current());
|
||||
|
||||
return $this->document->render();
|
||||
return $this->getDocument()->render();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -96,6 +96,6 @@ class JsonView extends AbstractView
|
|||
$result = json_encode($this->_output);
|
||||
|
||||
// Pushing output to the document
|
||||
$this->document->setBuffer($result);
|
||||
$this->getDocument()->setBuffer($result);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.UnitTest
|
||||
* @subpackage Base
|
||||
*
|
||||
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Tests\Unit\Libraries\Cms\Document;
|
||||
|
||||
use Joomla\CMS\Document\DocumentAwareTrait;
|
||||
use Joomla\CMS\Document\Document;
|
||||
use Joomla\Tests\Unit\UnitTestCase;
|
||||
use UnexpectedValueException;
|
||||
|
||||
/**
|
||||
* Test class for \Joomla\CMS\Document\DocumentAwareTrait
|
||||
*
|
||||
* @package Joomla.UnitTest
|
||||
* @subpackage MVC
|
||||
* @since __DEPLOY_VERSION__
|
||||
*/
|
||||
class DocumentAwareTraitTest extends UnitTestCase
|
||||
{
|
||||
/**
|
||||
* @testdox The user document can be set and accessed by the trait
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since __DEPLOY_VERSION__
|
||||
*/
|
||||
public function testGetSetDocument()
|
||||
{
|
||||
$document = new Document();
|
||||
$trait = new class () {
|
||||
use DocumentAwareTrait;
|
||||
|
||||
public function get(): Document
|
||||
{
|
||||
return $this->getDocument();
|
||||
}
|
||||
};
|
||||
|
||||
$trait->setDocument($document);
|
||||
|
||||
$this->assertEquals($document, $trait->get());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The user document can be set and accessed by the trait
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since __DEPLOY_VERSION__
|
||||
*/
|
||||
public function testGetDocumentThrowsException()
|
||||
{
|
||||
$this->expectException(UnexpectedValueException::class);
|
||||
|
||||
$trait = new class () {
|
||||
use DocumentAwareTrait;
|
||||
|
||||
public function get(): Document
|
||||
{
|
||||
return $this->getDocument();
|
||||
}
|
||||
};
|
||||
|
||||
$trait->get();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue