BobRay / MyComponent

Development environment for creating MODX extras
https://bobsguides.com/mycomponent-tutorial.html
23 stars 13 forks source link

some not created menues #12

Closed Bruno17 closed 11 years ago

Bruno17 commented 11 years ago

is this correct to have a

return $menus;

after each menuField in menuadapter?

            foreach($menuFields as $k => $fields) {
                $actionFields[$i]['id'] = $i + 1;
                /* do Action */
                $code .= "\$action = \$modx->newObject('modAction');\n";
                $code .= "\$action->fromArray( ";
                $code .= var_export($actionFields[$i], true);
                $code  .= ", '', true, true);\n";

                /* do Menu item */
                $code .= "\n";
                $code .= "\$";
                $code .= "menus[";
                $code .= $i+1 . '] = ' . "\$modx->newObject('modMenu');\n";
                $code .= "\$";
                $code .= "menus[";
                $code .= $i + 1 . ']->fromArray( ';
                $code .= var_export($menuFields[$i], true);
                $code .= ", '', true, true);\n";
                $code .= "\$";
                $code .= "menus[";
                $code .= $i + 1 . ']->addOne(';
                $code .= "\$action);\n";
                $code .= "\nreturn \$menus;\n";

                $tpl .= $code;
                $i++;
            }
BobRay commented 11 years ago

No, It's definitely not correct. Looking at the code, I don't think there's an easy fix. In order to handle multiple menus, I think it would be have to be refactored along the lines of the static createTransportFile() method in the ObjectAdapter (which I don't think can be used because menus are so weird).

As you probably know, the data used by createTransportFile() is in the big ObjectAdapter::$myObjects array(). If you're going to work on this, you might want to uncomment line 131 of the ExportObject snippet to get a look at that array. I used to have code to dump that array to a file called objectarray.txt, but it appears to be gone.

I will take a look at this when I have time, but I'm swamped right now.

BobRay commented 11 years ago

OK, I carved out a little time to work on this. Not as difficult as I thought. I need to do some tests, but in the meantime, just move the $code = ''; line inside the foreach (at the top), remove the $code .= "\nreturn \$menus;\n"; line and put

$tpl .= "\nreturn \$menus;\n";

Just below the closing brace of the foreach().

BobRay commented 11 years ago

I've pushed the changes. Should be all fixed. I noticed a comment (LOL): /* ToDo: make this work */