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

Revert "[5.2] Remove legacy code for filtering state in backend model… #43918

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ protected function populateState($ordering = 'ordering', $direction = 'asc')
$this->setState('itemtype', $this->getUserStateFromRequest($this->context . '.itemtype', 'itemtype', '', 'string'));
$this->setState('language', $this->getUserStateFromRequest($this->context . '.language', 'language', '', 'string'));

$this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string'));
$this->setState('filter.state', $this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state', '', 'cmd'));
$this->setState('filter.category_id', $this->getUserStateFromRequest($this->context . '.filter.category_id', 'filter_category_id', '', 'cmd'));
$this->setState('filter.menutype', $this->getUserStateFromRequest($this->context . '.filter.menutype', 'filter_menutype', '', 'string'));
$this->setState('filter.access', $this->getUserStateFromRequest($this->context . '.filter.access', 'filter_access', '', 'string'));
$this->setState('filter.level', $this->getUserStateFromRequest($this->context . '.filter.level', 'filter_level', '', 'cmd'));

// List state information.
parent::populateState($ordering, $direction);

Expand Down
3 changes: 3 additions & 0 deletions administrator/components/com_cache/src/Model/CacheModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public function __construct($config = [])
*/
protected function populateState($ordering = 'group', $direction = 'asc')
{
// Load the filter state.
$this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string'));

parent::populateState($ordering, $direction);
}

Expand Down
37 changes: 37 additions & 0 deletions administrator/components/com_content/src/Model/ArticlesModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,43 @@ protected function populateState($ordering = 'a.id', $direction = 'desc')
$this->context .= '.' . $forcedLanguage;
}

$search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
$this->setState('filter.search', $search);

$featured = $this->getUserStateFromRequest($this->context . '.filter.featured', 'filter_featured', '');
$this->setState('filter.featured', $featured);

$published = $this->getUserStateFromRequest($this->context . '.filter.published', 'filter_published', '');
$this->setState('filter.published', $published);

$level = $this->getUserStateFromRequest($this->context . '.filter.level', 'filter_level');
$this->setState('filter.level', $level);

$language = $this->getUserStateFromRequest($this->context . '.filter.language', 'filter_language', '');
$this->setState('filter.language', $language);

$formSubmitted = $input->post->get('form_submitted');

// Gets the value of a user state variable and sets it in the session
$this->getUserStateFromRequest($this->context . '.filter.access', 'filter_access');
$this->getUserStateFromRequest($this->context . '.filter.author_id', 'filter_author_id');
$this->getUserStateFromRequest($this->context . '.filter.category_id', 'filter_category_id');
$this->getUserStateFromRequest($this->context . '.filter.tag', 'filter_tag', '');

if ($formSubmitted) {
$access = $input->post->get('access');
$this->setState('filter.access', $access);

$authorId = $input->post->get('author_id');
$this->setState('filter.author_id', $authorId);

$categoryId = $input->post->get('category_id');
$this->setState('filter.category_id', $categoryId);

$tag = $input->post->get('tag');
$this->setState('filter.tag', $tag);
}

