Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.2] Content Category Save to Menu #3229

Closed
jgerman-bot opened this issue Jul 30, 2024 · 0 comments · Fixed by #3230
Closed

[5.2] Content Category Save to Menu #3229

jgerman-bot opened this issue Jul 30, 2024 · 0 comments · Fixed by #3230

Comments

@jgerman-bot
Copy link

New language relevant PR in upstream repo: joomla/joomla-cms#43840 Here are the upstream changes:

Click to expand the diff!
diff --git a/administrator/components/com_categories/src/Controller/CategoryController.php b/administrator/components/com_categories/src/Controller/CategoryController.php
index 6ffae68757181..6a9622ca24f71 100644
--- a/administrator/components/com_categories/src/Controller/CategoryController.php
+++ b/administrator/components/com_categories/src/Controller/CategoryController.php
@@ -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');
     }
 
     /**
@@ -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';
diff --git a/administrator/components/com_categories/src/View/Category/HtmlView.php b/administrator/components/com_categories/src/View/Category/HtmlView.php
index c1a7c70ab0100..79363376f6082 100644
--- a/administrator/components/com_categories/src/View/Category/HtmlView.php
+++ b/administrator/components/com_categories/src/View/Category/HtmlView.php
@@ -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();
@@ -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');
+                    }
                 }
             );
 
@@ -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');
@@ -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');
diff --git a/administrator/language/en-GB/joomla.ini b/administrator/language/en-GB/joomla.ini
index 04a50421f9024..71d1fc167480a 100644
--- a/administrator/language/en-GB/joomla.ini
+++ b/administrator/language/en-GB/joomla.ini
@@ -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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

4 participants