diff --git a/administrator/components/com_content/models/article.php b/administrator/components/com_content/models/article.php index f0398d220d6e0..8b358aa77d622 100644 --- a/administrator/components/com_content/models/article.php +++ b/administrator/components/com_content/models/article.php @@ -208,7 +208,7 @@ protected function canEditState($record) } // Default to component settings if neither article nor category known. - return parent::canEditState(); + return parent::canEditState($record); } /** @@ -334,19 +334,11 @@ public function getForm($data = array(), $loadData = true) return false; } - $jinput = JFactory::getApplication()->input; - - /* - * The front end calls this model and uses a_id to avoid id clashes so we need to check for that first. - * The back end uses id so we use that the rest of the time and set it to 0 by default. - */ - $id = $jinput->get('a_id', $jinput->get('id', 0)); + $id = $this->getState('article.id'); // Determine correct permissions to check. - if ($this->getState('article.id')) + if ($id) { - $id = $this->getState('article.id'); - // Existing record. Can only edit in selected categories. $form->setFieldAttribute('catid', 'action', 'core.edit'); @@ -359,12 +351,15 @@ public function getForm($data = array(), $loadData = true) $form->setFieldAttribute('catid', 'action', 'core.create'); } - $user = JFactory::getUser(); + $data = $this->loadFormData(); + + if (is_array($data)) + { + $data = ArrayHelper::toObject($data, 'JObject'); + } - // 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($data)) { // Disable fields for display. $form->setFieldAttribute('featured', 'disabled', 'true'); @@ -383,7 +378,7 @@ public function getForm($data = array(), $loadData = true) } // Prevent messing with article language and category when editing existing article with associations - $app = JFactory::getApplication(); + $app = JFactory::getApplication(); $assoc = JLanguageAssociations::isEnabled(); // Check if article is associated diff --git a/components/com_content/models/form.php b/components/com_content/models/form.php index aa5b749237b84..29df6f3df9b14 100644 --- a/components/com_content/models/form.php +++ b/components/com_content/models/form.php @@ -42,17 +42,24 @@ protected function populateState() { $app = JFactory::getApplication(); + // Load the parameters. + $params = $app->getParams(); + // Load state from the request. $pk = $app->input->getInt('a_id'); $this->setState('article.id', $pk); + if (!$pk && $params->get('enable_category') == 1) + { + $app->input->def('catid', $params->get('catid', 1)); + } + $this->setState('article.catid', $app->input->getInt('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')); @@ -84,7 +91,7 @@ public function getItem($itemId = null) } $properties = $table->getProperties(1); - $value = ArrayHelper::toObject($properties, 'JObject'); + $value = ArrayHelper::toObject($properties, 'JObject'); // Convert attrib field to Registry. $value->params = new Registry($value->attribs); @@ -110,27 +117,12 @@ public function getItem($itemId = null) } } - // Check edit state permission. - if ($itemId) + if (!$itemId) { - // Existing item - $value->params->set('access-change', $user->authorise('core.edit.state', $asset)); + $value->catid = (int) $this->getState('article.catid'); } - else - { - // New item. - $catId = (int) $this->getState('article.catid'); - if ($catId) - { - $value->params->set('access-change', $user->authorise('core.edit.state', 'com_content.category.' . $catId)); - $value->catid = $catId; - } - else - { - $value->params->set('access-change', $user->authorise('core.edit.state', 'com_content')); - } - } + $value->params->set('access-change', $this->canEditState($value)); $value->articletext = $value->introtext; @@ -140,7 +132,7 @@ public function getItem($itemId = null) } // Convert the metadata field to an array. - $registry = new Registry($value->metadata); + $registry = new Registry($value->metadata); $value->metadata = $registry->toArray(); if ($itemId)