Download & Extend

Features Integration (machine names, import and export via ctools)

Project:Custom breadcrumbs
Version:7.x-2.x-dev
Component:Code
Category:task
Priority:normal
Assigned:Unassigned
Status:needs review
Issue tags:ctools exportables features

Issue Summary

I am currently developing custom breadcrumbs integration with module features so that custom breadcrumbs can easily be exported and reused among features and drupal instances.

Is anyone interested in the public release of the code or integrate it directly in module core?

Thanks

Hernani

Comments

#1

I am interested in learning more about this. What's required to do this? Can you provide some details?

#2

Hi MGN,

Basically features allows you to export your module definitions to code, so that they can be imported in other drupal installations, compared, synchronized or updated.

Basically what is needed to achieve this is to change the way how custom breadcrumbs access data, so that instead of checking only in the database table it could also check in modules hook.

I think that custom breadcrumbs could achieve this if we stop to use the bid identifier in custom breadcrumbs table, and try to find other primary key for custom breadcrumbs that can be a string no auto-incremented. A key like node _ language, or views_path seems good candidates to this.

Right now i can not do this without this change.

I can provide some of the code developed, so we can achieve this feature and allow that custom_breadcrumbs can be exported along with spaces, contexts, pages, views, etc..

#3

+1 for Features integration !

#4

Subscribing.

#5

yes please!

#6

+1 - An absolute must for anyone using breadcrumbs and features

#7

+1

#8

@hernani have you been able to make this feature work ?

#9

I was unable to finish this task, mainly because features needs that each exportable object have an unique identifier that do not depends on auto increment keys, like custom breadcrumbs is currently using.

If it would be possible to identify custom breadcrumbs with other identifier (like a unique machine name), would be really easy to integrate with features..!

Are module maintainers available to change this behavior?

Hernani

#10

Alternatively, I think it's possible to use exportables to generate the unique keys for you... or something like that. But, clearly changing custom_breadcrumbs would be preferable.

#11

If it would be possible to identify custom breadcrumbs with other identifier (like a unique machine name)

So instead of storing bid in an autoincrement field, if we stored a unique string like

'$_SERVER["SERVER_NAME"]' . '-' . $bid;

then it would integrate with Features? Is there anything else that would need to be done?

Sorry, again, I haven't used Features so it would be helpful for someone to fill in all the necessary details.

#12

Why not use "BREADCRUMB TYPE" and "NAME" as they appear on "admin/build/custom_breadcrumbs/list"
edit: For the name, it would need to be translated to machine name. Breadcrumb names are already machine names.

#13

How adopting cTools' model for exportables? If I'm not mistaken, Features will automatically notice that Custom Breadcrumbs uses this common format and will provide the necessary integration. In another scenario, if Custom Breadcrumbs used variables for storage then Strongarm (2.x branch) would provide the cTools exportable and Features integration on behalf of the module.

#14

I'd rather see Custom Breadcrumbs implement cTools itself that rely on strongarm to export all of it's configurations via variables. Strongarm becomes particularity problematic to use effectively wit large websites with many modules installed due to the sheer number of variables.

IMO variables should be used to store simple settings and these can be exported with Strongarm. Modules that have more detailed configurations (such as custom breadcrumbs) should provide their own way to export via Features, possibly using cTools.

#15

@rickvug, thanks for tagging this issue and others like it. I am learning a lot by reading what others have done, including Stella's blog entry that describes the basic idea. I think I am starting to see the (ctools) light...It opens up some interesting possibilities in addition to the Features integration.

#16

@MGN You're welcome. I don't mind doing a little bit of organization and hand waving from time to time. The prospect of being able to easily push config to code has been a long held dream for many. IMO the pathway forward has never been as clear. Time to rally behind a common API.

#18

After making the following change to the custom_breadcrumb table (adding a unique key combining bid and node type), I was able to build a functional ctools export form. I've also developed a working import form within custom breadcrumbs that takes the code from the export form and adds a new breadcrumb into the database.

