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.
Labels |
Added:
No Code Attached Yet
|
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.
If you already have created an extension for this I am confused what you are asking for.
Brian do you have to answer all the things related Joomla? I am confused about this too.
I kindly request that you do not respond to any of my future posts on any platform please.
Guess my question was too hard to answer.
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?
@JoomlaTema if you want this feature, you can make a PR for it. No need to be rude. Thank you.
Labels |
Added:
Feature
|
probably because it doesnt actually work as the plugin runs (and fails) when saving anything
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.
It means that it has been flagged as a feature request as opposed to a bug report
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.
Your plugin doesn't work. I tested it!!
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.
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.
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.
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.
With your plugin enabled it is triggered and fails when you save an article or a custom field
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.
As I said - it fails when you save an article or a field - i do not lie
- 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
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.
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.
@JoomlaTema if you want this feature, you can make a PR for it. No need to be rude. Thank you.
"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?
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
I think i ve been able to create a PR. JoomlaTema/Duplicate-Menu-Items-With-Its-Module-Assignment-Option#1
You have not completed the last step
Actually you havent followed any of the steps
I deleted branches I think. I should start over again following instrucitons.
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.
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.
I have no idea who you are
and for future reference when taking copyright code from someone else even if it is GPL you can not change the copyright to yourself.
@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
/**
defined('_JEXEC') or die;
/**
Copy Module Assignments Plugin
/
class PlgContentCopymoduleassignments extends JPlugin
{
/*
/**
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
/***
@Package jt_copymoduleassignments Joomla.Plugin
@copyright Copyright (C) http://www.joomlatema.net, Inc. All rights reserved.
@author JoomlaTema.Net
@link http://www.joomlatema.net
*/
defined('_JEXEC') or die;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Factory;
/
Copy Module Assignments Plugin
*/
class PlgContentJt_Copymoduleassignments extends CMSPlugin
{
protected $db;
public function __construct($app, $plugin)
{
parent::__construct($app, $plugin);
$this->db = Factory::getDbo();
}
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?
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:
That cant really work as the menu item doesnt contain the module assignment. Its the other way around the module contains the menu assignment