Closed (fixed)
Project:
Protected Node
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
8 May 2017 at 14:33 UTC
Updated:
10 Jun 2017 at 15:29 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
grimreaperHello,
Thanks for the report.
In protected_node.module, protected_node_and_attachment() (http://cgit.drupalcode.org/protected_node/tree/protected_node.module#n345), there is some code for field_collection integration, I guess we can do something similar for paragraph integration.
I will see (next weekend) how to add a hook for that so other modules can add its own integration.
Or if you can provide a patch for that it would be great.
Comment #3
LauraRocksHi! Thank you!So, after short research, actually the "simple" paragraphs module integration can be done exactly like the field collection was made. I attached a very basic patch for that. But since there is only two lines that differ from the field collection; file usage type is either field_collection or paragraphs_item and then same with the entity_load, it's pretty much duplicate code. The query part would be easy to join but I don't know about the entity_load part.
And the paragraphs part only works when the paragraph is attached directly to the node. Actually if the hostEntity is not a node, but another paragraph, then gathering the "nids" would only cause problems so that's why I added the check
if ($paragraphs_item ->hostEntityType() == "node")
Then there is a question when someone has both of these in their site...
Comment #4
grimreaperHello,
Thank you very much for your patch.
I am sorry but I won't have much time this weekend to go further in the issue.
But is there a function in the paragraphs module to recursively get the host entities in case of paragraphs inside paragraphs?
Also before commiting the patch, it would be nice to write an automated test. If you do not have the time for that I will do it before merging the patch I will do it.
Thanks again for your contribution.
Comment #5
grimreaperHello,
I have tested your patch and it failed.
I don't why but on my environment the $paragraphs_item->hostEntityType() and other hosEntity methods returned NULL.
Here is a patch that fixes the bug, I managed the case of paragraphs inside paragraphs.
Also I fixed some coding standards mistake.
Can you please test this last patch?
And let's trigger the automated tests.
Comment #6
LauraRocksThank you for your work on this, this was actually my second patch ever, first one I did one day before, so I am not at all surprised that there was coding standard mistakes, I will look into them more in future. As for how I got my patch to actually work is a wonder, now with another fresh install, it didn't work for me either.
However, your patch is working great! And it indeed handles the case of nested paragraphs also. But as I really don't know how to write tests (another thing to look into), I just tested this manually.
I still wonder, should we consider the situation where both of those modules is installed...? I have never used them both in same project, but I don't know if there is some use cases where that would be needed...
Comment #7
grimreaperThanks for testing.
Currently the tests on this project are broken on the testbot, I never managed to figure out why. So I will try to have tests that pass locally.
I think I will commit your patch so you can be credited for your efforts and then my changes to have something working ;)
About the situation of both modules enabled, I don't think it will be a problem.
Back to "needs work" to remember to write the tests.
Comment #9
grimreaperHello,
Patch commited.
I made some automated tests that are green locally.
Also I found a warning message during my tests due to the paragraph module. A fix is already commited but not in the last version: http://cgit.drupalcode.org/paragraphs/commit/?id=68343ef8da09d8427c8936b...
I will publish a new version soon.