Skip to content

Commit

Permalink
[4.0] Use injected document in component views. (#26327)
Browse files Browse the repository at this point in the history
  • Loading branch information
SharkyKZ authored and wilsonge committed Sep 16, 2019
1 parent 1772741 commit 610b84c
Show file tree
Hide file tree
Showing 33 changed files with 62 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper;
Expand All @@ -22,13 +21,13 @@
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));

Factory::getDocument()->addScriptDeclaration('
$this->document->addScriptDeclaration('
Joomla.submitbutton = function(task)
{
if (task == "actionlogs.exportLogs")
{
Joomla.submitform(task, document.getElementById("exportForm"));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ public function display($tpl = null)
* Let's put the target src into a variable to use in the javascript code
* to avoid race conditions when the reference iframe loads.
*/
$document = Factory::getDocument();
$document->addScriptOptions('targetSrc', Route::_($this->editUri . '&task=' . $task . '&id=' . (int) $this->targetId));
$this->document->addScriptOptions('targetSrc', Route::_($this->editUri . '&task=' . $task . '&id=' . (int) $this->targetId));
$this->form->setValue('itemlanguage', '', $this->targetLanguage . ':' . $this->targetId . ':' . $this->targetAction);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
2 => 'icon-archive',
);

Factory::getDocument()->addScriptOptions('assosiations-modal', ['func' => $function]);
$this->document->addScriptOptions('assosiations-modal', ['func' => $function]);
HTMLHelper::_('script', 'com_associations/admin-associations-modal.min.js', ['version' => 'auto', 'relative' => true]);
?>
<form action="<?php echo Route::_('index.php?option=com_associations&view=associations&layout=modal&tmpl=component&function='
Expand Down
3 changes: 1 addition & 2 deletions administrator/components/com_banners/View/Tracks/RawView.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ public function display($tpl = null): void
throw new GenericDataException(implode("\n", $errors), 500);
}

$document = Factory::getDocument();
$document->setMimeEncoding($mimeType);
$this->document->setMimeEncoding($mimeType);

/** @var CMSApplication $app */
$app = Factory::getApplication();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
if (!empty($editor))
{
// This view is used also in com_menus. Load the xtd script only if the editor is set!
Factory::getDocument()->addScriptOptions('xtd-contacts', array('editor' => $editor));
$this->document->addScriptOptions('xtd-contacts', array('editor' => $editor));
$onclick = "jSelectContact";
}
?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function display($tpl = null)
}
}

Factory::getDocument()->addScriptOptions('articles.transitions', $transitions);
$this->document->addScriptOptions('articles.transitions', $transitions);

$articles = [];

Expand All @@ -155,7 +155,7 @@ public function display($tpl = null)
$articles['article-' . (int) $item->id] = Text::sprintf('COM_CONTENT_STAGE_ARTICLE_TITLE', $this->escape($item->title), (int) $item->id);
}

Factory::getDocument()->addScriptOptions('articles.items', $articles);
$this->document->addScriptOptions('articles.items', $articles);

Text::script('COM_CONTENT_ERROR_CANNOT_PUBLISH');
Text::script('COM_CONTENT_ERROR_CANNOT_UNPUBLISH');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function display($tpl = null)
}
}

Factory::getDocument()->addScriptOptions('articles.transitions', $transitions);
$this->document->addScriptOptions('articles.transitions', $transitions);

$articles = [];

Expand All @@ -134,7 +134,7 @@ public function display($tpl = null)
$articles['article-' . (int) $item->id] = Text::sprintf('COM_CONTENT_STAGE_ARTICLE_TITLE', $this->escape($item->title), (int) $item->id);
}

Factory::getDocument()->addScriptOptions('articles.items', $articles);
$this->document->addScriptOptions('articles.items', $articles);