There are many possibilities here, but I think the only change you might need to proceed with the features integration is the unique key, so I've attached a patch for the custom breadcrumbs install file. With this, features now recognizes custom breadcrumbs (it shows in the select at admin/build/features/create), though the exportable objects obviously aren't rendered since the feature hooks have yet to be implemented.

It seems the next step would be to implement the key features hooks, but I haven't looked too deeply into that yet. Perhaps someone else who knows these hooks better than I can develop the implementation? Is this done with the features module (i.e. features.custom_breadcrumbs.inc), or within custom breadcrumbs directly?

On another note, does it make sense to add export/import operations (and forms) within custom breadcrumbs for exporting without features? We could even goes as far as providing default custom breadcrumb objects that can be overridden (as with views, etc.). Would this be a signifcant advantage , or is database storage sufficient?

What are your thoughts and suggestions for moving forward?

AttachmentSize
579690_cb_features_integration.patch 1.26 KB

#19

Status:active» needs review

#20

Status:needs review» needs work

From my point of view, using ‘node_type’ (or other identifiers as ‘tid’) and bid fields could be inconvenient when exporting or modifying the feature: you’ll get a bunch of numbers and you’ll have to know to which “object” this numbers refers to – if you have two breadcrumbs settings for a single node type you’ll have to know the bid number of the cb setting you want to export, and it could get worst when the “object” identifier is another number (tids for example).

This could be ‘fixed’ in the administrative interface by implementing some features’ hooks, but this solution would be no good if you’re using drush to build you’re features.

On the other hand, as bid is just an auto incremental field it should be excluded from the exported object and should not be written into the database of the site where the feature is being installed (check the ‘no export’ setting on the Ctool’s advanced help documentation). I think (I’m not completely sure) that if this field is taken out of the exported object but is used as part of it’s identifier, that relation of the object in the database and the one in code would be lost.

I think that a machine-name field should be added to the schema. It could be the 'name' field – set as unique and restricted to machine-readable characters - or another field which generates it’s value by replacing invalid characters of the ‘(friendly) name’ field could be added. This would be the machine-readable unique identifier needed to integrate with features through the CTools’ API.

The second part of the proposal is a bit shaky since I haven't check the code throughfully. I don't know if the proposal I'm about to make might have negative impacts on code, performace, ease of use, extensibility, ease of imlementation, etc. Or if it will mean re-coding the whole module. I apologize if this has been discussed anywhere else, it’s just a start point which might be useful for someone who is more familiar with the code:

I've noticed that cb and each submodule declares the same db schema except for a single field whcih holds the id or information of the "object" that triggers the custom breadcrumb: node_type, view_path, panel_id, etc. How about merging all schemas into a single table by removing the field which holds the id and adding two new fields: type and id? type would hold the name of the "object" to which the custom breadcrumb should be applied (“node_type”, “view_path”, “panel_id”, etc) and id would hold the identifier or the relevant data needed to determine when to trigger the custom breadcrumb (the name of the node type, the path of the view, the id of the panel, etc). This way features integration could be provided from a single place without having to re-declare the CTool's schema specifics on each submodule and exportable objects would be automatically generated for modules which declare cb settings through the API.

#22

subs

#23

subscribing

#24

I would be very interested in developing integration of custom breadcrumbs with features. Can I help somehow?

#25

subscribe

#26

subscribe.

#27

Any update on this?

#28

At the time i was not able to finish this task, and I ended up not using it on the feature i was developing.

I see that are still interested people on this capability, i will try to pay some attention to MGM's changes posted in #18 and understand if it is now possible to implement it.

#29

Assigned to:Anonymous» iStryker
Status:needs work» active
Issue tags:-ctools exportables+ctools exportables features

I'll take this over

#30

Update: I have integrated Ctools export with Custom Breadcrumbs and it works, however it only works for node_type, and none of the other submodules. I'm having troubles as the user interface is a little different, and each module has a separate table. I am trying to create a user interface that will be able to do everything. I am currently having trouble with FormAPI and AJAX. I posted an issue on Ctools. http://drupal.org/node/958572. Any help would be appreciated. If not, then I'll keep struggling

#31

