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.
The new shortcut modules defines shortcut sets. The sets contains menu links which can be exported, but sets themselves cannot be exported yet. Here's a patch that adds this functionality.
Comment | File | Size | Author |
---|---|---|---|
#46 | 986968-46.patch | 3.66 KB | jwmoore1 |
#38 | 986968-shortcut-sets.patch | 3.71 KB | Dave Reid |
| |||
#37 | 986968-shortcut-sets.patch | 3.74 KB | Dave Reid |
| |||
#36 | export_shorcuts_sets-986968-36.patch | 4.13 KB | chrisgross |
| |||
#31 | interdiff-98696-24-31.patch | 3.19 KB | mkhamash |
Comments
Comment #1
floretan CreditAttribution: floretan commentedUpdated patch with the following changes:
- Convert shortcut sets back to object on rebuild.
- Rename the default hook to hook_shortcut_default_shortcut_set() to avoid conflict with http://api.drupal.org/api/drupal/modules--shortcut--shortcut.api.php/fun....
Comment #2
irakli CreditAttribution: irakli commentedFeatures export of a third-party module should be implemented as part of that module using Features API or (preferably) CTools Exportable API
Comment #3
DamienMcKennaShortcut sets are core Drupal functionality and should be handled out of the box by Features.
Comment #4
Dave ReidComment #5
DamienMcKennaWith some initial testing this seems to be working correctly.
Comment #6
Johnny vd Laar CreditAttribution: Johnny vd Laar commentedThere is one problem. It only works for updating existing shortcuts. It doesn't create new shortcut sets because it always sets the "set_name".
I wouldn't know how to fix this tho.
Comment #7
jmcneil CreditAttribution: jmcneil commentedsubscribe
Comment #8
febbraro CreditAttribution: febbraro commentedComment #9
nmc CreditAttribution: nmc commentedsubscribe
Comment #10
febbraro CreditAttribution: febbraro commentedComment #11
DamienMcKennaThere are two tables involved in the shortcuts system thus two pieces to the export:
The second part works as well as any other exported menu - there are some occasional glitches, but the first part is the custom part of this patch and needs some thorough testing.
Comment #12
DamienMcKennaAm I the only one who wishes this made each link available separately, similar to the menu system?
Comment #13
javi-er CreditAttribution: javi-er commentedI've tested the patch on #1 with a fresh install of the latest release of Drupal and Features and it works well for me.
Comment #14
buddaI exported some shortcuts on the default shortcut-set to a feature and activated the feature on a fresh Drupal 7 install. Nothing appeared. I performed a
drush cc all
and was greeted with errors regarding a clash:Should a REPLACE INTO / UPDATE be done if an INSERT fails?
Comment #15
buddaI renamed the default shortcut set to something custom, exported to a feature and activated the feature on a fresh site install. However the export still uses the machine name of "shortcut-set-1" which causes the same DB errors as above.
Comment #16
scor CreditAttribution: scor commentedreroll of #1 which worked for me.
Comment #17
itaine CreditAttribution: itaine commented@scor could you reroll another one up against rc2?
Comment #18
lee20 CreditAttribution: lee20 commentedAttached is a patch re-rolled against rc2
Comment #19
coredumperror CreditAttribution: coredumperror commentedI tried out this patch, and at first it wouldn't work because the file paths are wrong. They appear to be relative to the drupal base path, instead of the module base path.
Once I got that worked out, though, I found that the export and load functionality works great except for one small but critical problem. It saves all the data in the export, but on import it doesn't create the row in the
shortcut_set
table. It does, however, create themenu_links
rows correctly. Thus, manually adding the appropriate row toshortcut_set
fixes the import.I looked through the code in the patch to see if I could solve the problem, but I'm not familiar enough with the Features API to see what's wrong.
Comment #20
coredumperror CreditAttribution: coredumperror commentedAh ha! Upon further investigation, I discovered the problem. Unfortunately, the fix is not very straightforward due to a quirk in the
shortcut_set_save()
API (as described here #1175700: shortcut_set_save() "set_name" documentation is confusing, and passing in a nonexistent set name creates orphan menu links).On line 87 of
features.shortcut.inc
theshortcut_set_features_rebuild()
function callsshortcut_set_save(&$shortcut_set)
with an object much like this for$shortcut_set
:Unfortunately,
shortcut_set_save()
assumes that if you've provided aset_name
value, you want to do an update to an existing shortcut set, rather than adding a new one (see comment #2 on #1175700: shortcut_set_save() "set_name" documentation is confusing, and passing in a nonexistent set name creates orphan menu links). Since there is not yet any shortcut set named 'shortcut-set-2', it doesn't update anything. And due to another bug #602190: drupal_write_record() unable to determine if changes have been made., it reports that it did the update, even though the DB didn't change.The solution in my patch is probably not optimal, but it works. It calls
shortcut_set_save(&$shortcut_set)
with:Then grabs the auto-generated
set_name
that gets added by reference to$shortcut_set
. It then updates all the rows inmenu_links
which had the exportedset_name
, changing them to the auto-generatedset_name
.Depending on how the exporting user had his site set up, these two versions of
set_name
may very well be the same string; but since we can't be sure of that, this roundabout method seems necessary.Comment #21
nevergone CreditAttribution: nevergone commentedWhat would there be need for in order for the solution of the issue to go on?
Comment #22
mpotter CreditAttribution: mpotter commentedPatch should be re-rolled against the 2.x-beta and also tested for the problems raised in #19. Thus, as it's marked, it "Needs Review".
Comment #23
cedeweyI've rerolled the patch from #20 against features-7.x-2.0-beta and am not seeing the shortcut sets reflected when I export the feature and enable it on another site. Perhaps I'm missing a step though? What component should these be in? Currently I'm including the Block settings for Shortcuts and the management: --Shortcuts Menu Link.
Comment #24
discipolo CreditAttribution: discipolo commentedhere is the rerolled patch against 2.x-dev and it seems to work
Comment #25
carsonblack CreditAttribution: carsonblack commentedApplied patch cleanly and shortcut set and menu items are exported into feature code.
Comment #26
coredumperror CreditAttribution: coredumperror commentedHave you tried importing the saved shortcut sets, though? That was the main problem I had with the system. Drupal 7 implemented the shortcut set system in a way that doesn't lend itself well to importing a shortcut set into a site that already has other shortcut sets.
Comment #27
mpotter CreditAttribution: mpotter commentedWell, if people haven't tested the *importing* of shortcuts, then I need to move this back to "Review" state.
Comment #28
MiroslavBanov CreditAttribution: MiroslavBanov commentedI have tested it, importing does work, but I got bizarre issues when the feature was part of the install profile, and I installed different language, and I had translation string in the ".po" file for the string "Default". After profile installation, the feature was "Overridden", and I needed to revert it again. I want to be able to install my profile with a choice language if possible.
Comment #29
matthewmessmer CreditAttribution: matthewmessmer commented#24 works for me on the latest 2.x-dev branch with a few issues.
It failed to properly import shortcuts saved to the "Default" set, but it worked for any others sets I created.
A standard features reset works as expected and added new shortcuts to the original shortcut set, but if I did a feature reset with --force, a new shortcut set with the same name would be created and the original one would remain untouched.
Comment #30
hefox CreditAttribution: hefox commentedNeeds work based on 29
Comment #31
mkhamash CreditAttribution: mkhamash commentedI have edited patch number #24 to work as expected with the Drupal core patch for shortcut_set_save() issue #1175700-19: shortcut_set_save() "set_name" documentation is confusing, and passing in a nonexistent set name creates orphan menu links, I think we should go with this path instead of workarounds since the core issue is committed to Drupal 8 and only needs to be back-ported to D7.
Comment #32
hefox CreditAttribution: hefox commentedComment #33
chrisgross CreditAttribution: chrisgross commented#31 worked for me, but ONLY for the default shortcut set. Any additional shortcut sets would not import. That being said, the default set will only add shortcuts, but does not remove the few default shortcuts provided by core.
Comment #34
chrisgross CreditAttribution: chrisgross commentedStill needs work, but here's #31 re-rolled against 2.7
Comment #35
chrisgross CreditAttribution: chrisgross commentedComment #36
chrisgross CreditAttribution: chrisgross commentedWhoops fixed missing 'contact' module export that must have been added to features recently.
Comment #37
Dave ReidRevised patch that must be used in combination with #1175700: shortcut_set_save() "set_name" documentation is confusing, and passing in a nonexistent set name creates orphan menu links and removes the unnecessary db_update('menu_links') since it was a no-op (updating field to the same value).
Comment #38
Dave ReidI don't think we even need menu_cache_clear_all() anymore either.
Comment #39
froboyI tested #38 and it works for the Default set but not others. As described in #33 the second set exports, but doesn't import correctly.To the second part of #33, however, seems to be related to a long-term issue where Features can't remove menu items. I'd recommend that not be considered as a requirement here, but that the minimum viable patch be able to export and successfully import any number of shortcut sets.
EDIT: Inspecting the target db shows only "shortcut-set-1" in the "shortcut_set" table. If I manually add an entry for "shortcut-set-2" everything shows up, so it looks like registering the set is the only missing piece here.EDIT again: After an hour of being stupid, I read #37
Comment #40
froboyWith the patch in #37, this looks ready to go.
Comment #43
mpotter CreditAttribution: mpotter at Phase2 commentedWe can't mark this RTBC if it depends on a core Drupal patch that isn't committed yet. Thus, marking this as Postponed until the Drupal core issue mentioned in #37 is applied. Once that is done, somebody can test again and mark this RTBC at that time.
Comment #44
scotwith1tComment #45
joegraduatePatch #38 no longer cleanly applies to 7.x-2.x.
Comment #46
jwmoore1 CreditAttribution: jwmoore1 commentedRerolled patch #38 and resolved conflicts, which were just related to the comments in the features.module file changing.