Follow-up to #1010850: Update MigrateFieldHandler to work with migrate-7.x-2.4 and later
I have a link field where I always want to set a title but not always I have a link. In the link field settings is an option for that:
Optional URL: If checked, the URL field is optional and submitting a title alone will be acceptable. If the URL is omitted, the title will be displayed as plain text.
But on migration this is not allowed, because csandanov added in #53 the code $values = array_filter($values);
to the patch with the comment:
Patch #45 doesn't consider if URL is NULL and we always have empty record in link field.
Empty fields should be detected somehow else. Is there a validation hook for that?
Comment | File | Size | Author |
---|---|---|---|
#5 | link-migration-allow-title-without-url-2537248-5.patch | 1.17 KB | Ronino |
#4 | link-migration-allow-title-without-url-2537248-4.patch | 1.04 KB | osopolar |
Comments
Comment #1
osopolarPatch removes
$values = array_filter($values)
and checks if url or title is set before adding the value. I am still not sure if there isn't a more appropriate function to validate the value, is it?Comment #3
osopolarComment #4
osopolarFIX: Check
'required' != $instance['settings']['title']
not.'required' != $item['title']
Comment #5
Ronino CreditAttribution: Ronino as a volunteer commentedI can confirm that empty URL's are not migrated. But it seems like some things are different now either in the link or the migrate module as patch #4 doesn't change anything for me. I use link 7.x-1.4 and migrate 7.x-2.8.
In my patch I removed the line with array_filter(), too, but only because it does nothing. Arguments are removed from $values before and there's nothing to do for array_filter() as there are only array elements for non-empty URL's.
This patch adds elements to $values for those empty URL's based on the maximum delta it finds in $values. But it then also keeps all records (without checking URL and title for being optional like #4 does) as I think it should be up to the developer what data to import. For example, there is no automatic validation when importing nodes and I don't think this should be different here.
Comment #6
Ronino CreditAttribution: Ronino as a volunteer commentedMarked #1938850: Migrate fails to import links with title but empty url. as duplicate of this issue.
Comment #8
Ronino CreditAttribution: Ronino as a volunteer commentedTests are fully passed.
Comment #9
DamienMcKennaThis is good, thank you.
I made some refinements to the comments.
Comment #10
DamienMcKennaCommitted.