Problem/Motivation
Currently it's only possible to configure "CHECKBOXES DEFAULT VALUE", "DISABLE CHECKBOXES" and "HIDE CHECKBOXES" settings per entity type.
It would be great to have an ability to configure these settings per entity bundle as well.
Steps to reproduce
I can't unset "CHECKBOXES DEFAULT VALUE" for some entity bundles, I can only do it for the whole entity type.
Proposed resolution
In first comment I'm attaching the patch that adds `hook_entity_clone_settings_alter` hook where users can alter form settings and add settings per bundle.
function hook_entity_clone_settings_alter(array &$form_settings) {
// Adding settings per entity bundle.
$form_settings['taxonomy_term']['vocabulary_name']['default_value'] = false;
$form_settings['taxonomy_term']['vocabulary_name']['disable'] = false;
$form_settings['taxonomy_term']['vocabulary_name']['hidden'] = false;
}
Data model changes
Entity Clone Form settings array can now have settings per bundle if user add it in alter hook.
Issue fork entity_clone-3168732
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
skdrupal88Attaching the patch that adds `hook_entity_clone_settings_alter` hook where users can alter form settings and add settings per bundle.
Comment #4
dieterholvoet commentedCreated a merge request and rebased against #df77f98.
Comment #6
dieterholvoet commentedComment #8
dieterholvoet commentedComment #10
rajeshreeputraThis looks good, can we get it RTBC.
Comment #11
mably commentedWorks fine. Should get merged.
Comment #12
dpiet commentedUpdated patch in order to use in
composer.json, tested successfully on Drupal 11.1.5.Comment #13
mably commentedJust wondering why the
&& $is_cloneableconditions have been removed.An idea anyone?
Comment #14
mably commentedIn fact, doesn't seem to work if the checkbox are hidden, investigating.
Comment #16
mably commentedNew MR 96 works fine.
Handles multiple target bundles and reintroduce the
is_cloneabletest.Works even if all checkboxes are hidden.
Removed failing test incompatible with Drupal 11, all tests are green now.
RTBC.
Comment #17
mably commentedComment #18
mably commentedDefinitely not the best way to handle bundle value. Working on it.
Comment #19
mably commentedWe finally decided to simply display all the bundles on the configuration screen instead of using a hook:
What do you think?
Comment #20
mably commentedA new configuration option has been added, allowing to enable/disable the bundles feature at will:
Comment #21
mably commentedComment #22
mably commentedFYI it has been successfully deployed on a high traffic website (bordeaux.fr) for several weeks without any problem.
Comment #24
deaom commentedAdded a check as when you first save the settings, the form_settings are empty/null, so array_merge returns an error, as the first element is null (TypeError: array_merge(): Argument #1 must be of type array, null given in array_merge() (line 119 of /contrib/entity_clone/src/EntityCloneSettingsManager.php).) and thus preventing the settings form to be saved.
After the first save, the form_settings is populated.
This can be tested by installing the module and saving the settings, or if the module is already installed first uninstalling it and then installing again and saving the settings.
Leaving to Needs review, but based on the comments can be merged.
Comment #26
deaom commentedThe action test that is causing test failures is still removed here, but should be added back in once #3519053: Add action module as dev dependency. is merged.
Comment #27
deaom commentedBranch is re-based the action test is added back in and the tests are passing. Leaving status as is, but from my POV can be merged.
Comment #28
mably commentedPatch has been deployed in production for several months now. Everything is still running fine.
Comment #29
rajeshreeputraStarted merge train.
Comment #31
rajeshreeputra