diff --git a/administrator/components/com_content/src/Model/ArticleModel.php b/administrator/components/com_content/src/Model/ArticleModel.php index 92639c9f40d4b..6f0b7acc24458 100644 --- a/administrator/components/com_content/src/Model/ArticleModel.php +++ b/administrator/components/com_content/src/Model/ArticleModel.php @@ -485,7 +485,6 @@ public function getItem($pk = null) public function getForm($data = array(), $loadData = true) { $app = Factory::getApplication(); - $user = $app->getIdentity(); // Get the form. $form = $this->loadForm('com_content.article', 'article', array('control' => 'jform', 'load_data' => $loadData)); @@ -495,12 +494,17 @@ public function getForm($data = array(), $loadData = true) return false; } + // Object uses for checking edit state permission of article + $record = new \stdClass; + // Get ID of the article from input, for frontend, we use a_id while backend uses id $articleIdFromInput = $app->input->getInt('a_id') ?: $app->input->getInt('id', 0); // On edit article, we get ID of article from article.id state, but on save, we use data from input $id = (int) $this->getState('article.id', $articleIdFromInput); + $record->id = $id; + // For new articles we load the potential state + associations if ($id == 0 && $formField = $form->getField('catid')) { @@ -531,12 +535,13 @@ public function getForm($data = array(), $loadData = true) $form->setFieldAttribute('catid', 'refresh-enabled', true); $form->setFieldAttribute('catid', 'refresh-cat-id', $assignedCatids); $form->setFieldAttribute('catid', 'refresh-section', 'article'); + + // Store ID of the category uses for edit state permission check + $record->catid = $assignedCatids; } - // Check for existing article. // Modify the form based on Edit State access controls. - if ($id != 0 && (!$user->authorise('core.edit.state', 'com_content.article.' . (int) $id)) - || ($id == 0 && !$user->authorise('core.edit.state', 'com_content'))) + if (!$this->canEditState($record)) { // Disable fields for display. $form->setFieldAttribute('featured', 'disabled', 'true'); diff --git a/components/com_content/src/Model/FormModel.php b/components/com_content/src/Model/FormModel.php index 5995b92a97500..b73b7b1c5075a 100644 --- a/components/com_content/src/Model/FormModel.php +++ b/components/com_content/src/Model/FormModel.php @@ -49,19 +49,28 @@ protected function populateState() { $app = Factory::getApplication(); + // Load the parameters. + $params = $app->getParams(); + $this->setState('params', $params); + + if ($params && $params->get('enable_category') == 1 && $params->get('catid')) + { + $catId = $params->get('catid'); + } + else + { + $catId = 0; + } + // Load state from the request. $pk = $app->input->getInt('a_id'); $this->setState('article.id', $pk); - $this->setState('article.catid', $app->input->getInt('catid')); + $this->setState('article.catid', $app->input->getInt('catid', $catId)); $return = $app->input->get('return', null, 'base64'); $this->setState('return_page', base64_decode($return)); - // Load the parameters. - $params = $app->getParams(); - $this->setState('params', $params); - $this->setState('layout', $app->input->getString('layout')); }