Text::script('COM_CONTENT_ERROR_CANNOT_PUBLISH');
Text::script('COM_CONTENT_ERROR_CANNOT_UNPUBLISH');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
HTMLHelper::_('behavior.core');
HTMLHelper::_('script', 'com_content/admin-article-pagebreak.min.js', array('version' => 'auto', 'relative' => true));

$document = Factory::getDocument();
$this->eName = Factory::getApplication()->input->getCmd('e_name', '');
$this->eName = preg_replace('#[^A-Z0-9\-\_\[\]]#i', '', $this->eName);
$this->document->setTitle(Text::_('COM_CONTENT_PAGEBREAK_DOC_TITLE'));

$document->setTitle(Text::_('COM_CONTENT_PAGEBREAK_DOC_TITLE'));
?>
<div class="container-popup">
<form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
JS;

// @todo move the script to a file
Factory::getDocument()->addScriptDeclaration($js);
$this->document->addScriptDeclaration($js);

$collection = new \stdClass;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
if (!empty($editor))
{
// This view is used also in com_menus. Load the xtd script only if the editor is set!
Factory::getDocument()->addScriptOptions('xtd-articles', array('editor' => $editor));
$this->document->addScriptOptions('xtd-articles', array('editor' => $editor));
$onclick = "jSelectArticle";
}
?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
JS;

// @todo mode the script to a file
Factory::getDocument()->addScriptDeclaration($js);
$this->document->addScriptDeclaration($js);

$featuredButton = (new ActionButton(['tip_title' => 'JGLOBAL_TOGGLE_FEATURED']))
->addState(0, 'articles.featured', 'unfeatured', 'COM_CONTENT_UNFEATURED')
Expand Down
2 changes: 1 addition & 1 deletion administrator/components/com_fields/tmpl/field/modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

$this->useCoreUI = true;

