Support from Acquia helps fund testing for Drupal Acquia logo

Comments

imre.horjan’s picture

I've written a patch, which exports menu links using UUIDs for Features version 2.x-dev.
The modifications was originally written for version 2.3, but ported a patch to the dev version.)

imre.horjan’s picture

Status: Active » Needs review

Changing the status to Needs review

imre.horjan’s picture

Title: Correct UUID export and import of menu items linking to nodes, terms and users » UUID export and import of menu items linking to nodes, terms and users
Issue summary: View changes
imre.horjan’s picture

Issue summary: View changes
imre.horjan’s picture

FileSize
5.01 KB

Here's a modified patch file.

The code in the previous patch didn't correctly identify the imported / existing menu items, so menu items were created multiple times on consecutive feature reverts.

This is fixed. Already imported / existing menu items will be identified and won't be created multiple times.

There's a side effect using this patch:
Menu items compontent will always be in the 'Overriden" state.
That's because uuid paths are used in exported module code, while internal paths are set up for menu items in the database. Features diff identifies that as a manual override.

JurriaanRoelofs’s picture

Thanks! I tried the patch and it succesfully imported menu links as part of my distribution profile.
What is odd though is that imported menu links do not get added during profile installation. It might be relevant that the menu links and the content that is linked are in the same feature module, so maybe the menu link features fails initially because the content is not added yet, or maybe a cache clear is needed after the content is added, before the links are added.

Using a little hack in my feature module's install file the import of menu links is completed after profile installation:


module_load_include('module', 'features');
features_revert(array('sooperthemes_glazed_config' => array('menu_links')));

JurriaanRoelofs’s picture

Status: Needs review » Needs work

major issue: after adding menu links to a feature the frontend menu actually links to a uuid path instead of a pathauto path. this is not good for SEO and not an option for existing sites.

update: I see I didnt have this problem on the site to which I exported the feature and the difference I noticed was the feature being enabled on the latter and disabled on the former site. When I enable the feature on the source site the menu links turn back to normal

imre.horjan’s picture

Hi Jurriaan!
As far as I understand it works fine if you enable the exported feature module.

Menu items are exported using the UUID path, however in some cases the UUID path couldn't be resolved to an internal path (for example you forgot to export the corresponding node or it's in a module which is reverted later).
In this case the menu item will be created using the UUID path. I think it's better than skipping / hiding the menu item.

The problem you mentioned in #6 might be because components handled by Features itself are reverted before other contrib module components (like UUID nodes).

I think the best solution would be to refactor the code from Features module into UUID Features module.

When I started to write the code, it was easier to start with Features than UUID Features.

JurriaanRoelofs’s picture

I've rebuilt my menu and been spending all day trying to make it work but this is what happens:
1. Menu is fine
2. I add menu links to a feature and export it
3. The menu_links table gets updated, replacing my node links with uuid links, setting router path from node/% to uuid and setting the link_path to uuid too, making my menu turn into a uuid mess on the frontend.

update: I just noticed that if I revert the feature with the (bodged) menu links, the menu is back to normal. I have to delete a menu item before reverting otherwise it will show "default" status. I'm hoping it will stay working now but I still recommend anyone using this code to backup your database (often) when playing around.

imre.horjan’s picture

Backing up the database before trying untrusted code is a good practice.

Jurr, it would be nice to know whether you started working with patch #1, or you got involved with patch #5.

UUID paths are replaced by it's internal paths by revert.

If you find any menu item not working fine, simply delete it, and the next revert will create it right.

You may be right regarding router paths.
When you export a feature module the link path is set to the UUID path of the target entity, and router path is set to 'uuid'.
When reverting that feature UUID paths are replaced by the internal path, and the router path should also be set back to 'node/%' for example. This may not work correctly.

I need some time to check and fix that.

imre.horjan’s picture

This comment is posted twice accidentally.

JurriaanRoelofs’s picture

Hi, I used the patch in comment #5, I'll post back when I will work on my menu links feature again and see if I can figure out if reverting fixes the problem

hswong3i’s picture

I am now applying #5 for DruStack http://cgit.drupalcode.org/drustack/commit/?id=b722665
Will report if error happened ;-)

imre.horjan’s picture

We still have some problems.
The patch works in an automated deployment environment, in which case you export features on one site, and revert them on the other, but causes problems when you export and revert them on the same site.

When you export, your menu paths are changed unexpectedly, so you always need to revert after export.

mattsqd’s picture

I worked off of #5 to allow UUIDs to always stay in the info file instead of reverting back to node IDs.

mattsqd’s picture

Added another missing section where a link was loaded but uuid path not added for parent_identifier.

mattsqd’s picture

mattsqd’s picture

Found another issue where the uuid link was saved instead of the internal link so links were not displaying correctly.

kenorb’s picture

Status: Needs work » Needs review
bohemier’s picture

Thanks for the patch. It worked for me. I was able to export nodes and menu items and import them back in another site with different node ids.

hswong3i’s picture

Revoke from #18 + code cleanup with coder + patch via latest 7.x-2.x

JurriaanRoelofs’s picture

great work hswong3i.
I still have the prolbem of UUID Redirector showing on pages as a breadcrumb component. This is in nodes where the menu tree is used to generate breadcrumbs.
Any way to fix that?

nvahalik’s picture

Shouldn't this be a part of the UUID features module? It seems odd to include it here.

nvahalik’s picture

Status: Needs review » Needs work

Don't include non-relevant code formats in your patch. It adds bulk to the patch and makes it harder to review.

