Now, there can't be a simpler one than this. The documentation is on https://drupal.org/node/2154215 and with extract, the example will be the role migration once that lands. Postponed on #2154209: Process refactor: multiple handling

CommentFileSizeAuthor
#7 2154563_7.patch2.6 KBchx
flatten.patch2.19 KBchx
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chx’s picture

Status: Postponed » Needs review
dawehner’s picture

+++ b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/process/Flatten.php
@@ -0,0 +1,29 @@
+    return iterator_to_array(new \RecursiveIteratorIterator(new \RecursiveArrayIterator($value)), FALSE);

Can we have some comment which explains how this works together?

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

chx told me that we use this kind of code without docs in other places.

chx’s picture

webchick’s picture

Status: Reviewed & tested by the community » Fixed

None of us in IRC could figure out what that line of code did either. :P~ And just because we have other horrifying examples in core is no reason to add more. ;)

Added some more docs, including a pointer to the handbook page, and...

Committed and pushed to 8.x. Thanks!

webchick’s picture

Status: Fixed » Needs work

Huh. Well something obviously went horribly wrong there. :P Reverted for now since I introduced a syntax error by missing half the file. :( We want it to basically look like https://gist.github.com/webchickenator/94e5605ce970a7b688c0 but I don't have time right now to dig into why that's not working when applied as a patch.

chx’s picture

Status: Needs work » Needs review
FileSize
2.6 KB

Manually edited patches need to be fixed by rediff from patchutils.

chx’s picture

Status: Needs review » Reviewed & tested by the community

This was almost committed so surely it's ready.

chx’s picture

And thanks much for fixing Migrate docs. I have stated today in the podcast (and even demonstrated there as well) one really loses touch with reality after a time -- I have been using recursive iterators for years now so I had no clue they were a problem -- indeed when I looked at the need to have a flatten plugin this line of code came naturally to me.

Another thing we could do

    $new_value = array();
    array_walk_recursive($value, function($a) use (&$new_value) { $new_value[] = $a; });
    return $new_value;

Is that better?

larowlan’s picture

I understood the intent of 9 faster than the earlier approach, due to lack of familiarity with the RecursiveIteratorIterator class

webchick’s picture

Status: Reviewed & tested by the community » Fixed

No, I think the code is fine, it just needed some explanation, which is there now. :)

Committed and pushed to 8.x, this time without breaking HEAD. ;) Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.