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

[5.3] Refactoring views to directly call models (com_guidedtours to com_newsfeeds) #44164

Open
wants to merge 8 commits into
base: 5.3-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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 @@ -16,6 +16,7 @@
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\Component\Guidedtours\Administrator\Model\StepModel;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -68,11 +69,14 @@ class HtmlView extends BaseHtmlView
*/
public function display($tpl = null)
{
$this->form = $this->get('Form');
$this->item = $this->get('Item');
$this->state = $this->get('State');
/** @var StepModel $model */
$model = $this->getModel();

if (\count($errors = $this->get('Errors'))) {
$this->form = $model->getForm();
$this->item = $model->getItem();
$this->state = $model->getState();

if (\count($errors = $model->getErrors())) {
throw new GenericDataException(implode("\n", $errors), 500);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\Component\Guidedtours\Administrator\Model\StepsModel;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -82,18 +83,21 @@ class HtmlView extends BaseHtmlView
*/
public function display($tpl = null)
{
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->state = $this->get('State');
$this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters');
/** @var StepsModel $model */
$model = $this->getModel();

if (!\count($this->items) && $this->isEmptyState = $this->get('IsEmptyState')) {
$this->items = $model->getItems();
$this->pagination = $model->getPagination();
$this->state = $model->getState();
$this->filterForm = $model->getFilterForm();
$this->activeFilters = $model->getActiveFilters();

if (!\count($this->items) && $this->isEmptyState = $model->getIsEmptyState()) {
$this->setLayout('emptystate');
}

// Check for errors.
if (\count($errors = $this->get('Errors'))) {
if (\count($errors = $model->getErrors())) {
throw new GenericDataException(implode("\n", $errors), 500);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\Component\Guidedtours\Administrator\Model\TourModel;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -68,11 +69,14 @@ class HtmlView extends BaseHtmlView
*/
public function display($tpl = null)
{
$this->form = $this->get('Form');
$this->item = $this->get('Item');
$this->state = $this->get('State');
/** @var TourModel $model */
$model = $this->getModel();

if (\count($errors = $this->get('Errors'))) {
$this->form = $model->getItem();
$this->item = $model->getItem();
$this->state = $model->getState();

if (\count($errors = $model->getErrors())) {
throw new GenericDataException(implode("\n", $errors), 500);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\Component\Guidedtours\Administrator\Model\ToursModel;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -81,18 +82,21 @@ class HtmlView extends BaseHtmlView
*/
public function display($tpl = null)
{
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->state = $this->get('State');
$this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters');
/** @var ToursModel $model */
$model = $this->getModel();

if (!\count($this->items) && $this->isEmptyState = $this->get('IsEmptyState')) {
$this->items = $model->getItems();
$this->pagination = $model->getPagination();
$this->state = $model->getState();
$this->filterForm = $model->getFilterForm();
$this->activeFilters = $model->getActiveFilters();

if (!\count($this->items) && $this->isEmptyState = $model->getIsEmptyState()) {
$this->setLayout('emptystate');
}

// Check for errors.
if (\count($errors = $this->get('Errors'))) {
if (\count($errors = $model->getErrors())) {
throw new GenericDataException(implode("\n", $errors), 500);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Joomla\Component\Installer\Administrator\View\Discover;

use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\Component\Installer\Administrator\Model\DiscoverModel;
use Joomla\Component\Installer\Administrator\View\Installer\HtmlView as InstallerViewDefault;

// phpcs:disable PSR1.Files.SideEffects
Expand Down Expand Up @@ -75,23 +76,26 @@ class HtmlView extends InstallerViewDefault
*/
public function display($tpl = null)
{
/** @var DiscoverModel $model */
$model = $this->getModel();

// Run discover from the model.
if (!$this->getModel()->checkExtensions()) {
$this->getModel()->discover();
if (!$model->checkExtensions()) {
$model->discover();
}

// Get data from the model.
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters');
$this->items = $model->getItems();
$this->pagination = $model->getPagination();
$this->filterForm = $model->getFilterForm();
$this->activeFilters = $model->getActiveFilters();

if (!\count($this->items) && $this->isEmptyState = $this->get('IsEmptyState')) {
if (!\count($this->items) && $this->isEmptyState = $model->getIsEmptyState()) {
$this->setLayout('emptystate');
}

// Check for errors.
if (\count($errors = $this->get('Errors'))) {
if (\count($errors = $model->getErrors())) {
throw new GenericDataException(implode("\n", $errors), 500);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\Component\Installer\Administrator\Model\InstallerModel;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -71,21 +72,21 @@ public function __construct($config = null)
*/
public function display($tpl = null)
{
/** @var InstallerModel $model */
$model = $this->getModel();

// Get data from the model.
$state = $this->get('State');
$this->state = $state = $model->getState();

// Are there messages to display?
$showMessage = false;
$this->showMessage = false;

if (\is_object($state)) {
$message1 = $state->get('message');
$message2 = $state->get('extension_message');
$showMessage = ($message1 || $message2);
$message1 = $state->get('message');
$message2 = $state->get('extension_message');
$this->showMessage = ($message1 || $message2);
}

$this->showMessage = $showMessage;
$this->state = &$state;

$this->addToolbar();
Copy link
Member

Choose a reason for hiding this comment

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

That change looks a bit strange, can we always expect that the state is a Registry or Object?
If not the reference in line 87 may have a special purpose?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it always is a Registry object, however you are right, the $state in line 79 is wrong. Fixing it now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

Choose a reason for hiding this comment

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

See line 84.

parent::display($tpl);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Joomla\CMS\Language\LanguageHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\Component\Installer\Administrator\Model\LanguagesModel;
use Joomla\Component\Installer\Administrator\View\Installer\HtmlView as InstallerViewDefault;

// phpcs:disable PSR1.Files.SideEffects
Expand Down Expand Up @@ -65,15 +66,18 @@ public function display($tpl = null)
throw new NotAllowed(Text::_('JERROR_ALERTNOAUTHOR'), 403);
}

/** @var LanguagesModel $model */
$model = $this->getModel();

// Get data from the model.
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters');
$this->items = $model->getItems();
$this->pagination = $model->getPagination();
$this->filterForm = $model->getFilterForm();
$this->activeFilters = $model->getActiveFilters();
$this->installedLang = LanguageHelper::getInstalledLanguages();

// Check for errors.
if (\count($errors = $this->get('Errors'))) {
if (\count($errors = $model->getErrors())) {
throw new GenericDataException(implode("\n", $errors), 500);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Joomla\CMS\Helper\ContentHelper;
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\Pagination\Pagination;
use Joomla\Component\Installer\Administrator\Model\ManageModel;
use Joomla\Component\Installer\Administrator\View\Installer\HtmlView as InstallerViewDefault;

// phpcs:disable PSR1.Files.SideEffects
Expand Down Expand Up @@ -73,14 +74,17 @@ class HtmlView extends InstallerViewDefault
*/
public function display($tpl = null)
{
/** @var ManageModel $model */
$model = $this->getModel();

// Get data from the model.
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters');
$this->items = $model->getItems();
$this->pagination = $model->getPagination();
$this->filterForm = $model->getFilterForm();
$this->activeFilters = $model->getActiveFilters();

// Check for errors.
if (\count($errors = $this->get('Errors'))) {
if (\count($errors = $model->getErrors())) {
throw new GenericDataException(implode("\n", $errors), 500);
}

Expand Down
23 changes: 12 additions & 11 deletions administrator/components/com_installer/src/View/Update/HtmlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Joomla\CMS\Language\Text;
use Joomla\CMS\Object\CMSObject;
use Joomla\Component\Installer\Administrator\Helper\InstallerHelper as CmsInstallerHelper;
use Joomla\Component\Installer\Administrator\Model\UpdateModel;
use Joomla\Component\Installer\Administrator\View\Installer\HtmlView as InstallerViewDefault;

// phpcs:disable PSR1.Files.SideEffects
Expand Down Expand Up @@ -81,18 +82,18 @@ class HtmlView extends InstallerViewDefault
*/
public function display($tpl = null)
{
// Get data from the model.
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters');

$paths = new \stdClass();
$paths->first = '';
/** @var UpdateModel $model */
$model = $this->getModel();

$this->paths = &$paths;

if (\count($this->items) === 0 && $this->isEmptyState = $this->get('IsEmptyState')) {
// Get data from the model.
$this->items = $model->getItems();
$this->pagination = $model->getPagination();
$this->filterForm = $model->getFilterForm();
$this->activeFilters = $model->getActiveFilters();
$this->paths = new \stdClass();
$this->paths->first = '';

if (\count($this->items) === 0 && $this->isEmptyState = $model->getIsEmptyState()) {
$this->setLayout('emptystate');
} else {
Factory::getApplication()->enqueueMessage(Text::_('COM_INSTALLER_MSG_WARNINGS_UPDATE_NOTICE'), 'warning');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Joomla\Component\Installer\Administrator\View\Warnings;

use Joomla\Component\Installer\Administrator\Model\WarningsModel;
use Joomla\Component\Installer\Administrator\View\Installer\HtmlView as InstallerViewDefault;

// phpcs:disable PSR1.Files.SideEffects
Expand All @@ -34,7 +35,10 @@ class HtmlView extends InstallerViewDefault
*/
public function display($tpl = null)
{
$this->messages = $this->get('Items');
/** @var WarningsModel $model */
$model = $this->getModel();

$this->messages = $model->getItems();

if (!\count($this->messages)) {
$this->setLayout('emptystate');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

/** @var \Joomla\Component\Installer\Administrator\View\Installer\HtmlView $this */

$state = $this->get('State');
$state = $this->state;
$message1 = $state->get('message');
$message2 = $state->get('extension_message');
?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\CMS\Version;
use Joomla\Component\Joomlaupdate\Administrator\Model\UpdateModel;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -163,20 +164,21 @@ class HtmlView extends BaseHtmlView
*/
public function display($tpl = null)
{
$this->updateInfo = $this->get('UpdateInformation');
$this->selfUpdateAvailable = $this->get('CheckForSelfUpdate');
/** @var UpdateModel $model */
$model = $this->getModel();

// Get results of pre update check evaluations
$model = $this->getModel();
$this->phpOptions = $this->get('PhpOptions');
$this->phpSettings = $this->get('PhpSettings');
$this->nonCoreExtensions = $this->get('NonCoreExtensions');
$this->updateInfo = $model->getUpdateInformation();
$this->selfUpdateAvailable = $model->getCheckForSelfUpdate();
$this->phpOptions = $model->getPhpOptions();
$this->phpSettings = $model->getPhpSettings();
$this->nonCoreExtensions = $model->getNonCoreExtensions();
$this->isDefaultBackendTemplate = (bool) $model->isTemplateActive($this->defaultBackendTemplate);
$nextMajorVersion = Version::MAJOR_VERSION + 1;

// The critical plugins check is only available for major updates.
if (version_compare($this->updateInfo['latest'], (string) $nextMajorVersion, '>=')) {
$this->nonCoreCriticalPlugins = $this->get('NonCorePlugins');
$this->nonCoreCriticalPlugins = $model->getNonCorePlugins();
}

// Set to true if a required PHP option is not ok
Expand All @@ -189,7 +191,7 @@ public function display($tpl = null)
}
}

$this->state = $this->get('State');
$this->state = $model->getState();

$hasUpdate = !empty($this->updateInfo['hasUpdate']);
$hasDownload = isset($this->updateInfo['object']->downloadurl->_data);
Expand Down
Loading