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 (frontend) #44170

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 5 additions & 3 deletions components/com_config/src/View/Modules/HtmlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Joomla\CMS\Form\Form;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\Component\Config\Site\Model\ModulesModel;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -71,9 +72,10 @@ public function display($tpl = null)
// Need to add module name to the state of model
$model->getState()->set('module.name', $moduleData['module']);

/** @var Form form */
$this->form = $this->get('form');
$this->positions = $this->get('positions');
/** @var ModulesModel $model */
$model = $this->getModel();
$this->form = $model->getForm();
$this->positions = $model->getPositions();
$this->item = $moduleData;

if ($this->form) {
Expand Down
11 changes: 7 additions & 4 deletions components/com_contact/src/View/Contact/HtmlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Joomla\CMS\User\UserFactoryAwareInterface;
use Joomla\CMS\User\UserFactoryAwareTrait;
use Joomla\Component\Contact\Site\Helper\RouteHelper;
use Joomla\Component\Contact\Site\Model\ContactModel;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -136,11 +137,13 @@ class HtmlView extends BaseHtmlView implements UserFactoryAwareInterface
*/
public function display($tpl = null)
{
/** @var ContactModel $model */
$model = $this->getModel();
$app = Factory::getApplication();
$user = $this->getCurrentUser();
$state = $this->get('State');
$item = $this->get('Item');
$this->form = $this->get('Form');
$state = $model->getState();
$item = $model->getItem();
$this->form = $model->getForm();
$params = $state->get('params');
$contacts = [];

Expand Down Expand Up @@ -193,7 +196,7 @@ public function display($tpl = null)
}

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

Expand Down
8 changes: 5 additions & 3 deletions components/com_contact/src/View/Contact/VcfView.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\View\AbstractView;
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\Component\Contact\Site\Model\ContactModel;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -43,11 +44,12 @@ class VcfView extends AbstractView
*/
public function display($tpl = null)
{
// Get model data.
$item = $this->get('Item');
/** @var ContactModel $model */
$model = $this->getModel();
$item = $model->getItem();

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

Expand Down
12 changes: 7 additions & 5 deletions components/com_contact/src/View/Featured/HtmlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Joomla\CMS\Mail\MailHelper;
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\Component\Contact\Site\Model\FeaturedModel;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -87,19 +88,20 @@ public function display($tpl = null)
$app = Factory::getApplication();
$params = $app->getParams();

// Get some data from the models
$state = $this->get('State');
$items = $this->get('Items');
/** @var FeaturedModel $model */
$model = $this->getModel();
$state = $model->getState();
$items = $model->getItems();
$category = $this->get('Category');
$children = $this->get('Children');
$parent = $this->get('Parent');
$pagination = $this->get('Pagination');
$pagination = $model->getPagination();

// Flag indicates to not add limitstart=0 to URL
$pagination->hideEmptyLimitstart = true;

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

Expand Down
14 changes: 8 additions & 6 deletions components/com_contact/src/View/Form/HtmlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\Component\Contact\Administrator\Helper\ContactHelper;
use Joomla\Component\Contact\Site\Model\FormModel;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -79,11 +80,12 @@ public function display($tpl = null)
$user = $this->getCurrentUser();
$app = Factory::getApplication();

// Get model data.
$this->state = $this->get('State');
$this->item = $this->get('Item');
$this->form = $this->get('Form');
$this->return_page = $this->get('ReturnPage');
/** @var FormModel $model */
$model = $this->getModel();
$this->state = $model->getState();
$this->item = $model->getItem();
$this->form = $model->getForm();
$this->return_page = $model->getReturnPage();

if (empty($this->item->id)) {
$authorised = $user->authorise('core.create', 'com_contact') || \count($user->getAuthorisedCategories('com_contact', 'core.create'));
Expand All @@ -107,7 +109,7 @@ public function display($tpl = null)
}

// Check for errors.
if (\count($errors = $this->get('Errors'))) {
if (\count($errors = $model->getErrors())) {
$app->enqueueMessage(implode("\n", $errors), 'error');

return false;
Expand Down
11 changes: 7 additions & 4 deletions components/com_content/src/View/Archive/HtmlView.php
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\Plugin\PluginHelper;
use Joomla\Component\Content\Site\Model\ArchiveModel;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -115,13 +116,15 @@ class HtmlView extends BaseHtmlView
*/
public function display($tpl = null)
{
/** @var ArchiveModel $model */
$model = $this->getModel();
$app = Factory::getApplication();
$user = $this->getCurrentUser();
$state = $this->get('State');
$items = $this->get('Items');
$pagination = $this->get('Pagination');
$state = $model->getState();
$items = $model->getItems();
$pagination = $model->getPagination();

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

Expand Down
9 changes: 6 additions & 3 deletions components/com_content/src/View/Article/HtmlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Joomla\CMS\Uri\Uri;
use Joomla\Component\Content\Site\Helper\AssociationHelper;
use Joomla\Component\Content\Site\Helper\RouteHelper;
use Joomla\Component\Content\Site\Model\ArticleModel;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -107,13 +108,15 @@ public function display($tpl = null)
$app = Factory::getApplication();
$user = $this->getCurrentUser();

$this->item = $this->get('Item');
/** @var ArticleModel $model */
$model = $this->getModel();
$this->item = $model->getItem();
$this->print = $app->getInput()->getBool('print', false);
$this->state = $this->get('State');
$this->state = $model->getState();
$this->user = $user;

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

Expand Down
6 changes: 5 additions & 1 deletion components/com_content/src/View/Featured/FeedView.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Joomla\CMS\MVC\View\AbstractView;
use Joomla\CMS\Router\Route;
use Joomla\Component\Content\Site\Helper\RouteHelper;
use Joomla\Component\Content\Site\Model\FeaturedModel;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -55,7 +56,10 @@ public function display($tpl = null)
// Get some data from the model
$app->getInput()->set('limit', $app->get('feed_limit'));
$categories = Categories::getInstance('Content');
$rows = $this->get('Items');

/** @var FeaturedModel $model */
$model = $this->getModel();
$rows = $model->getItems();

foreach ($rows as $row) {
// Strip html from feed item title
Expand Down
13 changes: 8 additions & 5 deletions components/com_content/src/View/Featured/HtmlView.php
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\Plugin\PluginHelper;
use Joomla\CMS\Router\Route;
use Joomla\Component\Content\Site\Model\FeaturedModel;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -117,20 +118,22 @@ public function display($tpl = null)
{
$user = $this->getCurrentUser();

$state = $this->get('State');
$items = $this->get('Items');
$pagination = $this->get('Pagination');
/** @var FeaturedModel $model */
$model = $this->getModel();
$state = $model->getState();
$items = $model->getItems();
$pagination = $model->getPagination();

// Flag indicates to not add limitstart=0 to URL
$pagination->hideEmptyLimitstart = true;

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

/** @var \Joomla\Registry\Registry $params */
$params = &$state->params;
$params = $state->params;

// PREPARE THE DATA

Expand Down
14 changes: 8 additions & 6 deletions components/com_content/src/View/Form/HtmlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Component\Content\Site\Model\FormModel;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -113,11 +114,12 @@ public function display($tpl = null)
$app = Factory::getApplication();
$user = $app->getIdentity();

// Get model data.
$this->state = $this->get('State');
$this->item = $this->get('Item');
$this->form = $this->get('Form');
$this->return_page = $this->get('ReturnPage');
/** @var FormModel $model */
$model = $this->getModel();
$this->state = $model->getState();
$this->item = $model->getItem();
$this->form = $model->getForm();
$this->return_page = $model->getReturnPage();

if (empty($this->item->id)) {
$catid = $this->state->params->get('catid');
Expand Down Expand Up @@ -153,7 +155,7 @@ public function display($tpl = null)
}

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

Expand Down
11 changes: 6 additions & 5 deletions components/com_finder/src/View/Search/FeedView.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Router\Route;
use Joomla\Component\Finder\Site\Model\SearchModel;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -45,12 +46,12 @@ public function display($tpl = null)
// Adjust the list limit to the feed limit.
$app->getInput()->set('limit', $app->get('feed_limit'));

// Get view data.
$state = $this->get('State');
/** @var SearchModel $model */
$model = $this->getModel();
$state = $model->getState();
$params = $state->get('params');
$query = $this->get('Query');
$results = $this->get('Items');
$total = $this->get('Total');
$query = $model->getQuery();
$results = $model->getItems();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is $total = $this->get('Total'); removed?

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't used so no need to carry the value

Copy link
Contributor

Choose a reason for hiding this comment

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

ok.. thx


// If the feed has been disabled, we want to bail out here
if ($params->get('show_feed_link', 1) == 0) {
Expand Down
18 changes: 11 additions & 7 deletions components/com_finder/src/View/Search/HtmlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Joomla\CMS\Uri\Uri;
use Joomla\Component\Finder\Administrator\Indexer\Query;
use Joomla\Component\Finder\Site\Helper\FinderHelper;
use Joomla\Component\Finder\Site\Model\SearchModel;
use Joomla\Filesystem\Path;

// phpcs:disable PSR1.Files.SideEffects
Expand Down Expand Up @@ -138,17 +139,20 @@ public function display($tpl = null)
$app = Factory::getApplication();
$this->params = $app->getParams();

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

// Get view data.
$this->state = $this->get('State');
$this->query = $this->get('Query');
$this->state = $model->getState();
$this->query = $model->getQuery();
\JDEBUG ? Profiler::getInstance('Application')->mark('afterFinderQuery') : null;
$this->results = $this->get('Items');
$this->results = $model->getItems();
\JDEBUG ? Profiler::getInstance('Application')->mark('afterFinderResults') : null;
$this->sortOrderFields = $this->get('sortOrderFields');
$this->sortOrderFields = $model->getSortOrderFields();
\JDEBUG ? Profiler::getInstance('Application')->mark('afterFinderSortOrderFields') : null;
$this->total = $this->get('Total');
$this->total = $model->getTotal();
\JDEBUG ? Profiler::getInstance('Application')->mark('afterFinderTotal') : null;
$this->pagination = $this->get('Pagination');
$this->pagination = $model->getPagination();
\JDEBUG ? Profiler::getInstance('Application')->mark('afterFinderPagination') : null;

// Flag indicates to not add limitstart=0 to URL
Expand Down Expand Up @@ -181,7 +185,7 @@ public function display($tpl = null)
}

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

Expand Down
10 changes: 6 additions & 4 deletions components/com_newsfeeds/src/View/Newsfeed/HtmlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\Component\Newsfeeds\Site\Helper\RouteHelper;
use Joomla\Component\Newsfeeds\Site\Model\NewsfeedModel;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -101,13 +102,14 @@ public function display($tpl = null)
// Get view related request variables.
$print = $app->getInput()->getBool('print');

// Get model data.
$state = $this->get('State');
$item = $this->get('Item');
/** @var NewsfeedModel $model */
$model = $this->getModel();
$state = $model->getState();
$item = $model->getItem();

// Check for errors.
// @TODO: Maybe this could go into ComponentHelper::raiseErrors($this->get('Errors'))
if (\count($errors = $this->get('Errors'))) {
if (\count($errors = $model->getErrors())) {
throw new GenericDataException(implode("\n", $errors), 500);
}

Expand Down
Loading