// List state information.
parent::populateState($ordering, $direction);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ protected function getStoreId($id = '')
*/
protected function populateState($ordering = 'a.title', $direction = 'asc')
{
// Load the filter state.
$this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string'));
$this->setState('filter.state', $this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state', '', 'cmd'));

// Load the parameters.
$params = ComponentHelper::getParams('com_finder');
$this->setState('params', $params);
Expand Down
7 changes: 7 additions & 0 deletions administrator/components/com_finder/src/Model/IndexModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,13 @@ public function purge()
*/
protected function populateState($ordering = 'l.title', $direction = 'asc')
{
// Load the filter state.
$this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string'));
$this->setState('filter.state', $this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state', '', 'cmd'));
$this->setState('filter.type', $this->getUserStateFromRequest($this->context . '.filter.type', 'filter_type', '', 'cmd'));
$this->setState('filter.content_map', $this->getUserStateFromRequest($this->context . '.filter.content_map', 'filter_content_map', '', 'cmd'));
$this->setState('filter.language', $this->getUserStateFromRequest($this->context . '.filter.language', 'filter_language', ''));

// Load the parameters.
$params = ComponentHelper::getParams('com_finder');
$this->setState('params', $params);
Expand Down
6 changes: 6 additions & 0 deletions administrator/components/com_finder/src/Model/MapsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,12 @@ public function getTable($type = 'Map', $prefix = 'Administrator', $config = [])
*/
protected function populateState($ordering = 'branch_title, a.lft', $direction = 'ASC')
{
// Load the filter state.
$this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string'));
$this->setState('filter.state', $this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state', '', 'cmd'));
$this->setState('filter.branch', $this->getUserStateFromRequest($this->context . '.filter.branch', 'filter_branch', '', 'cmd'));
$this->setState('filter.level', $this->getUserStateFromRequest($this->context . '.filter.level', 'filter_level', '', 'cmd'));

// Load the parameters.
$params = ComponentHelper::getParams('com_finder');
$this->setState('params', $params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Joomla\Component\Guidedtours\Administrator\Model;

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\Component\Guidedtours\Administrator\Helper\GuidedtoursHelper;
Expand Down Expand Up @@ -77,6 +78,11 @@ public function __construct($config = [])
*/
protected function populateState($ordering = 'a.ordering', $direction = 'ASC')
{
$app = Factory::getApplication();
$extension = $app->getUserStateFromRequest($this->context . '.filter.extension', 'extension', null, 'cmd');

$this->setState('filter.extension', $extension);

parent::populateState($ordering, $direction);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ private function fetchSchemaCache($cid = 0)
*/
protected function populateState($ordering = 'name', $direction = 'asc')
{
$this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string'));
$this->setState('filter.client_id', $this->getUserStateFromRequest($this->context . '.filter.client_id', 'filter_client_id', null, 'int'));
$this->setState('filter.type', $this->getUserStateFromRequest($this->context . '.filter.type', 'filter_type', '', 'string'));
$this->setState('filter.folder', $this->getUserStateFromRequest($this->context . '.filter.folder', 'filter_folder', '', 'string'));

parent::populateState($ordering, $direction);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ protected function populateState($ordering = 'name', $direction = 'asc')
{
$app = Factory::getApplication();

// Load the filter state.
$this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string'));
$this->setState('filter.client_id', $this->getUserStateFromRequest($this->context . '.filter.client_id', 'filter_client_id', null, 'int'));
$this->setState('filter.type', $this->getUserStateFromRequest($this->context . '.filter.type', 'filter_type', '', 'string'));
$this->setState('filter.folder', $this->getUserStateFromRequest($this->context . '.filter.folder', 'filter_folder', '', 'string'));

$this->setState('message', $app->getUserState('com_installer.message'));
$this->setState('extension_message', $app->getUserState('com_installer.extension_message'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected function _getList($query, $limitstart = 0, $limit = 0)
$listDirn = $this->getState('list.direction', 'asc');

// Replace slashes so preg_match will work
$search = $this->getState('filter.search', '');
$search = $this->getState('filter.search');
$search = str_replace('/', ' ', $search);
$db = $this->getDatabase();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ protected function getStoreId($id = '')
*/
protected function populateState($ordering = 'name', $direction = 'asc')
{
$this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string'));

$this->setState('extension_message', Factory::getApplication()->getUserState('com_installer.extension_message'));

parent::populateState($ordering, $direction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ protected function populateState($ordering = 'name', $direction = 'asc')
{
$app = Factory::getApplication();

// Load the filter state.
$this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string'));
$this->setState('filter.client_id', $this->getUserStateFromRequest($this->context . '.filter.client_id', 'filter_client_id', null, 'int'));
$this->setState('filter.package_id', $this->getUserStateFromRequest($this->context . '.filter.package_id', 'filter_package_id', null, 'int'));
$this->setState('filter.status', $this->getUserStateFromRequest($this->context . '.filter.status', 'filter_status', '', 'string'));
$this->setState('filter.type', $this->getUserStateFromRequest($this->context . '.filter.type', 'filter_type', '', 'string'));
$this->setState('filter.folder', $this->getUserStateFromRequest($this->context . '.filter.folder', 'filter_folder', '', 'string'));
$this->setState('filter.core', $this->getUserStateFromRequest($this->context . '.filter.core', 'filter_core', '', 'string'));

$this->setState('message', $app->getUserState('com_installer.message'));
$this->setState('extension_message', $app->getUserState('com_installer.extension_message'));
$app->setUserState('com_installer.message', '');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public function __construct($config = [], ?MVCFactoryInterface $factory = null)
*/
protected function populateState($ordering = 'u.name', $direction = 'asc')
{
$this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string'));
$this->setState('filter.client_id', $this->getUserStateFromRequest($this->context . '.filter.client_id', 'filter_client_id', null, 'int'));
$this->setState('filter.type', $this->getUserStateFromRequest($this->context . '.filter.type', 'filter_type', '', 'string'));
$this->setState('filter.folder', $this->getUserStateFromRequest($this->context . '.filter.folder', 'filter_folder', '', 'string'));

$app = Factory::getApplication();
$this->setState('message', $app->getUserState('com_installer.message'));
$this->setState('extension_message', $app->getUserState('com_installer.extension_message'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,40 @@ static function ($item) {
*/
protected function populateState($ordering = 'name', $direction = 'asc')
{
// Load the filter state.
$stateKeys = [
'search' => 'string',
'client_id' => 'int',
'enabled' => 'string',
'type' => 'string',
'folder' => 'string',
'supported' => 'int',
];

foreach ($stateKeys as $key => $filterType) {
$stateKey = 'filter.' . $key;

switch ($filterType) {
case 'int':
case 'bool':
$default = null;
break;

default:
$default = '';
break;
}

$stateValue = $this->getUserStateFromRequest(
$this->context . '.' . $stateKey,
'filter_' . $key,
$default,
$filterType
);

$this->setState($stateKey, $stateValue);
}

parent::populateState($ordering, $direction);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ public function __construct($config = [], ?MVCFactoryInterface $factory = null)
*/
protected function populateState($ordering = 'name', $direction = 'asc')
{
// Load the filter state.
$this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string'));

// Special case for client id.
$clientId = (int) $this->getUserStateFromRequest($this->context . '.client_id', 'client_id', 0, 'int');
$clientId = (!\in_array($clientId, [0, 1])) ? 0 : $clientId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,13 @@ protected function populateState($ordering = 'key', $direction = 'asc')
$client = substr($language_client, -1);
$language = substr($language_client, 0, -1);

// Sets the search filter.
$search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
$this->setState('filter.search', $search);

$this->setState('language_client', $language . $client);
$this->setState('filter.client', $client ? 'administrator' : 'site');
$this->setState('filter.language', $language);

// Add the 'language_client' value to the session to display a message if none selected
$app->setUserState('com_languages.overrides.language_client', $language . $client);
Expand Down
15 changes: 15 additions & 0 deletions administrator/components/com_menus/src/Model/ItemsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,21 @@ protected function populateState($ordering = 'a.lft', $direction = 'asc')
$this->context .= '.' . $forcedLanguage;
}

$search = $this->getUserStateFromRequest($this->context . '.search', 'filter_search');
$this->setState('filter.search', $search);

$published = $this->getUserStateFromRequest($this->context . '.published', 'filter_published', '');
$this->setState('filter.published', $published);

$access = $this->getUserStateFromRequest($this->context . '.filter.access', 'filter_access');
$this->setState('filter.access', $access);

$parentId = $this->getUserStateFromRequest($this->context . '.filter.parent_id', 'filter_parent_id');
$this->setState('filter.parent_id', $parentId);

$level = $this->getUserStateFromRequest($this->context . '.filter.level', 'filter_level');
$this->setState('filter.level', $level);

// Watch changes in client_id and menutype and keep sync whenever needed.
$currentClientId = $app->getUserState($this->context . '.client_id', 0);
$clientId = $app->getInput()->getInt('client_id', $currentClientId);
Expand Down
3 changes: 3 additions & 0 deletions administrator/components/com_menus/src/Model/MenusModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ protected function getListQuery()
*/
protected function populateState($ordering = 'a.ordering', $direction = 'asc')
{
$search = $this->getUserStateFromRequest($this->context . '.search', 'filter_search');
$this->setState('filter.search', $search);

$clientId = (int) $this->getUserStateFromRequest($this->context . '.client_id', 'client_id', 0, 'int');
$this->setState('client_id', $clientId);

Expand Down
11 changes: 11 additions & 0 deletions administrator/components/com_modules/src/Model/ModulesModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,21 @@ protected function populateState($ordering = 'a.position', $direction = 'asc')
// Make context client aware
$this->context .= '.' . $app->getInput()->get->getInt('client_id', 0);

// Load the filter state.
$this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string'));
$this->setState('filter.position', $this->getUserStateFromRequest($this->context . '.filter.position', 'filter_position', '', 'string'));
$this->setState('filter.module', $this->getUserStateFromRequest($this->context . '.filter.module', 'filter_module', '', 'string'));
$this->setState('filter.menuitem', $this->getUserStateFromRequest($this->context . '.filter.menuitem', 'filter_menuitem', '', 'cmd'));
$this->setState('filter.access', $this->getUserStateFromRequest($this->context . '.filter.access', 'filter_access', '', 'cmd'));

// If in modal layout on the frontend, state and language are always forced.
if ($app->isClient('site') && $layout === 'modal') {
$this->setState('filter.language', 'current');
$this->setState('filter.state', 1);
} else {
// If in backend (modal or not) we get the same fields from the user request.
$this->setState('filter.language', $this->getUserStateFromRequest($this->context . '.filter.language', 'filter_language', '', 'string'));
$this->setState('filter.state', $this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state', '', 'string'));
}

// Special case for the client id.
Expand Down
13 changes: 13 additions & 0 deletions administrator/components/com_modules/src/Model/PositionsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ public function __construct($config = [])
*/
protected function populateState($ordering = 'ordering', $direction = 'asc')
{
// Load the filter state.
$search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
$this->setState('filter.search', $search);

$state = $this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state', '', 'string');
$this->setState('filter.state', $state);

$template = $this->getUserStateFromRequest($this->context . '.filter.template', 'filter_template', '', 'string');
$this->setState('filter.template', $template);

$type = $this->getUserStateFromRequest($this->context . '.filter.type', 'filter_type', '', 'string');
$this->setState('filter.type', $type);

// Special case for the client id.
$clientId = (int) $this->getUserStateFromRequest($this->context . '.client_id', 'client_id', 0, 'int');
$clientId = (!\in_array((int) $clientId, [0, 1])) ? 0 : (int) $clientId;
Expand Down
16 changes: 16 additions & 0 deletions administrator/components/com_privacy/src/Model/ConsentsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,22 @@ protected function getStoreId($id = '')
*/
protected function populateState($ordering = 'a.id', $direction = 'desc')
{
// Load the filter state.
$this->setState(
'filter.search',
$this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search')
);

$this->setState(
'filter.subject',
$this->getUserStateFromRequest($this->context . '.filter.subject', 'filter_subject')
);

$this->setState(
'filter.state',
$this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state')
);

// Load the parameters.
$this->setState('params', ComponentHelper::getParams('com_privacy'));

Expand Down
Loading