nvahalik’s picture

Also, my suggestion is to re-roll this patch into UUID Features. There is no other UUID-related code in this module and I doubt they will want to add it since there is already a module that handles that functionality anyway.

imre.horjan’s picture

Hi nvahalik and others,
I'm not up-to-date with the status of this patch. We are still using the #5 patch in production without problems.
Yes it should be part of UUID features instead of features module, but it won't be an easy job (see my comment #8 above).
Feel free to refactor into that module if you have time for that.
The refactor may also solve some unexpected results.

shakarins’s picture

Thank you everybody, this patch has been very useful for me, but now I have the same problem than #22.
JurriaanRoelofs, have you found any solution for the breadcrumb issue?

hswong3i’s picture

FileSize
16.42 KB

Just simply reroll #21 via latest 7.x-2.x changes.

(Well, sorry that I will not put else improvement effort for D7, just some simple maintenance duty)

joseph.olstad’s picture

I pushed a commit today that conflicts with patch 28.

Here's the reroll.

patch 28 is good for the release features 7.x-2.11

patch 29 works for the latest dev branch 7.x-dev

joseph.olstad’s picture

fixing regression in patch 29,
here's patch 30

I pushed a commit to the 7.x-2.x branch today that conflicts with patch 28.

Here's the reroll.

patch 28 is good for the release features 7.x-2.11

patch 30 works for the latest dev branch 7.x-dev

joseph.olstad’s picture

Status: Needs work » Fixed

fixed in 7.x-2.x dev

joseph.olstad’s picture

For any related regressions such as the breadcrumb issue, please open a new issue and put a link to it here.

It is likely that some of these issues noted above have been fixed by other issues.

In any case, open a new issue and link it here as mentioned.

hswong3i’s picture

@joseph.olstad thank you very much ~~~

P.S. I just guess this issue may forever as a patch living inside my composer.json since #13 ;-P

Status: Fixed » Closed (fixed)

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

ciss’s picture

    @joseph.olstad The committed patch introduced some nasty code duplication into the code base (4x functionally equivalent code) and should be refactored into a helper function. Should I attach a follow-up patch to this issue or create a new one?

    Duplicate code:

  1. +++ b/includes/features.menu.inc
    @@ -210,7 +229,68 @@ function menu_links_features_export($data, &$export, $module_name = '') {
    +        $uri = explode('/', $link['link_path']);
    +        if (count($uri) == 3 && $uri[0] == 'uuid') {
    +          $entity_data = uuid_uri_array_to_data($uri);
    +          $entities = entity_uuid_load($entity_data['entity_type'], array($entity_data['uuid']));
    +          if (!empty($entities)) {
    +            $entity_type = $entity_data['entity_type'];
    +            $entity = reset($entities);
    +            $internal_uri = entity_uri($entity_data['entity_type'], $entity);
    +            $link['link_path'] = $internal_uri['path'];
    +          }
    +        }
    
  2. +++ b/includes/features.menu.inc
    @@ -237,20 +327,34 @@ function menu_links_features_export_render($module, $data, $export = NULL) {
    +            $uri = explode('/', $temp['link_path']);
    +            if ($uri[0] == 'uuid' && count($uri) == 3) {
    +              $entity_data = uuid_uri_array_to_data($uri);
    +              $entities = entity_uuid_load($entity_data['entity_type'], array($entity_data['uuid']));
    +              if (!empty($entities)) {
    +                $entity = reset($entities);
    +                $internal_uri = entity_uri($entity_data['entity_type'], $entity);
    +                $temp['link_path'] = $internal_uri['path'];
    +              }
    +            }
    
  3. +++ b/includes/features.menu.inc
    @@ -328,6 +432,23 @@ function menu_links_features_rebuild_ordered($menu_links, $reset = FALSE) {
    +      $internal_path = '';
    +      $uri = explode('/', $link['link_path']);
    +      if (module_exists('uuid') && $uri[0] == 'uuid' && count($uri) == 3) {
    +        $entity_data = uuid_uri_array_to_data($uri);
    +        $entities = entity_uuid_load($entity_data['entity_type'], array($entity_data['uuid']));
    +        if (!empty($entities)) {
    +          $entity = reset($entities);
    +          $internal_uri = entity_uri($entity_data['entity_type'], $entity);
    +          $internal_path = $internal_uri['path'];
    +        }
    +      }
    
  4. +++ b/includes/features.menu.inc
    @@ -359,29 +481,61 @@ function features_menu_link_load($identifier) {
    +  $internal_path = '';
    +  $uri = explode('/', $link_path);
    +  if (module_exists('uuid') && $uri[0] == 'uuid' && count($uri) == 3) {
    +    $entity_data = uuid_uri_array_to_data($uri);
    +    $entities = entity_uuid_load($entity_data['entity_type'], array($entity_data['uuid']));
    +    if (!empty($entities)) {
    +      $entity = reset($entities);
    +      $internal_uri = entity_uri($entity_data['entity_type'], $entity);
    +      $internal_path = $internal_uri['path'];
    +    }
    +  }
    
donquixote’s picture

@ciss (#36)
Thanks for pointing this out!
I suggest to open a new issue and then link between them.

joseph.olstad’s picture

@ciss, please post the patch here or to a new issue and please add a link to that issue here so that I am notified.

ciss’s picture

@donquixote @joseph.olstad Created #3085880: Revisit UUID handling for menu links as follow-up.

donquixote’s picture

donquixote’s picture

Issue summary: View changes