Factory::getDocument()->addScriptDeclaration("
$this->document->addScriptDeclaration("
Joomla.submitbutton = function(task)
{
if (task == 'field.cancel' || document.formvalidator.isValid(document.getElementById('item-form')))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

HTMLHelper::_('behavior.keepalive');
HTMLHelper::_('script', 'com_finder/indexer.min.js', array('version' => 'auto', 'relative' => true));
Factory::getDocument()->addScriptDeclaration('var msg = "' . Text::_('COM_FINDER_INDEXER_MESSAGE_COMPLETE') . '";');
$this->document->addScriptDeclaration('var msg = "' . Text::_('COM_FINDER_INDEXER_MESSAGE_COMPLETE') . '";');
?>

<div class="text-center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

HTMLHelper::_('script', 'com_joomlaupdate/admin-update-default.js', ['version' => 'auto', 'relative' => true]);

Factory::getDocument()->addScriptOptions(
$this->document->addScriptOptions(
'joomlaupdate',
[
'password' => $password,
Expand Down
2 changes: 1 addition & 1 deletion administrator/components/com_media/tmpl/file/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
'contents' => $this->file->content,
];

Factory::getDocument()->addScriptOptions('com_media', $config);
$this->document->addScriptOptions('com_media', $config);

$this->useCoreUI = true;
?>
Expand Down
3 changes: 1 addition & 2 deletions administrator/components/com_media/tmpl/media/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Joomla\CMS\Toolbar\Toolbar;
use Joomla\CMS\Uri\Uri;

$doc = Factory::getDocument();
$params = ComponentHelper::getParams('com_media');

// Make sure core.js is loaded before media scripts
Expand Down Expand Up @@ -53,6 +52,6 @@
'currentPath' => $this->currentPath,
'isModal' => Factory::getApplication()->input->getCmd('tmpl', '') === 'component' ? true : false,
);
$doc->addScriptOptions('com_media', $config);
$this->document->addScriptOptions('com_media', $config);
?>
<div id="com-media"></div>
2 changes: 1 addition & 1 deletion administrator/components/com_menus/tmpl/item/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
Text::script('ERROR');
Text::script('JGLOBAL_VALIDATION_FORM_FAILED');

Factory::getDocument()->addScriptOptions('menu-item', ['itemId' => (int) $this->item->id]);
$this->document->addScriptOptions('menu-item', ['itemId' => (int) $this->item->id]);
HTMLHelper::_('script', 'com_menus/admin-item-edit.min.js', ['version' => 'auto', 'relative' => true]);

// Ajax for parent items
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
$allLevels[$value->id] = $value->title;
}

Factory::getDocument()->addScriptOptions('menus-edit-modules', ['viewLevels' => $allLevels, 'itemId' => $this->item->id]);
$this->document->addScriptOptions('menus-edit-modules', ['viewLevels' => $allLevels, 'itemId' => $this->item->id]);
HTMLHelper::_('stylesheet', 'com_menus/admin-item-edit_modules.css', array('version' => 'auto', 'relative' => true));
HTMLHelper::_('script', 'com_menus/admin-item-edit_modules.min.js', array('version' => 'auto', 'relative' => true));

Expand Down
2 changes: 1 addition & 1 deletion administrator/components/com_menus/tmpl/items/modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
if (!empty($editor))
{
// This view is used also in com_menus. Load the xtd script only if the editor is set!
Factory::getDocument()->addScriptOptions('xtd-menus', array('editor' => $editor));
$this->document->addScriptOptions('xtd-menus', array('editor' => $editor));
$onclick = "jSelectMenuItem";
$link = 'index.php?option=com_menus&view=items&layout=modal&tmpl=component&editor=' . $editor . '&' . Session::getFormToken() . '=1';
}
Expand Down
2 changes: 1 addition & 1 deletion administrator/components/com_menus/tmpl/menus/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
}
}

Factory::getDocument()->addScriptOptions('menus-default', ['items' => $itemIds]);
$this->document->addScriptOptions('menus-default', ['items' => $itemIds]);
HTMLHelper::_('jquery.framework');
HTMLHelper::_('script', 'com_menus/admin-menus-default.min.js', array('version' => 'auto', 'relative' => true));
?>
Expand Down
2 changes: 1 addition & 1 deletion administrator/components/com_modules/tmpl/module/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
Text::script('JALL');
Text::script('JTRASHED');

Factory::getDocument()->addScriptOptions('module-edit', ['itemId' => $this->item->id, 'state' => (int) $this->item->id == 0 ? 'Add' : 'Edit']);
$this->document->addScriptOptions('module-edit', ['itemId' => $this->item->id, 'state' => (int) $this->item->id == 0 ? 'Add' : 'Edit']);
HTMLHelper::_('script', 'com_modules/admin-module-edit.min.js', array('version' => 'auto', 'relative' => true));

$input = Factory::getApplication()->input;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
Text::script('JGLOBAL_SELECT_NO_RESULTS_MATCH');
Text::script('JGLOBAL_SELECT_PRESS_TO_SELECT');

Factory::getDocument()->getWebAssetManager()->enableAsset('choicesjs');
$this->document->getWebAssetManager()->enableAsset('choicesjs');
HTMLHelper::_('webcomponent', 'system/fields/joomla-field-fancy-select.min.js', ['version' => 'auto', 'relative' => true]);

?>
Expand Down
2 changes: 0 additions & 2 deletions administrator/components/com_modules/tmpl/select/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;

$document = Factory::getDocument();

$app = Factory::getApplication();

$function = $app->input->getCmd('function');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Joomla\CMS\Router\Route;

$lang = Factory::getLanguage();
$renderer = Factory::getDocument()->loadRenderer('module');
$renderer = $this->document->loadRenderer('module');
$options = array('style' => 'raw');
$mod = ModuleHelper::getModule('mod_feed');
$param = array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
};
JS;

Factory::getDocument()->addScriptDeclaration($js);
$this->document->addScriptDeclaration($js);
?>

