Feature No Code Attached Yet
avatar JoomlaTema
JoomlaTema
25 Mar 2025

Duplicate Menu Items With Its Module Assignment Option

When duplicating a menu item, an option to automatically copy all assigned modules to the newly created menu item can be added. A checkbox, such as "Duplicate with all assigned modules," could be included when using the "Save as Copy" button. This ensures seamless duplication while maintaining consistent module assignments.

That would be great. Thanks.

avatar JoomlaTema JoomlaTema - open - 25 Mar 2025
avatar joomla-cms-bot joomla-cms-bot - change - 25 Mar 2025
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 25 Mar 2025
avatar brianteeman
brianteeman - comment - 25 Mar 2025

That cant really work as the menu item doesnt contain the module assignment. Its the other way around the module contains the menu assignment

avatar JoomlaTema
JoomlaTema - comment - 25 Mar 2025

Actually there was a plugin for joomla 3 that I used to use in the past. Then i ve created one for j4 ( https://extensions.joomla.org/extension/jt-copy-module-assignments/) it works well but i thought that would be great if that feature was added core. Also we have module assignment section on each joomla menu items So this shouldn't be impossible.

avatar brianteeman
brianteeman - comment - 25 Mar 2025

If you already have created an extension for this I am confused what you are asking for.

avatar JoomlaTema
JoomlaTema - comment - 25 Mar 2025

Brian do you have to answer all the things related Joomla? I am confused about this too.

avatar JoomlaTema
JoomlaTema - comment - 25 Mar 2025

I kindly request that you do not respond to any of my future posts on any platform please.

avatar brianteeman
brianteeman - comment - 25 Mar 2025

Guess my question was too hard to answer.

avatar JoomlaTema
JoomlaTema - comment - 25 Mar 2025

I already provided the answer to your question in my first post. I mentioned that I have an extension for this, but it would be great if it were part of the core features, so I wouldn't have to rely on an extension. Is that too difficult to understand?

avatar chmst
chmst - comment - 28 Mar 2025

@JoomlaTema if you want this feature, you can make a PR for it. No need to be rude. Thank you.

avatar drmenzelit drmenzelit - change - 30 Mar 2025
Labels Added: Feature
avatar drmenzelit drmenzelit - labeled - 30 Mar 2025
avatar brianteeman
brianteeman - comment - 31 Mar 2025

probably because it doesnt actually work as the plugin runs (and fails) when saving anything

avatar Fedik Fedik - change - 31 Mar 2025
The description was changed
avatar Fedik Fedik - edited - 31 Mar 2025
avatar JoomlaTema
JoomlaTema - comment - 31 Mar 2025

Hi what that means "drmenzelit added Feature yesterday" Does it mean that feature added joomla now? Also i do not know how to add a pull request.

avatar brianteeman
brianteeman - comment - 31 Mar 2025

It means that it has been flagged as a feature request as opposed to a bug report

avatar JoomlaTema
JoomlaTema - comment - 31 Mar 2025

I am having trouble understanding this. We all know that, some core features of Joomla work through plugins. So we have a working plugin, so I don't understand how it's impossible to do this. If you can not do anything you simply implement that plugin to core that is all. Am i wrong? How could that be impossible.

avatar brianteeman
brianteeman - comment - 31 Mar 2025
  1. Your plugin doesn't work. I tested it!!

  2. A feature request needs code in the form of a pull request

When code is submitted it will be tested AND the release leads and maintainers will make a decision if it is a feature that is suitable for inclusion.

avatar JoomlaTema
JoomlaTema - comment - 31 Mar 2025

Brian I do not know what is your problem with me or what are you trying to do but the plugin works. You are refusing all my posts on all platforms. You make same thing and has a negative approach to all my posts. Do you have any problem with me? You should use save as copy button in menu. See that video. https://www.awesomescreenshot.com/video/38237677?key=4cc2c0c24915f1eb4bddf87ab7b00e91 I have created a second main menu module 2 and assigned it only to typography menu item then duplicated that menu item and as you can see the assigned module came. By the way thanks Vivian.

avatar JoomlaTema
JoomlaTema - comment - 31 Mar 2025

I do not mean to add my plugin to core. I just suggest that feature may take place in Joomla that is a simple request. It is just an idea. It is hard to understand what are you trying to do. You do the same thing against all my posts on all platforms (forum, mattermost etc). You always has a negative approach even sometimes rude to all my posts or insulting me on some platforms. I do not understand this. If you have a problem with me simply you can say it.

avatar JoomlaTema
JoomlaTema - comment - 31 Mar 2025

I am not a native coder or a php expert, i am a self-taught joomla lover just trying to be a part of Joomla Community. I love Joomla very much. It was a hobby at the beginning but now i can produce some simple extensions and modules. But you always try to make me hate Joomla. I am sorry for saying this but i feel so.

avatar brianteeman
brianteeman - comment - 31 Mar 2025

With your plugin enabled it is triggered and fails when you save an article or a custom field

avatar JoomlaTema
JoomlaTema - comment - 31 Mar 2025

I am using it for a while and i did not see any problem like this. I did not try custom fields but i can save articles with plugin enabled. See that video: https://www.awesomescreenshot.com/video/38239006?key=67ac24db86d5a01277ec485af52b0351
article is saved just with a message about context editing. I have not noticed it before.

avatar brianteeman
brianteeman - comment - 31 Mar 2025

As I said - it fails when you save an article or a field - i do not lie

chrome_Jqxp1CSDTL.mp4
avatar brianteeman
brianteeman - comment - 31 Mar 2025
  1. A feature request needs code in the form of a pull request

When code is submitted it will be tested AND the release leads and maintainers will make a decision if it is a feature that is suitable for inclusion.

This is the procedure for EVERY feature

avatar JoomlaTema
JoomlaTema - comment - 31 Mar 2025

In your video it says field saved just with a context editing warning. It saves field or article with a red no context editing was made. I have improved that old j3 copy module assignments plugin which was not working on j4 (https://github.com/alexxandar/Copy-Module-Assignments). That is a simple warning about invalid context. So that means your action is not related plugin's work. Here is plugin's related php code part. So it seems that plugin works but your action is not related the enabled plugin. I think this is the situation.

` public function onContentAfterSave($context, &$table, $isNew)
{
// Debugging output
JFactory::getApplication()->enqueueMessage('Context: ' . $context);
JFactory::getApplication()->enqueueMessage('Is New: ' . ($isNew ? 'Yes' : 'No'));

// Return if invalid context
if ($context != 'com_menus.item') {
    JFactory::getApplication()->enqueueMessage('Invalid context, exiting.', 'error');
    return true;
}

`
You just see the warning here i think. That does not mean plugin does not work or prevent something.

avatar JoomlaTema
JoomlaTema - comment - 31 Mar 2025

Brian If that section is your responsibility I Give Up. I do not want to be in a relation with you. If not please let me talk to the others.
I kindly repeat my request please do not reply any of my post on any platform. I do not want to see Brian Teeman name under any of my post. Please respect this.

avatar brianteeman
brianteeman - comment - 1 Apr 2025

@JoomlaTema if you want this feature, you can make a PR for it. No need to be rude. Thank you.

avatar JoomlaTema
JoomlaTema - comment - 1 Apr 2025

"Pull request creation failed. Validation failed: must be a collaborator" What does that mean? Should I select a collaborator, or should I be a collaborator?

avatar brianteeman
brianteeman - comment - 1 Apr 2025

You need to make a fork of the joomla repo
Create a branch in that fork and commit your changes there
Then go back to the origin joomla repo and it will let you create a pull request from your branch

avatar JoomlaTema
JoomlaTema - comment - 1 Apr 2025
avatar brianteeman
brianteeman - comment - 1 Apr 2025

You have not completed the last step

avatar brianteeman
brianteeman - comment - 1 Apr 2025

Actually you havent followed any of the steps

avatar JoomlaTema
JoomlaTema - comment - 1 Apr 2025

I deleted branches I think. I should start over again following instrucitons.

avatar rdeutz
rdeutz - comment - 2 Apr 2025

Not a bad idea. But when it should be part of the core a plugin is not the best way. We could implement it into the menu model and add a switch on the Module Assignment page like "Copy Menu Assignments".

Btw. you migth not noticed it, but Brian tried to help you and you responded quite rude. That's nothing we want to see here.

avatar JoomlaTema
JoomlaTema - comment - 2 Apr 2025

Thanks for the answer. I am a joomla lover since 2007 I know Brian very well. I have 40+ extensions on JED. I love to be a part of Joomla Community. This event was just the last straw. For almost 10 years, Brian has been showing me a negative, demeaning, and rude attitude in all environments and on every platform, and I have been enduring it. But when he did the same thing here, I had to respond firmly. I did not mean to be rude . I m not a native English speaker may be it was perceived that way.
I only asked him not to respond to any of my posts. It wasn't my intention to be rude. But he has been constantly rude to me in every environment for years.

avatar brianteeman
brianteeman - comment - 2 Apr 2025

I have no idea who you are

avatar brianteeman
brianteeman - comment - 2 Apr 2025

and for future reference when taking copyright code from someone else even if it is GPL you can not change the copyright to yourself.

avatar JoomlaTema
JoomlaTema - comment - 2 Apr 2025

@rdeutz I am not trying to implement my extension to the core. I just want that feature to be added Joomla. That is a simple request it is just an idea. If it is not possible it is okay.

Brian it is hard to believe that you do not know me I use same nickname on all platforms. Yesterday you scolded me on mattermost when I was asking how to create a pull request referring this topic. As i said before i am not a native coder or a php expert just a self taught joomler i am from a totally different area (a medical doctor) trying to be the part of the Community. I may not know how things work. But i feel that you have always been angry with me. May be i am wrong but i do nothink i am. I do not want to prolong this conversation also.
I did not know that GPL point.

This is original code of J3 plugin:

`<?php
/**

  • @Package Joomla.Plugin
  • @subpackage Content.CopyAssignments
  • @copyright Copyright (C) 2016 Aleksandar Jovanović (himself@alexxandar.me). All rights reserved.
  • @license GNU General Public License version 2 or later; see LICENSE.txt
    */

defined('_JEXEC') or die;

/**

  • Copy Module Assignments Plugin
    /
    class PlgContentCopymoduleassignments extends JPlugin
    {
    /
    *

    • Database object
    • @var JDatabaseDriver
    • @SInCE 3.3
      */
      protected $db;

    /**

    • Plugin that copies module assignments from original to new menu item when using "Save as copy"

    • @param string $context The context of the content being passed to the plugin.

    • @param mixed &$row An object with a "text" property

    • @param mixed $params Additional parameters. See {@see PlgContentContent()}.

    • @param integer $page Optional page number. Unused. Defaults to zero.

    • @return boolean True on success.
      */
      public function onContentAfterSave( $context, &$table, $isNew )
      {
      // Return if invalid context
      if ( $context != 'com_menus.item' )
      return true;

      // Return if items is not a product of "Save as copy"
      if ( !( $table->get( '_location_id' ) > 1 && $isNew == false ) )
      return true;

      // Find all assigned modules
      $query1 = $this->db->getQuery(true)
      ->select($this->db->quoteName('moduleid'))
      ->from($this->db->quoteName('#__modules_menu'))
      ->where($this->db->quoteName('menuid') . ' = ' . $table->get( '_location_id' ) );
      $this->db->setQuery($query1);
      $modules = (array) $this->db->loadColumn();

      // Assing all found modules to copied menu item
      if( !empty( $modules ) )
      {
      foreach( $modules as $mid )
      {
      $mdl = new stdClass();
      $mdl->moduleid = $mid;
      $mdl->menuid = $table->get( 'id' );
      $this->db->insertObject( '#__modules_menu', $mdl );
      }
      }

      // Check if menu item is on the assign to all except list
      $query2 = $this->db->getQuery(true)
      ->select($this->db->quoteName('moduleid'))
      ->from($this->db->quoteName('#__modules_menu'))
      ->where($this->db->quoteName('menuid') . ' = -' . $table->get( '_location_id' ) );
      $this->db->setQuery($query2);
      $modulesExcept = (array) $this->db->loadColumn();

      // Add menu item to the exception list for all modules that have the original one in there
      if( !empty( $modulesExcept ) )
      {
      foreach( $modulesExcept as $mid )
      {
      $mdl = new stdClass();
      $mdl->moduleid = $mid;
      $mdl->menuid = $table->get( 'id' ) * -1;
      $this->db->insertObject( '#__modules_menu', $mdl );
      }
      }

      return true;
      }
      }
      `

and this is improved J4-5 compatible code by me:

`<?php
/***

public function onContentAfterSave($context, &$table, $isNew)
{
// Debugging output
Factory::getApplication()->enqueueMessage('Context: ' . $context);
Factory::getApplication()->enqueueMessage('Is New: ' . ($isNew ? 'Yes' : 'No'));

// Return if invalid context
if ($context != 'com_menus.item') {
    Factory::getApplication()->enqueueMessage('Invalid context, exiting.', 'error');
    return true;
}

// Only proceed if the item is new
if ($isNew) {
    // Get the original menu item ID from the submitted data (this assumes the ID is part of the submitted form data)
    $originalMenuId = Factory::getApplication()->input->getInt('id', 0);

    // Debugging output
    Factory::getApplication()->enqueueMessage('New Menu Item ID: ' . $table->id);
    Factory::getApplication()->enqueueMessage('Original Menu ID: ' . $originalMenuId);

    // Proceed with fetching assigned modules for the original menu ID
    $query1 = $this->db->getQuery(true)
        ->select($this->db->quoteName('moduleid'))
        ->from($this->db->quoteName('#__modules_menu'))
        ->where($this->db->quoteName('menuid') . ' = ' . (int) $originalMenuId);
    $this->db->setQuery($query1);

    try {
        $modules = (array) $this->db->loadColumn();
        Factory::getApplication()->enqueueMessage('Modules Found: ' . count($modules));
    } catch (Exception $e) {
        Factory::getApplication()->enqueueMessage('Error fetching modules: ' . $e->getMessage(), 'error');
        return false;
    }

    // Assign all found modules to copied menu item
    if (!empty($modules)) {
        foreach ($modules as $mid) {
            $mdl = new stdClass();
            $mdl->moduleid = $mid;
            $mdl->menuid = $table->id; // This is the new menu item ID
            try {
                $this->db->insertObject('#__modules_menu', $mdl);
                Factory::getApplication()->enqueueMessage('Assigned module ID: ' . $mid . ' to new menu item ID: ' . $table->id);
            } catch (Exception $e) {
                Factory::getApplication()->enqueueMessage('Error assigning module ID ' . $mid . ': ' . $e->getMessage(), 'error');
            }
        }
    } else {
        Factory::getApplication()->enqueueMessage('No modules to assign', 'warning');
    }

    // Continue with any additional logic for exception modules if needed...
} else {
    Factory::getApplication()->enqueueMessage('Item is being edited, not duplicating.', 'warning');
}

return true;

}
}`

Do you think that is a problem?

avatar rdeutz
rdeutz - comment - 2 Apr 2025

I am not here to judge and I know sometimes people have a history. I just want to have it here as nice as possible, that's all.

Related to the idea: As I said it is a good idea, it is something that can be solved with a plugin. But such a plugin wouldn't be merged into core, because we have better ways to solve it. So we have two options:

  1. You make it as a plugin, upload it to the JED (or whereever you want) and we can close the issue
  2. You (or someone else) can try to add it to the menu item model and implement the functionality there
avatar JoomlaTema
JoomlaTema - comment - 2 Apr 2025

@rdeutz thank you very much for your positive approach. I already have an extension on JED for this just wanted to know if it is possible to add that feature to joomla.

Add a Comment

Login with GitHub to post a comment