diff --git a/administrator/components/com_content/src/Model/ArticleModel.php b/administrator/components/com_content/src/Model/ArticleModel.php
index bc9bd82c04633..33603bbf06c7c 100644
--- a/administrator/components/com_content/src/Model/ArticleModel.php
+++ b/administrator/components/com_content/src/Model/ArticleModel.php
@@ -13,6 +13,8 @@
use Joomla\CMS\Event\AbstractEvent;
use Joomla\CMS\Factory;
+use Joomla\CMS\Filter\InputFilter;
+use Joomla\CMS\Filter\OutputFilter;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormFactoryInterface;
use Joomla\CMS\Helper\TagsHelper;
@@ -684,10 +686,9 @@ public function validate($form, $data, $group = null)
*/
public function save($data)
{
- $input = Factory::getApplication()->input;
- $filter = \JFilterInput::getInstance();
- $db = $this->getDbo();
- $user = Factory::getUser();
+ $app = Factory::getApplication();
+ $input = $app->input;
+ $filter = InputFilter::getInstance();
if (isset($data['metadata']) && isset($data['metadata']['author']))
{
@@ -780,8 +781,29 @@ public function save($data)
// Alter the title for save as copy
if ($input->get('task') == 'save2copy')
{
- $origTable = clone $this->getTable();
- $origTable->load($input->getInt('id'));
+ $origTable = $this->getTable();
+
+ if ($app->isClient('site'))
+ {
+ $origTable->load($input->getInt('a_id'));
+
+ if ($origTable->title === $data['title'])
+ {
+ /**
+ * If title of article is not changed, set alias to original article alias so that Joomla! will generate
+ * new Title and Alias for the copied article
+ */
+ $data['alias'] = $origTable->alias;
+ }
+ else
+ {
+ $data['alias'] = '';
+ }
+ }
+ else
+ {
+ $origTable->load($input->getInt('id'));
+ }
if ($data['title'] == $origTable->title)
{
@@ -789,12 +811,9 @@ public function save($data)
$data['title'] = $title;
$data['alias'] = $alias;
}
- else
+ elseif ($data['alias'] == $origTable->alias)
{
- if ($data['alias'] == $origTable->alias)
- {
- $data['alias'] = '';
- }
+ $data['alias'] = '';
}
}
@@ -803,16 +822,16 @@ public function save($data)
{
if ($data['alias'] == null)
{
- if (Factory::getApplication()->get('unicodeslugs') == 1)
+ if ($app->get('unicodeslugs') == 1)
{
- $data['alias'] = \JFilterOutput::stringUrlUnicodeSlug($data['title']);
+ $data['alias'] = OutputFilter::stringUrlUnicodeSlug($data['title']);
}
else
{
- $data['alias'] = \JFilterOutput::stringURLSafe($data['title']);
+ $data['alias'] = OutputFilter::stringURLSafe($data['title']);
}
- $table = Table::getInstance('Content', 'JTable');
+ $table = $this->getTable();
if ($table->load(array('alias' => $data['alias'], 'catid' => $data['catid'])))
{
@@ -824,7 +843,7 @@ public function save($data)
if (isset($msg))
{
- Factory::getApplication()->enqueueMessage($msg, 'warning');
+ $app->enqueueMessage($msg, 'warning');
}
}
}
diff --git a/components/com_content/src/Controller/ArticleController.php b/components/com_content/src/Controller/ArticleController.php
index 5989033cb64e4..496ac6c1b50f4 100644
--- a/components/com_content/src/Controller/ArticleController.php
+++ b/components/com_content/src/Controller/ArticleController.php
@@ -391,6 +391,10 @@ public function save($key = null, $urlVar = 'a_id')
$this->setRedirect(Route::_('index.php?Itemid=' . $menuitem . $lang, false));
}
}
+ elseif ($this->getTask() === 'save2copy')
+ {
+ // Redirect to the article page, use the redirect url set from parent controller
+ }
else
{
// If ok, redirect to the return page.
diff --git a/components/com_content/src/View/Form/HtmlView.php b/components/com_content/src/View/Form/HtmlView.php
index 5f019e35c148d..f449cdcbba416 100644
--- a/components/com_content/src/View/Form/HtmlView.php
+++ b/components/com_content/src/View/Form/HtmlView.php
@@ -86,6 +86,14 @@ class HtmlView extends BaseHtmlView
*/
protected $captchaEnabled = false;
+ /**
+ * Should we show Save As Copy button?
+ *
+ * @var boolean
+ * @since __DEPLOY_VERSION__
+ */
+ protected $showSaveAsCopy = false;
+
/**
* Execute and display a template script.
*
@@ -95,8 +103,8 @@ class HtmlView extends BaseHtmlView
*/
public function display($tpl = null)
{
- $user = Factory::getUser();
$app = Factory::getApplication();
+ $user = $app->getIdentity();
// Get model data.
$this->state = $this->get('State');
@@ -181,7 +189,15 @@ public function display($tpl = null)
}
}
+ // If the article is being edited and the current user has permission to create article
+ if ($this->item->id
+ && ($user->authorise('core.create', 'com_content') || \count($user->getAuthorisedCategories('com_content', 'core.create'))))
+ {
+ $this->showSaveAsCopy = true;
+ }
+
$this->_prepareDocument();
+
parent::display($tpl);
}
diff --git a/components/com_content/tmpl/form/edit.php b/components/com_content/tmpl/form/edit.php
index c3ea589ceabb7..5b5865023f31e 100644
--- a/components/com_content/tmpl/form/edit.php
+++ b/components/com_content/tmpl/form/edit.php
@@ -161,6 +161,12 @@
+ showSaveAsCopy) : ?>
+
+