Skip to content
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
51 changes: 35 additions & 16 deletions administrator/components/com_content/src/Model/ArticleModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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']))
{
Expand Down Expand Up @@ -780,21 +781,39 @@ 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)
{
list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']);
$data['title'] = $title;
$data['alias'] = $alias;
}
else
elseif ($data['alias'] == $origTable->alias)
{
if ($data['alias'] == $origTable->alias)
{
$data['alias'] = '';
}
$data['alias'] = '';
}
}

Expand All @@ -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'])))
{
Expand All @@ -824,7 +843,7 @@ public function save($data)

if (isset($msg))
{
Factory::getApplication()->enqueueMessage($msg, 'warning');
$app->enqueueMessage($msg, 'warning');
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions components/com_content/src/Controller/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 17 additions & 1 deletion components/com_content/src/View/Form/HtmlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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');
Expand Down Expand Up @@ -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);
}

Expand Down
6 changes: 6 additions & 0 deletions components/com_content/tmpl/form/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@
<span class="icon-check" aria-hidden="true"></span>
<?php echo Text::_('JSAVE'); ?>
</button>
<?php if ($this->showSaveAsCopy) : ?>
<button type="button" class="btn btn-primary" data-submit-task="article.save2copy">
<span class="icon-copy" aria-hidden="true"></span>
<?php echo Text::_('JSAVEASCOPY'); ?>
</button>
<?php endif; ?>
<button type="button" class="btn btn-danger" data-submit-task="article.cancel">
<span class="icon-times" aria-hidden="true"></span>
<?php echo Text::_('JCANCEL'); ?>
Expand Down
1 change: 1 addition & 0 deletions language/en-GB/joomla.ini
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ JREGISTER="Register"
JREQUIRED="Required"
JRESET="Reset"
JSAVE="Save"
JSAVEASCOPY="Save As Copy"
JSELECT="Select"
JSHOW="Show"
JSHOWPASSWORD="Show Password"
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/MVC/Controller/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ public function save($key = null, $urlVar = null)
{
case 'apply':
// Set the record data in the session.
$recordId = $model->getState($this->context . '.id');
$recordId = $model->getState($model->getName() . '.id');
$this->holdEditId($context, $recordId);
$app->setUserState($context . '.data', null);
$model->checkout($recordId);
Expand Down