- Issue created by @matthieuscarset
- First commit to issue fork.
- Merge request !9014Issue:3463868 - Two #config_targets error when used on a text_format form element → (Open) created by vinmayiswamy
- 🇮🇳India vinmayiswamy
Hi, to resolve this issue, the following modifications were made to the
ConfigFormBaseclass:Enhanced Handling of
text_formatElements:
Added a special case handling fortext_formatelements within thedoStoreConfigMap()method.
This ensures thattext_formatelements are properly mapped to their value and format properties by updating the$maparray with these keys.Code Modifications:
doStoreConfigMap()Method:copyFormValuesToConfig()Method:
Checked if the element type is
text_format.
If true, the#config_targetfortext_formatfields is now mapped separately for both.valueand.formatproperties. This prevents the conflict of having two#config_targetspointing to the same configuration key.
Added logic to handle#array_parentsas arrays and applied proper mapping to avoid duplication issues.Updated to ensure that
$array_parentsis always treated as an array when retrieving form elements.
Added logic to skip the iteration if the parent path is not found and to ensure that elements have the#config_targetproperty set before processing.The modifications ensure that
text_formatelements are handled correctly by addressing the issue of duplicate configuration targets. By implementing specific logic fortext_formatfields and updating the configuration mapping process, the fix prevents validation exceptions and maintains consistency across the configuration form.Please review the changes to confirm that they address the issue effectively. Your feedback and suggestions for further improvements are greatly appreciated.
Thanks!
- Status changed to Needs review
over 1 year ago 7:25am 1 August 2024 - Status changed to Needs work
over 1 year ago 1:03pm 1 August 2024 - Status changed to Needs review
about 1 year ago 2:06pm 8 August 2024 - 🇮🇳India vinmayiswamy
Hi, I have added a PHPUnit test case to verify the changes made to the
doStoreConfigMapmethod in theConfigFormBaseclass. This test is designed to check how the method handlestext_formatelements with#config_targetproperties and ensures that the configuration mappings are updated correctly.In this test, I created a mock of
FormStateInterfaceto simulate the form state and validate that thedoStoreConfigMapmethod interacts with it as expected. SincedoStoreConfigMapis a protected method, I used reflection to access and invoke it.The test involves setting up a mock for
FormStateInterfaceand specifying an expectation for the set method to be called with the key 'config_targets' and a particular map. I then used reflection to invoke the protecteddoStoreConfigMapmethod on a mocked instance ofConfigFormBase. The sample form element defined includestext_formatand#config_targetattributes, as well as#array_parentsfor validation.The focus of the test is to ensure that the
config_targetsmap contains the correct entries and values fortext_formatelements, verifying that the#config_targetproperties are processed appropriately.Could anyone please advise if a functional test is also required in addition to this unit test? While this unit test verifies the method in isolation, a functional test might be needed to assess its behaviour within the broader application context.
As this is my first attempt at writing test cases, I would really appreciate any feedback on whether this test is thorough and meets all necessary criteria. If there are additional scenarios to consider or best practices to follow, your guidance would be very helpful.
Please review the test case and let me know if any further steps are needed or if improvements should be made.
Thanks!
- Status changed to Needs work
about 1 year ago 3:23pm 13 August 2024 - 🇮🇳India vinmayiswamy
Hi, I have updated the issue summary. Please review the changes and let me know if any further changes are required. Thank you!
- Status changed to Needs review
about 1 year ago 4:22am 14 August 2024 - Status changed to RTBC
about 1 year ago 6:07pm 14 August 2024 - 🇺🇸United States smustgrave
https://git.drupalcode.org/issue/drupal-3463868/-/jobs/2381869 shows the test coverage so removing that tag.
Believe feedback has been addressed.
- Status changed to Needs work
about 1 year ago 7:13am 30 August 2024 - 🇬🇧United Kingdom catch
I think we should look at whether this can be done without special-casing text_format in the config system - the exception is designed to prevent broken usage, and if the usage isn't broken then we should be able to account for that. Other config could have a similar structure.
- First commit to issue fork.
- Merge request !10182Issue #3463868: Two #config_targets error when used on a text_format form element → (Open) created by idebr
- 🇳🇱Netherlands idebr
MR 10182 implements an alternative solution where the code ends up as follows:
$form['parent']['akey']['asubkey'] = [ '#type' => 'text_format', '#title' => $this->t('Subkey title'), '#format' => $this->config('mymodule.settings')->get('akey.asubkey.format'), '#config_target' => "mymodule.settings:akey.asubkey", ];I'm not sure ConfigTarget was intended to control any element property other than #default_value when reading the change record at https://www.drupal.org/node/3373502 →
- 🇨🇦Canada nickdickinsonwilde Victoria, BC (T'So-uke lands)
MR 10182, resolves the issue, and seems like the least noisy solution and most future safe.
- Status changed to Needs review
9 months ago 2:58pm 11 February 2025 - 🇺🇸United States smustgrave
Yea the new MR dropped the test coverage from the original MR. One should also be close.d
- Status changed to Needs work
6 days ago 4:10pm 31 October 2025