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

Comments

stefan.korn created an issue. See original summary.

stefan.korn’s picture

Issue summary: View changes
stefan.korn’s picture

Assigned: stefan.korn » Unassigned
Status: Active » Needs review
StatusFileSize
new11.35 KB

Status: Needs review » Needs work

The last submitted patch, 3: improve_paragraphs_usage_module-3197540-003-patch.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

stefan.korn’s picture

StatusFileSize
new11.35 KB
stefan.korn’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 5: improve_paragraphs_usage_module-3197540-005.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

stefan.korn’s picture

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

liber_t’s picture

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

Exception: Notice: Undefined index: bundle
Drupal\paragraphs_usage\Service\ParagraphsUsageService->setUsedParagraphs()() (Line: 95)

in you patch I have coding standard errors too, can you fix these errors

FILE: project/web/modules/custom/paragraphs_usage/src/Controller/ParagraphsUsageController.php
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 5 ERRORS AND 3 WARNINGS AFFECTING 5 LINES
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
  9 | WARNING | [x] Unused use statement
 28 | ERROR   | [ ] Missing short description in doc comment
 33 | ERROR   | [ ] Parameter $paragraphs_usage_service is not described in comment
 77 | WARNING | [ ] Line exceeds 80 characters; contains 215 characters
 77 | ERROR   | [x] Comments may not appear after statements
 77 | ERROR   | [x] No space found before comment text; expected "// Url::fromRoute('entity.' . $entity_type_used . '.edit_form', [$entity_type_used =>
    |         |     $used_paragraph['bundle']]);" but found "//Url::fromRoute('entity.' . $entity_type_used . '.edit_form', [$entity_type_used =>
    |         |     $used_paragraph['bundle']]);"
 77 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
 83 | WARNING | [x] A comma should follow the last multiline array item. Found: ')'
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------------------------------------------------------------------------


FILE: project/web/modules/custom/paragraphs_usage/src/Service/ParagraphsUsageService.php
-------------------------------------------------------------------------------------------------------------------------
FOUND 40 ERRORS AND 5 WARNINGS AFFECTING 35 LINES
-------------------------------------------------------------------------------------------------------------------------
   1 | ERROR   | [ ] Missing required strict_types declaration
  12 | ERROR   | [x] Doc comment short description must end with a full stop
  14 | ERROR   | [x] Doc comment long description must end with a full stop
  20 | ERROR   | [ ] Missing short description in doc comment
  25 | ERROR   | [ ] Missing short description in doc comment
  30 | ERROR   | [ ] Missing short description in doc comment
  35 | ERROR   | [ ] Missing short description in doc comment
  36 | ERROR   | [x] Data types in @var tags need to be fully namespaced
  40 | ERROR   | [ ] Missing short description in doc comment
  47 | ERROR   | [ ] Missing short description in doc comment
  57 | ERROR   | [ ] Missing parameter comment
  58 | ERROR   | [ ] Missing parameter comment
  59 | ERROR   | [ ] Missing parameter comment
  70 | ERROR   | [x] Doc comment short description must start with a capital letter
  70 | ERROR   | [x] Doc comment short description must end with a full stop
  72 | ERROR   | [x] Doc comment long description must start with a capital letter
  72 | ERROR   | [x] Doc comment long description must end with a full stop
  74 | ERROR   | [ ] Missing parameter comment
  82 | ERROR   | [x] Doc comment short description must start with a capital letter
  82 | ERROR   | [x] Doc comment short description must end with a full stop
  84 | ERROR   | [ ] Description for the @return value is missing
  91 | ERROR   | [x] Doc comment short description must start with a capital letter
  91 | ERROR   | [x] Doc comment short description must end with a full stop
 133 | ERROR   | [x] Doc comment short description must start with a capital letter
 133 | ERROR   | [x] Doc comment short description must end with a full stop
 135 | ERROR   | [ ] Missing parameter comment
 135 | ERROR   | [ ] Missing parameter type
 136 | ERROR   | [ ] Missing parameter comment
 136 | ERROR   | [ ] Missing parameter type
 137 | ERROR   | [ ] Missing parameter comment
 138 | ERROR   | [ ] Missing parameter comment
 143 | ERROR   | [ ] Type hint "null" missing for $bundle_entity_type
 143 | ERROR   | [x] Expected 1 space between type hint and argument "$field_definition"; 2 found
 145 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
 149 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
 159 | WARNING | [x] A comma should follow the last multiline array item. Found: )
 160 | WARNING | [x] A comma should follow the last multiline array item. Found: ]
 165 | ERROR   | [x] Doc comment short description must start with a capital letter
 166 | ERROR   | [ ] Doc comment short description must end with a full stop
 166 | ERROR   | [ ] Doc comment short description must be on a single line, further text should be a separate paragraph
 170 | ERROR   | [x] Namespaced classes/interfaces/traits should be referenced with use statements
 172 | WARNING | [x] A comma should follow the last multiline array item. Found: )
 179 | ERROR   | [x] Doc comment short description must start with a capital letter
 180 | ERROR   | [ ] Doc comment short description must end with a full stop
 180 | ERROR   | [ ] Doc comment short description must be on a single line, further text should be a separate paragraph
