Here's a quicky. Let's say you've created some exportable content (using CTools) which references a term ID and you have to go from your dev site to the production site. And your taxonomy is also being exported using UUID.
Somehow you have to tie them together because sure as eggs is eggs the term IDs created on the production site are not going to be the same as the local ones. That's why you used UUID in the first place. Right?
Here's what you do: in your local exportable you will have a column for the term ID so include a column for the term UUID as well.
In your add/edit form for the exportable you'll have to include some code to automatically add the selected term's UUID - I did it in the form validation. Basically you read the selected term ID, load the selected term which will have the UUID in it (because it's added to the base table). Set the term UUID value in $form_state['values']. Assuming you're using CTools Export UI the UUID will be saved automatically.
Also, in the module install, add "no export" => TRUE to the TID field, so that Export UI does not include it in the feature. (This code works for Features, it doesn't work for single imports, I'll leave that as an exercise for the reader - hint: you can specify an "import callback".)
That's the easy bit, when you export your content it will be saved with the term's UUID and not the term's ID. The difficult bit is how to link the UUID of exported content when Features loads it into the new site.
Except it's not hard at all. In your export specification, in the schema, you have the "default hook", well CTools Export UI very kindly calls an drupal_alter() on the default items after it's loaded them. So we can do this:
/**
* Implements hook_DEFAULT_HOOK_alter().
*
* This intercepts any defaults picked up from code and converts
* their UUID category into the local TID (which might be different
* on every site).
*
*/
function mymodule_my_default_hook_alter(&$items) {
$uuids = db_select('taxonomy_term_data', 't')
->fields('t', array('uuid', 'tid'))
->execute()->fetchAllKeyed();
foreach ($items as $item) {
if (empty($item->tid) && !empty($uuids[$item->uuid])) {
$item->tid= $uuids[$item->uuid];
}
}
}
The database call creates an array which maps all UUIDs to TIDs in one go. If your site uses a lot of taxonomy terms - perhaps you have user tagging - you might want to restrict this call to a specific vocabulary.
The exact item property names will depend on what you set up in your schema.
Sorted.
Showing posts with label ctools. Show all posts
Showing posts with label ctools. Show all posts
Thursday, 11 July 2013
Tuesday, 29 May 2012
Then three come all at once
I have been doing some work on the field_extract module, a few minor fix-ups most of which wouldn't be noticed and added support for the entityreference field. You can find this module here: http://drupal.org/project/field_extract
Someone I worked with recently has put out my "deeplink" module which allows otherwise hidden content to be made available on a specific trackable URL. My version was Drupal 6 (that's what I was working on at the time) he's doing the D7 upgrade, you can find it http://drupal.org/project/deeplink
But deeplink needs my Controls module, and that's a baby that needs explanation. And that explanation is available on the project page http://drupal.org/project/controls there's both a D6 and D7 version both written by lil ole me.
Briefly: Controls is an API module which provides a similar function to CTools plugins (they have a lot in common), but requires virtually no setting up and is much easier to use. Now I always say that to people but I did seriously wonder whether it was true, so for the last commercial project I worked on I didn't use Controls, I went back to using CTools plugins instead. I desperately wished I hadn't.
So I'll stick by my statement - I think Controls is easier to use and in some ways more versatile than CTools plugins.
However they are also more easily abused. It's something for developers working on an end-client's website. Anyway I'll let you be the judge.
Someone I worked with recently has put out my "deeplink" module which allows otherwise hidden content to be made available on a specific trackable URL. My version was Drupal 6 (that's what I was working on at the time) he's doing the D7 upgrade, you can find it http://drupal.org/project/deeplink
But deeplink needs my Controls module, and that's a baby that needs explanation. And that explanation is available on the project page http://drupal.org/project/controls there's both a D6 and D7 version both written by lil ole me.
Briefly: Controls is an API module which provides a similar function to CTools plugins (they have a lot in common), but requires virtually no setting up and is much easier to use. Now I always say that to people but I did seriously wonder whether it was true, so for the last commercial project I worked on I didn't use Controls, I went back to using CTools plugins instead. I desperately wished I hadn't.
So I'll stick by my statement - I think Controls is easier to use and in some ways more versatile than CTools plugins.
However they are also more easily abused. It's something for developers working on an end-client's website. Anyway I'll let you be the judge.
Wednesday, 16 November 2011
Ssssh
I've not posted recently because my current job involves Drupal 6 so I've done virtually no D7 work for a while. However I do have a new set of modules for developers coming soon which will be in both D6 and D7 varieties.
Essentially it's a system that does a similar job to CTools plugins but is lightweight and standalone. It's very good for de-coupling dependent custom modules, essentially very simple but very versatile.
There's a core module that provides the API (a very small module indeed) and then some other modules that demonstrate how to use it and provide handy facilities at the same time.
Hopefully I'll have that out by Christmas. I'm also happy to say that my field_extract module is doing very nicely in the module usage charts currently standing at 99 sites.
Essentially it's a system that does a similar job to CTools plugins but is lightweight and standalone. It's very good for de-coupling dependent custom modules, essentially very simple but very versatile.
There's a core module that provides the API (a very small module indeed) and then some other modules that demonstrate how to use it and provide handy facilities at the same time.
Hopefully I'll have that out by Christmas. I'm also happy to say that my field_extract module is doing very nicely in the module usage charts currently standing at 99 sites.
Subscribe to:
Posts (Atom)