Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Topic started by: GL700Wing on September 25, 2024, 01:29:46 AM

Title: Add Modify to Quick Buttons menu
Post by: GL700Wing on September 25, 2024, 01:29:46 AM
Link to the mod (https://custom.simplemachines.org/index.php?mod=4406)

Add Modify to Quick Buttons menu
v1.1

This mod will add the Modify button to the Quick Buttons menu and provide an option to remove the Quick Edit button from the Quick Buttons menu.

Release History
v1.0 - 25-Sep-24
o Initial release as Replace Quick Edit with Modify.

v1.1 - 28-Sep-24
o As per this request (https://www.simplemachines.org/community/index.php?msg=4180424) made removal of the Quick Edit button from Quick Buttons menu optional.
o Renamed to Add Modify to Quick Buttons menu.

License
Copyright 2024 Kathy Leslie

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Title: Re: Replace Quick Edit with Modify
Post by: JRMBelgium on September 25, 2024, 02:29:20 PM
For some reason I can't review this mod so just letting you know here it works perfectly!

I modified the code a little for me so that it not replaces the button, but simply adds it. This way anyone can choose which options fits best for their needs.
Title: Re: Replace Quick Edit with Modify
Post by: Steve on September 26, 2024, 07:27:59 AM
Quote from: JRMBelgium on September 25, 2024, 02:29:20 PMI modified the code a little for me so that it not replaces the button, but simply adds it.
How? I would like that option as well.
Title: Re: Replace Quick Edit with Modify
Post by: GL700Wing on September 26, 2024, 07:36:01 AM
Quote from: Steve on September 26, 2024, 07:27:59 AM
Quote from: JRMBelgium on September 25, 2024, 02:29:20 PMI modified the code a little for me so that it not replaces the button, but simply adds it.
How? I would like that option as well.
Simples - just comment out the following line in ./Sources/Subs-RQEwM.php
    unset($output['quickbuttons']['quick_edit']);

Might update the mod to include a setting that gives the option to just move the 'Modify' button (ie, also keep the 'Quick Edit' button) ...
Title: Re: Replace Quick Edit with Modify
Post by: Steve on September 27, 2024, 08:25:15 AM
Thanks GL.  :)
Title: Re: Replace Quick Edit with Modify
Post by: JRMBelgium on September 28, 2024, 02:27:36 AM
Quote from: Steve on September 26, 2024, 07:27:59 AM
Quote from: JRMBelgium on September 25, 2024, 02:29:20 PMI modified the code a little for me so that it not replaces the button, but simply adds it.
How? I would like that option as well.

<?php
//============================================================================================================
// Function for adding the 'Modify' button from the 'More' menu to the main view without removing the 'Quick Edit' button.
// Called as hook by 'integrate_prepare_display_context' in ./Sources/Display.php.
//============================================================================================================
function RQEwM_displayContext(&$output)
{
   global
$context, $scripturl, $txt;

   
// 'Modify' button definition copied from ./Sources/Display.php
   
$modifyButton = array(
       
'modify' => array(
           
'label' => $txt['modify'],
           
'href' => $scripturl . '?action=post;msg=' . $output['id'] . ';topic=' . $context['current_topic'] . '.' . $context['start'],
           
'icon' => 'modify_button',
           
'show' => $output['can_modify']
       ),
   );

   
// Add the 'Modify' button to the quick buttons menu.
   // This places 'Modify' immediately after 'Quick Edit'.
   
$quickButtonsKeys = array_keys($output['quickbuttons']);
   
$index = array_search('quick_edit', $quickButtonsKeys);
   
   if (
$index !== false) {
       
// Insert 'Modify' after 'Quick Edit'
       
$index += 1;
       
$output['quickbuttons'] = array_merge(
           
array_slice($output['quickbuttons'], 0, $index),
           
$modifyButton,
           
array_slice($output['quickbuttons'], $index)
       );
   } else {
       
// If 'Quick Edit' is not found, append 'Modify' at the end
       
$output['quickbuttons'] = array_merge($output['quickbuttons'], $modifyButton);
   }

   
// Remove the 'Modify' button from the 'More' menu to prevent duplication
   
if (isset($output['quickbuttons']['more']['modify'])) {
       unset(
$output['quickbuttons']['more']['modify']);
   }

   
// Note: The line below has been removed to retain the 'Quick Edit' button
   // unset($output['quickbuttons']['quick_edit']);
}
?>
Title: Re: Add Modify to Quick Buttons menu
Post by: GL700Wing on September 28, 2024, 04:58:25 AM
Quote from: Steve on September 27, 2024, 08:25:15 AMThanks GL.  :)
Done!
AM2QBM.jpg
Title: Re: Add Modify to Quick Buttons menu
Post by: Steve on September 28, 2024, 08:51:04 AM
Thanks GL. Is there supposed to be any settings somewhere?
Title: Re: Add Modify to Quick Buttons menu
Post by: GL700Wing on September 28, 2024, 08:55:04 AM
Quote from: Steve on September 28, 2024, 08:51:04 AMThanks GL. Is there supposed to be any settings somewhere?
In Modification Settings (hopefully) ...


Just updated the mod package file to redirect to the Modifications Settings page after mod is installed.
Title: Re: Add Modify to Quick Buttons menu
Post by: Steve on September 28, 2024, 02:05:12 PM
I had totally missed the setting the first time I looked. Sorry about that.

Thanks for the update.  :)
Title: Re: Add Modify to Quick Buttons menu
Post by: Steve on September 30, 2024, 10:37:27 AM
There seems to be a glitch somewhere ... when modifying a post and saving it, I get a message at the top of the page that says 'Loading' and the page is never refreshed. But if I manually refresh the page, the post shows with any changes I've made.  ???
Title: Re: Add Modify to Quick Buttons menu
Post by: GL700Wing on September 30, 2024, 06:52:25 PM
Quote from: Steve on September 30, 2024, 10:37:27 AMThere seems to be a glitch somewhere ... when modifying a post and saving it, I get a message at the top of the page that says 'Loading' and the page is never refreshed. But if I manually refresh the page, the post shows with any changes I've made.  ???
That seems like a JS issue and this mod doesn't do any JS stuff - wondering if it's because of this issue (https://www.simplemachines.org/community/index.php?msg=4180617) which you also reported.
Title: Re: Add Modify to Quick Buttons menu
Post by: Steve on October 01, 2024, 08:54:06 AM
Possible I guess. I know nothing about coding so you could very well be right.