-------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 20 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------------------------------
stefan.korn’s picture

Status: Needs work » Needs review
StatusFileSize
new12.09 KB

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

Status: Needs review » Needs work

The last submitted patch, 10: improve_paragraphs_usage_module-3197540-010.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

stefan.korn’s picture

Status: Needs work » Needs review
StatusFileSize
new12.14 KB
liber_t’s picture

Status: Needs review » Needs work

thanks

I have PHPCS errors again with your patch:

FILE: project/web/modules/custom/paragraphs_usage/src/Service/ParagraphsUsageService.php
----------------------------------------------------------------------------------------
FOUND 8 ERRORS AFFECTING 8 LINES
----------------------------------------------------------------------------------------
  56 | ERROR | [x] Additional blank lines found at end of doc comment
  64 | ERROR | [x] Additional blank lines found at end of doc comment
  90 | ERROR | [ ] Missing parameter comment
 155 | ERROR | [ ] Parameter comment must start with a capital letter
 157 | ERROR | [ ] Parameter comment must start with a capital letter
 159 | ERROR | [ ] Parameter comment must start with a capital letter
 161 | ERROR | [ ] Parameter comment must start with a capital letter
 207 | ERROR | [x] Additional blank lines found at end of doc comment
----------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------

Can you write the tests if possible ?

Best regards

stefan.korn’s picture

Status: Needs work » Needs review
StatusFileSize
new12.17 KB

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

liber_t’s picture

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.

Not problem, I will write the tests,

Best regards

Pooja Ganjage’s picture

StatusFileSize
new12.15 KB

Hi,

Creating a patch for solving PHPCS issue as suggested in #13 comment.

Please review the patch.

Thanks.

stefan.korn’s picture

No change to #14 here, so patch can be ignored imho.

bakop’s picture

Assigned: Unassigned » bakop
Status: Needs review » Active
bakop’s picture

StatusFileSize
new9.3 KB

Hi,

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.

bakop’s picture

Assigned: bakop » Unassigned
Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 19: improve_paragraphs_usage.patch, failed testing. View results

stefan.korn’s picture

Hi, thanks for writing tests. I think you missed the new file src/Service/ParagraphsUsageService.php in your patch

bakop’s picture

Humm yes, you're right !

It should be good now !

bakop’s picture

Status: Needs work » Needs review
liber_t’s picture

Assigned: Unassigned » liber_t

  • stefan.korn authored b28dc86 on 1.0.x
    Issue #3197540 by stefan.korn, bastienkopka, liber_t: Improve Paragraphs...
liber_t’s picture

Assigned: liber_t » Unassigned
Status: Needs review » Fixed

Thank you Stefan and Bastien

liber_t’s picture

Status: Fixed » Closed (fixed)