When validating that a paragraph item is empty or not, with paragraph's implementation of hook_field_is_empty(), paragraphs_item_is_empty() is no longer called. It used to be, but commit 44d19785bc9b1abc6e53db675d2b5463db41ec6e removed usage of it, which is a bit sad. This also means that the hook_paragraphs_is_empty() hook is no longer invoked, which was quite useful for allowing other modules to override whether a paragraph was empty or not.
My use case: I have some fields in a paragraph that are considered 'content', and some that are considered for 'style'. If all the content fields in the paragraph entity are empty, even if the style ones aren't, I want to consider the paragraph empty, and avoid saving it.
More generally, paragraphs_item_is_empty() was useful for avoiding saving paragraphs that have no field values set in them, which even without the hook_paragraphs_is_empty() hook, was useful functionality.
Either paragraphs_item_is_empty(), and hopefully the usage of hook_paragraphs_is_empty() for other modules, should be used again - or removed from the module. I don't quite understand the design decision made in the aforementioned commit for why the usage was originally removed, so I'll defer to anyone who can convince me they should just be removed, even if that does mean useful functionality is lost.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | empty-items-2497059-2.patch | 1.5 KB | jeroen.b |
Comments
Comment #1
jeroen.b commentedI can't remember why I removed paragraphs_item_is_empty(). Looking at the commit, it does not seem like a wanted change. I'd accept a patch to re-introduce it, possibly with some extra tests.
Comment #2
jeroen.b commentedPlease see if attached patch fixes this for you.
I think the reason I removed this is that hook_field_is_empty() automatically cleans out items that are empty.
Mostly, this isn't something you would like, you want deletions to be user triggered. paragraphs_item_is_empty() checked the fields for field_is_empty to see if the embedded fields are empty. The change makes paragraphs_item_is_empty() only execute the paragraphs_is_empty_alter, what do you think?
Comment #3
Stanto commentedHi Jeroen,
That seems to be a really elegant solution to bring back the hook paragraphs_is_empty.
Works great for me so far. I'd love to see it part of the next release.
Thank you!
Comment #4
jstollerThere've been a pile of commits to dev recently and the paragraphs_item_is_empty() function is once again being called, so in an effort to cleanup the Paragraphs issue queue I'm closing this ticket and marking it "outdated." However, if you find there is a problem with how this was implemented in the latest Paragraphs 7.x-1.x-dev release than please feel free to open a new issue.