Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Looks like Diff doesn't support fields which are wrapped into a field collection.
From what I get, it seems that a diff is applied on the field collection entity rather than the fields inside. So, it notices a change but cannot render what actually changed...
I'll try to look closer at the source.
Comment | File | Size | Author |
---|---|---|---|
#23 | fieldcollection-diff-example.png | 236.95 KB | skorzh |
#23 | field_collection-diff_support-1595702-23.patch | 3.43 KB | skorzh |
| |||
#13 | field_collection_diff.png | 16.85 KB | heddn |
#9 | baddiff.jpg | 445.83 KB | federico.parra |
#4 | field_collection-1595702-4-diff-field-support.patch | 2.27 KB | rocketeerbkw |
Comments
Comment #1
Alan D. CreditAttribution: Alan D. commentedIt is only returning the FC id.
Changes that I will hopefully include are:
Meaning that you can only show the ID, or the rendered FC with selectable view mode and markdown options.
Comment #2
Alan D. CreditAttribution: Alan D. commentedThis is a patch for the new Diff 7.x-3.x branch. This provides field support via Diffs internal callback via it's own implementation of hook_entity_diff().
It provides a view mode and markdown options for the field when it is rendered for the comparison engine.
Note: It does not attempt to implement hook_entity_diff() itself, which would provide diff functionality on the entity itself (I'm not sure what other than fields would be required by Field Collection itself....)
Comment #3
fago#2 works for me, but when used two markdown options appear in the field_collection field settings. There is one "markdown callback" added in by diff.module and the "Raw Diff markdown callback" added in by the patch, whereas only the latter seem to take effect. I don't know what's the point in the form is then though, maybe a bug in the diff module? We should sort this out though.
Note: The @file comments needs an update.
Comment #4
rocketeerbkw CreditAttribution: rocketeerbkw commentedI don't think the extra raw markdown setting is needed as Diff module provides a default markdown setting.
The current functionality of comparing complete field collection output works OK, it would be awesome if we could invoke the individual field diff functions though... I tried doing this and failed hard. Here's an updated patch that addresses #3 in the meantime.
Comment #5
mitchell CreditAttribution: mitchell commentedTagging.
Comment #6
3CWebDev CreditAttribution: 3CWebDev commentedI need to have diff support for field collections also and found this thread, however I am not able to get it functioning. Can someone please explain to me how to get this to work? I tried added the patch from #2 into a module but the collection fields are still ignored by the diff comparisons.
Comment #7
federico.parra CreditAttribution: federico.parra commentedHi! I tried patch in #6 and found not difference to the usual display of diff when
it comes to compare field collection.
It is very user unfriendly! Isn't a way to get a more visually easy/understandable comparison?
Thanks,
Federico
Comment #8
Alan D. CreditAttribution: Alan D. commentedReally, the only benefit of this patch is to provide the FC id. The default diff modules use of the view modes settings mimic the other options that the display settings provide.
Open for suggestions here, remembering that FC item is simply a reference to another entity. One possible solution would be to alter diff_entity_fields_diff() so that it could insert an internal diff of the referenced entity (i.e. Field collections, Term references, Entity References, Node References, ...). I have added an issue for that here: #1897196: Support recursive Diffs of fields within fieldable entity references - Field collection, Entity reference, ...
Comment #9
federico.parra CreditAttribution: federico.parra commentedThis is what Diff comparison looks like when comparing two revisions of a node where several Field Collection entities have been edited/added/removed:
As you can see only a developer would make any sense of this view.
The Diff should show the different in content, there should be no HTML at all in the screen.
Only the difference in texts in text fields, difference in choices in multiple choices fields, etc.
Is this even in the roadmap?
In my use case I need necessarily to be able to display to my client all the changes (a kind of undo-history)
he has done in the past to the node, and the node is full of Field Collections some of which contain Field Collections
within them!
Ideas?
Best and thank you
Federico
Comment #10
Alan D. CreditAttribution: Alan D. commentedNo test environment, and fuzzy with the inner workings as it has been a couple of months since I last looked through the code, but go to admin/config/content/diff and select marked down as default would be a good start. If you enable the "Revision comparison" display mode on this content type, you can hide these from the standard diff comparisons. (Names and URL from latest dev version)
Then there are few paths to follow up.
1) To create a new formatter for the FC to show the bits you want. Probably difficult to create a global solution for this.
2) to find and modify the current formatters to remove the edit links when in the view mode "diff_standard". Least the HTML would be tidier.
3) to make some formatter settings to control the edit / delete links. Again, just makes the HTML output cleaner.
No running FC environment at the moment to check this, but 2 and 3 may already be options in the module. Or there could be an existing formatter that will render the output cleaner. Enabling Revision comparison display mode gives you some control at least :)
Comment #11
federico.parra CreditAttribution: federico.parra commentedThank you so much Alan!!
I will try these options and report back.
Thank you,
Federico
Comment #12
Renee S CreditAttribution: Renee S commentedFederico, any luck? Running into this and it's yucky :)
Comment #13
heddnHere's a solution to try while we get a more permanent thing in place. It might even give us some ideas on how to resolve it more permanently.
Implement hook_entity_diff_alter(). For each of the field collections, pass the #old and #new html through a function that cleans up the HTML a little. I haven't tested it with multi-valued fields in a collection, but it works for single values.
Comment #14
sylwester CreditAttribution: sylwester commented@heedn, would you mind explaining #13 in more details? How would you pass values in hook_entity_diff_alter?
Comment #15
heddnComment #17
jorges CreditAttribution: jorges commentedAs this still remains unresolved, you might be interested in my workaround. I have a Field Collection
field_test
, every of the possibly unlimited items holding 2 text fieldsfield_test_arguments
andfield_test_expected content
. (But the solution allows more text fields.)Key feature is the
$template
variable, where I define how the collection text fields shall be rendered. In this example, the get rendered asexample_test_arguments → example_test_expected_content
.Comment #18
manuel.adanThis is also needed in D8 version. Open a new issue for that?
Comment #19
Bhuvana_Indukuri CreditAttribution: Bhuvana_Indukuri commentedCan someone confirm if any of these approaches were tested and if there is a workaround to this issue.
Comment #20
Bhuvana_Indukuri CreditAttribution: Bhuvana_Indukuri commentedThanks @Jorges !! #17 worked for me.
Comment #21
hanoiiI tried @heddn approach with a different cleanup function and it's somehow quick to make it work, however, only after doing that I noticed there's a markdown diff on the link, not sure how new that is, but it does work pretty good. And you can configure it so that it's the default state of the diff.
Comment #22
Amir Simantov CreditAttribution: Amir Simantov commentedHi, thanks jorges for #17 - it works for me.
One fix, though: In function X_render_field_collection_revision I have wrapped the foreach with a condition:
if (isset($field_collection[LANGUAGE_NONE]))
This is needed when a field is empty.
If anybody needs to support an inner field that is a reference entity, then instead of checking for
One should check for
$fcitem->{$field_collection_field_name}[LANGUAGE_NONE][0]['target_id']
I needed the title so my code inside the function to render the item is:
This is not a nice code, but it works ;)
Comment #23
skorzhHi!
My patch provides diff support for Field collections.
Looking forward for feedback.
Comment #25
jmuzz CreditAttribution: jmuzz commentedLooks good. Thanks for the patch!
If there are any issues with the new diff support please create a new issue rather than reopen this one.
Comment #27
Amir Simantov CreditAttribution: Amir Simantov commentedHi. I was wondering why it is not committed to dev... Thanks.
Comment #28
Alan D. CreditAttribution: Alan D. commentedIt's both committed and present in the download
https://cgit.drupalcode.org/field_collection/tree/field_collection.diff....
https://www.drupal.org/project/field_collection/releases/7.x-1.x-dev
Will only kick into life with Diff 7.x-3.x and after the caches are fully cleared (aka you did run update.php after updating? or drush cc or /admin/config/development/performance, or admin menu clear all caches, ...)
Comment #29
Amir Simantov CreditAttribution: Amir Simantov commentedHi Alan, thanks for the clarification. However, I did not see here, in this very issue, any commit... How can one know, then, that it was committed? It is the first time that I see something like this in drupal.org, that is, that a patch was committed and in the issue it is not said it was. Could you please explain this to me so I can know better for next time? Thanks again, Amir
Comment #30
NWOM CreditAttribution: NWOM commented@Amir Simantov check comment #24.
Comment #31
Amir Simantov CreditAttribution: Amir Simantov commentedHo, "authored" is like "submitted" - did not know that. Thanks!