Skip to content

Commit

Permalink
[5.2] Content Category Save to Menu (joomla#43840)
Browse files Browse the repository at this point in the history
  • Loading branch information
brianteeman authored Jul 29, 2024
1 parent 51710f8 commit ab8d4ff
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public function __construct($config = [], MVCFactoryInterface $factory = null, C
if (empty($this->extension)) {
$this->extension = $this->input->get('extension', 'com_content');
}

$this->registerTask('save2menulist', 'save');
$this->registerTask('save2menublog', 'save');
}

/**
Expand Down Expand Up @@ -254,8 +257,34 @@ protected function postSaveHook(BaseDatabaseModel $model, $validData = [])
$item->metadata = (string) $registry;
}

// When editing in modal then redirect to modalreturn layout
if ($this->input->get('layout') === 'modal' && $this->task === 'save') {
if (\in_array($this->getTask(), ['save2menulist', 'save2menublog'])) {
$editState = [];

$type = 'component';
$id = $model->getState('category.id');
$link = 'index.php?option=com_content&view=category';

if ($this->getTask() === 'save2menublog') {
$link .= '&layout=blog'; // Append the layout parameter for the blog layout
}

$editState = [
'id' => $id,
'link' => $link,
'title' => $model->getItem($id)->title,
'type' => $type,
'request' => ['id' => $id],
];

$this->app->setUserState('com_menus.edit.item', [
'data' => $editState,
'type' => $type,
'link' => $link,
]);

$this->setRedirect(Route::_('index.php?option=com_menus&view=item&client_id=0&menutype=mainmenu&layout=edit', false));
} elseif ($this->input->get('layout') === 'modal' && $this->task === 'save') {
// When editing in modal then redirect to modalreturn layout
$id = $item->id;
$return = 'index.php?option=' . $this->option . '&view=' . $this->view_item . $this->getRedirectToItemAppend($id)
. '&layout=modalreturn&from-task=save';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public function display($tpl = null)
protected function addToolbar()
{
$extension = Factory::getApplication()->getInput()->get('extension');

$user = $this->getCurrentUser();
$userId = $user->id;
$toolbar = Toolbar::getInstance();
Expand Down Expand Up @@ -203,9 +204,14 @@ protected function addToolbar()
$saveGroup = $toolbar->dropdownButton('save-group');

$saveGroup->configure(
function (Toolbar $childBar) {
function (Toolbar $childBar) use ($canDo, $component) {
$childBar->save('category.save');
$childBar->save2new('category.save2new');

if ($canDo->get('core.create', 'com_menus.menu') && $component === 'com_content') {
$childBar->save('category.save2menulist', 'JTOOLBAR_SAVE_TO_MENU_AS_LIST');
$childBar->save('category.save2menublog', 'JTOOLBAR_SAVE_TO_MENU_AS_BLOG');
}
}
);

Expand All @@ -223,7 +229,7 @@ function (Toolbar $childBar) {
$saveGroup = $toolbar->dropdownButton('save-group');

$saveGroup->configure(
function (Toolbar $childBar) use ($checkedOut, $canDo, $itemEditable) {
function (Toolbar $childBar) use ($checkedOut, $canDo, $itemEditable, $component) {
// Can't save the record if it's checked out and editable
if (!$checkedOut && $itemEditable) {
$childBar->save('category.save');
Expand All @@ -233,6 +239,11 @@ function (Toolbar $childBar) use ($checkedOut, $canDo, $itemEditable) {
}
}

if ($canDo->get('core.create', 'com_menus.menu') && $component === 'com_content') {
$childBar->save('category.save2menulist', 'JTOOLBAR_SAVE_TO_MENU_AS_LIST');
$childBar->save('category.save2menublog', 'JTOOLBAR_SAVE_TO_MENU_AS_BLOG');
}

// If an existing item, can save to a copy.
if ($canDo->get('core.create')) {
$childBar->save2copy('category.save2copy');
Expand Down
2 changes: 2 additions & 0 deletions administrator/language/en-GB/joomla.ini
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,8 @@ JTOOLBAR_SAVE="Save & Close"
JTOOLBAR_SAVE_AND_NEW="Save & New"
JTOOLBAR_SAVE_AS_COPY="Save as Copy"
JTOOLBAR_SAVE_TO_MENU="Save to Menu"
JTOOLBAR_SAVE_TO_MENU_AS_BLOG="Save to Menu as Blog"
JTOOLBAR_SAVE_TO_MENU_AS_LIST="Save to Menu as List"
JTOOLBAR_TRASH="Trash"
JTOOLBAR_UNARCHIVE="Unarchive"
JTOOLBAR_UNINSTALL="Uninstall"
Expand Down

0 comments on commit ab8d4ff

Please sign in to comment.