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.

Command icon 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

skorzh created an issue. See original summary.

skdrupal88’s picture

Status: Active » Needs review
StatusFileSize
new7.56 KB

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;
}

DieterHolvoet made their first commit to this issue’s fork.

dieterholvoet’s picture

Created a merge request and rebased against #df77f98.

dieterholvoet’s picture

Version: 8.x-1.x-dev » 2.x-dev

Rajeshreeputra made their first commit to this issue’s fork.

dieterholvoet’s picture

beloglazov91 made their first commit to this issue’s fork.

rajeshreeputra’s picture

This looks good, can we get it RTBC.

mably’s picture

Status: Needs review » Reviewed & tested by the community

Works fine. Should get merged.

dpiet’s picture

Updated patch in order to use in composer.json, tested successfully on Drupal 11.1.5.

mably’s picture

Just wondering why the && $is_cloneable conditions have been removed.

An idea anyone?

mably’s picture

Status: Reviewed & tested by the community » Needs work

In fact, doesn't seem to work if the checkbox are hidden, investigating.

mably’s picture

Status: Needs work » Reviewed & tested by the community

New MR 96 works fine.

Handles multiple target bundles and reintroduce the is_cloneable test.

Works even if all checkboxes are hidden.

Removed failing test incompatible with Drupal 11, all tests are green now.

RTBC.

mably’s picture

mably’s picture

Status: Reviewed & tested by the community » Needs work

Definitely not the best way to handle bundle value. Working on it.

mably’s picture

We finally decided to simply display all the bundles on the configuration screen instead of using a hook:

Bundles

What do you think?

mably’s picture

A new configuration option has been added, allowing to enable/disable the bundles feature at will:

Bundles toggler

mably’s picture

Status: Needs work » Needs review
mably’s picture

FYI it has been successfully deployed on a high traffic website (bordeaux.fr) for several weeks without any problem.

deaom made their first commit to this issue’s fork.

deaom’s picture

Added 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.

deaom changed the visibility of the branch 3168732-allow-to-alter to hidden.

deaom’s picture

The 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.

deaom’s picture

Branch 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.

mably’s picture

Status: Needs review » Reviewed & tested by the community

Patch has been deployed in production for several months now. Everything is still running fine.

rajeshreeputra’s picture

Started merge train.

rajeshreeputra’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.