<form action="<?php echo Route::_('index.php?option=com_privacy&view=request&id=' . (int) $this->item->id); ?>" method="post" name="adminForm" id="item-form" class="form-validate">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

if ($this->type == 'font')
{
Factory::getDocument()->addStyleDeclaration("
$this->document->addStyleDeclaration("
@font-face {
font-family: previewFont;
src: url('" . $this->font['address'] . "')
Expand Down
2 changes: 1 addition & 1 deletion components/com_contact/View/Contact/VcfView.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function display($tpl = null)
throw new GenericDataException(implode("\n", $errors), 500);
}

Factory::getDocument()->setMimeEncoding('text/directory', true);
$this->document->setMimeEncoding('text/directory', true);

// Compute lastname, firstname and middlename
$item->name = trim($item->name);
Expand Down
6 changes: 3 additions & 3 deletions components/com_content/View/Featured/FeedView.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public function display($tpl = null)
{
// Parameters
$app = Factory::getApplication();
$doc = Factory::getDocument();
$params = $app->getParams();
$feedEmail = $app->get('feed_email', 'none');
$siteEmail = $app->get('mailfrom');
$doc->link = Route::_('index.php?option=com_content&view=featured');

$this->document->link = Route::_('index.php?option=com_content&view=featured');

// Get some data from the model
$app->input->set('limit', $app->get('feed_limit'));
Expand Down Expand Up @@ -123,7 +123,7 @@ public function display($tpl = null)
$item->description = '<div class="feed-description">' . $description . '</div>';

// Loads item info into rss array
$doc->addItem($item);
$this->document->addItem($item);
}
}
}
3 changes: 1 addition & 2 deletions components/com_content/tmpl/categories/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper;
Expand Down Expand Up @@ -49,7 +48,7 @@
JS;

// @todo move script to a file
Factory::getDocument()->addScriptDeclaration($js);
$this->document->addScriptDeclaration($js);
?>
<div class="com-content-categories categories-list">
<?php
Expand Down
2 changes: 1 addition & 1 deletion components/com_finder/View/Search/HtmlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ protected function prepareDocument($query)
$ostitle = $this->params->get('opensearch_name',
Text::_('COM_FINDER_OPENSEARCH_NAME') . ' ' . Factory::getApplication()->get('sitename')
);
Factory::getDocument()->addHeadLink(
$this->document->addHeadLink(
Uri::getInstance()->toString(array('scheme', 'host', 'port')) . Route::_('index.php?option=com_finder&view=search&format=opensearch'),
'search', 'rel', array('title' => $ostitle, 'type' => 'application/opensearchdescription+xml')
);
Expand Down
13 changes: 6 additions & 7 deletions components/com_finder/View/Search/OpensearchView.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ class OpensearchView extends AbstractView
*/
public function display($tpl = null)
{
$doc = Factory::getDocument();
$app = Factory::getApplication();

$params = ComponentHelper::getParams('com_finder');
$doc->setShortName($params->get('opensearch_name', $app->get('sitename')));
$doc->setDescription($params->get('opensearch_description', $app->get('MetaDesc')));
$this->document->setShortName($params->get('opensearch_name', $app->get('sitename')));
$this->document->setDescription($params->get('opensearch_description', $app->get('MetaDesc')));

// Prevent any output when OpenSearch Support is disabled
if (!$params->get('opensearch', 1))
Expand All @@ -64,27 +63,27 @@ public function display($tpl = null)
// Add the HTML result view
$htmlSearch = new OpenSearchUrl;
$htmlSearch->template = $baseUrl . Route::_($searchUri, false);
$doc->addUrl($htmlSearch);
$this->document->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';
$doc->addUrl($htmlSearch);
$this->document->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';
$doc->addUrl($htmlSearch);
$this->document->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';
$doc->addUrl($htmlSearch);
$this->document->addUrl($htmlSearch);
}
}
}

0 comments on commit 610b84c

Please sign in to comment.