I would like to give support on developing 'exportables' for this module. I have found another approach using features hooks http://treehouseagency.com/blog/thomas-wysocki/2010/10/28/making-your-mo...

@iStryker: Is there any repo where I can see development of this feature and get involved?

#32

subscribe

#33

Interested in this as well since the crumbs already have a "name" and since paths are likely to be the same across sites.

#34

Subscribing. Thanks for your work.

#35

It would be awesome *feature*!

#36

Meanwhile, here is what I do: in the install file of the feature (create one if one does not already exist), add the following or integrate into the existing install hook implementation:

<?php
function MYFEATURENAME_install() { /* change MYFEATURENAME for your actual feature name */
 
drupal_install_modules(array('custom_breadcrumbs'));
  if (
function_exists('_custom_breadcrumbs_save_breadcrumb')) {
   
$obj->paths = 'projects'; /* projects is an example here, put whatever you want */
   
$obj->titles = 'Projects';
   
$obj->node_type = 'project';
   
$obj->name = 'Custom breadcrumb for projects';
   
_custom_breadcrumbs_save_breadcrumb('custom_breadcrumbs', 'node', $obj);
  }
}
?>

If your feature is already installed and you are adding this functionality, you will have to add an update hook implementation and then run a database update on your target site, because the install function will never be called (of course, we're not really touching the database here. Rather, we're hijacking hook_update_N(), which is meant for database updates, and using it for something else):
<?php
function MYFEATURENAME_update_6000() {
 
drupal_install_modules(array('custom_breadcrumbs'));
  if (
function_exists('_custom_breadcrumbs_save_breadcrumb')) {
   
$obj->paths = 'projects';
   
$obj->titles = 'Projects';
   
$obj->node_type = 'project';
   
$obj->name = 'Custom breadcrumb for projects';
   
_custom_breadcrumbs_save_breadcrumb('custom_breadcrumbs', 'node', $obj);
  }
  return array();
}
?>

This is not ideal, but it works for me in some situations. Cheers,

Albert.

#37

A suggestion around machine names - what about simply using the content type and enforcing that there can only be once custom breadcrumb rule per content type? At the moment (using D7-1.x) I can create multiple rules per content type, which is a bit pointless seeing as how I'd only want the one. Most features are built around a content type so this mapping should be natural. If this isn't workable then the best thing to do would be to change bid to machine_name, with the upgrade path creating machine_name from bid+node_type. Drupal 7 FAPI supports machine name as a special field so the fancy auto generation from the title comes for free.

#38

Version:6.x-2.x-dev» 7.x-1.x-dev

I see that new features are not being added to 7.x-1.x, but here's a patch to add Features to 7.x-1.x incase somebody wants it.

AttachmentSize
579690_7-1_custom_breadcrumbs_features_export.patch 16.08 KB

#39

Actually use this patch not my previous one.

AttachmentSize
579690_7-1_custom_breadcrumbs_features_export-1.patch 16.08 KB

#40

