First of all: Nice module, was searching for this.
Problem/Motivation
It seems to me that the module has some flaws (it's a fairly young module, so this is not too surprising). I spotted the following problems:
- the negate option is not working properly (option to exclude instead of include paragraph types in field settings)
- it's not working with all entities. For example it does not work with user entity (probably not working with entities that do not have bundles)
- It seems to me that the module is loading and walking through every entity in the system, which might be a performance issue especially if there are a lot of entities in a system (maybe #3194695: Some 'Allowed memory size' fatal errors is already poiting in that way). This is the code line: https://git.drupalcode.org/project/paragraphs_usage/-/blob/862877d989959.... I am not sure, why this should be necessary.
I am providing a somewhat bigger patch to address the mentioned issues.
Steps to reproduce
- Use the negate option in paragraph field settings
- Use a paragraph field on user (admin/config/people/accounts/fields)
Proposed resolution
Refactor code to fix the issues
Remaining tasks
Provide a patch
User interface changes
none
API changes
introducing a Service and handling the search for usage different
Data model changes
none
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | improve_paragraphs_usage-202102191613.patch | 18.6 KB | bakop |
| #19 | improve_paragraphs_usage.patch | 9.3 KB | bakop |
| #14 | improve_paragraphs_usage_module-3197540-014.patch | 12.17 KB | stefan.korn |
Comments
Comment #2
stefan.kornComment #3
stefan.kornComment #5
stefan.kornComment #6
stefan.kornComment #8
stefan.kornnot sure why the taxonomy test is failing. If I am adding a paragraph field to a taxonomy vocabulary I do not experience the warning message given in test.
Comment #9
liber_tThank you for this patch,
In these tests (testCheckIfUsed and testCheckIfNotUsed), phpunit create paragraphs with term but if node module is enable and that node module doesn't have bundle, we have theses notices.
in you patch I have coding standard errors too, can you fix these errors
Comment #10
stefan.korn@liber_t: Thanks for coming back quickly on this. And thanks for explanation of taxonomy test, now I see.
Reworked the patch to hopefully pass tests and coding standards.
Comment #12
stefan.kornComment #13
liber_tthanks
I have PHPCS errors again with your patch:
Can you write the tests if possible ?
Best regards
Comment #14
stefan.kornmore coding standard fixes.
Regarding tests: You mean test for user entity and test for negate option? I am not very experienced with writing tests. That might take some time.
Comment #15
liber_tNot problem, I will write the tests,
Best regards
Comment #16
Pooja Ganjage commentedHi,
Creating a patch for solving PHPCS issue as suggested in #13 comment.
Please review the patch.
Thanks.
Comment #17
stefan.kornNo change to #14 here, so patch can be ignored imho.
Comment #18
bakopComment #19
bakopHi,
I took the patch of stefan.korn and i fixed the phpstan, phpmd et phpcs.
I have created tests for the paragraphs on a user and for the inclusion and exclusion part.
Can you check please ?
Thanks.
Comment #20
bakopComment #22
stefan.kornHi, thanks for writing tests. I think you missed the new file src/Service/ParagraphsUsageService.php in your patch
Comment #23
bakopHumm yes, you're right !
It should be good now !
Comment #24
bakopComment #25
liber_tComment #27
liber_tThank you Stefan and Bastien
Comment #28
liber_t