Title:Features Integration» Exportability (machine names and Features Integration
Status:active» needs review

I haven't had the time to do a full review of the changes in #39. One area that still needs work and discussion is the upgrade path. A few issues:

  • The function custom_breadcrumbs_update_6102() is named incorrectly. Updates for version 1.x for Drupal 7 should be custom_breadcrumbs_update_71XX().
  • If all usage of $bid is to be removed then the bid column should go as well.
  • Is moving the values of bid into name the best upgrade path? It isn't portable. Other options would be article, article+bid or a random hash.

Overall I really like the direction of the patch. Providing machine names and using ctools for exportability is certainly the way to go. Some feedback from the Custom Breadcrumbs maintainer would be valuable at this point.

#41

Title:Exportability (machine names and Features Integration» Features Integration (machine names, import and export via ctools)

#42

The _custom_breadcrumbs_load_for_type function should load conditions, not names.

AttachmentSize
custom_breadcrumbs_features_export-579690-42.patch 16.07 KB

#43

Version:7.x-1.x-dev» 6.x-2.0-rc1
Assigned to:iStryker» Anonymous

I needed features integration for a project. The project is still on drupal 6, so I created a patch for Custom Breadcrumbs and all of its sub-modules on 6.x-2.0-rc1. I had to make some changes to the database schemas, so be sure to run update.php after patching. To use it you need to have the features module installed. It uses the standard features hooks.

Copy the patch to the custom_breadcrumbs directory and run the following command:
patch -c -p 1 < custom_breadcrumbs_features_integration_6_x_2_0_rc1-579690-43.patch

Now run the database update.php script.
Either from your browser (you need to be logged in as admin).

or from the command line using drush from your drupal root:
drush updb

If you have any custom breadcrumbs defined, navigate to Site building >> Features on your website and select Create feature.
On the form that appears in the Edit component select list a number of Custom Breadcrumbs components will show up depending on the type of the custom breadcrumbs you have defined on your system.

AttachmentSize
custom_breadcrumbs_features_integration_6_x_2_0_rc1-579690-43.patch 70.82 KB

#44

subscribing

#45

Subscribing.

#46

Patch almost applies to dev. All except taxonomy:

patching file custom_breadcrumbs_taxonomy/custom_breadcrumbs_taxonomy.module
Hunk #1 succeeded at 44 (offset -4 lines).
Hunk #2 succeeded at 52 (offset -4 lines).
Hunk #3 succeeded at 103 (offset -4 lines).
Hunk #4 FAILED at 558.
1 out of 4 hunks FAILED -- saving rejects to file custom_breadcrumbs_taxonomy/custom_breadcrumbs_taxonomy.module.rej

#47

Subscribing. For d7 also if possible.

#48

Thanks for the feedback jason.fisher!

Hope you did not miss that the patch is for 6.x-2.0-rc1.
Let me find some time to post a new patch for dev one of these days.

#49

Version:6.x-2.0-rc1» 6.x-2.x-dev

Here's the same patch on dev.

Use:
patch -c -p 1 < custom_breadcrumbs_features_integration_6_x_2_0_dev-579690-49.patch

Remember it will works on the current (29 November 2011) dev release.
Any changes made to dev might invalidate it.

AttachmentSize
custom_breadcrumbs_features_integration_6_x_2_0_dev-579690-49.patch 75.64 KB

#50

Does anyone have a version of this patch for D7?

#51

Hey @goldlilys, you can use the Follow button in the top-right now instead of typing a subscribe comment. Enjoy :)

#52

Hi,
I have encountered a little problem with the patch for 6.x-2.0-rc1.

The problem is in here

<?php
function custom_breadcrumbs_panels_config_features_export_options() {
 
$options = array();

 
$query = " SELECT machine_name, node_type FROM {custom_breadcrumbs_panels} ";
 
$params = array();
 
$result = db_query($query, $params);
  while (
$row = db_fetch_array($result)) {
   
$options[$row['machine_name']] = 'Panel ID: '. $row['panel_id'];
  }
  return
$options;
}
?>

The query for the panels should be:
<?php
  $query
= " SELECT machine_name, panel_id FROM {custom_breadcrumbs_panels} ";
?>

Thank you,
Tarch.

#53

Hi,
attached you find the patch with the correction of the bug I reported plus the replacement of a couple of dashes that should be underscores.

<?php
  $saved
= _custom_breadcrumbs-panels_config_set_data($item);
?>

and

<?php
      $code
[] = '  $custom_breadcrumbs-panels_configs[] = '. features_var_export($item, '  ') .';';
?>

in both cases the dash after 'breadcrumbs' is meant as a subtraction for PHP.

Tarch

AttachmentSize
custom_breadcrumbs_features_integration_6_x_2_0_rc1-579690-43.patch 70.82 KB

#54

Version:6.x-2.x-dev» 7.x-2.x-dev

Hi Snugug,

I created a first go at a patch for the 7.x-2.x development branch.
Let's all hope it makes it into the next release.

To apply the patch, follow the instructions on http://drupal.org/node/1054616

Hope you can give it some testing. Do not forget to run update.php.

This upgrade is sponsored by Unicef Uganda for the Devtrac project.

AttachmentSize
custom_breadcrumbs_features_integration_7_x_2_x_dev-579690-50.patch 73.95 KB
nobody click here