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.
Allow modules to define vocabularies without calling Taxonomy module functions directly.
Comments
Comment #1
chachasikes CreditAttribution: chachasikes commentedthis patch should be built off this patch for taxonomy
http://drupal.org/node/412518#comment-1996762
was trying to implement hook in forum.module
function forum_taxonomy_vocabulary_info(){
$info = array(
'forums' => array(
'name' => t('Forums'),
'machine_name' => 'forums',
'description' => t('Forum navigation vocabulary'),
'hierarchy' => 1,
'relations' => 0,
'module' => 'forum',
'weight' => -10,
),
);
return $info;
}
forum_enable can mostly be removed, but there is a variable that is set in database, which is sort of funky -- and this effects the uninstall script & tests.
Comment #2
Anonymous (not verified) CreditAttribution: Anonymous commented@chachasikes: thanks for this. I'm going to separate this patch from the #412518: Convert taxonomy_node_* related code to use field API + upgrade path so it can be reviewed on its own. Please check back on the issue before working on it again.
Comment #3
Anonymous (not verified) CreditAttribution: Anonymous commentedthis patch applies to head.
Comment #4
catchIt looks a bit odd to me doing this in taxonomy_get_vocabularies() - why not a hook_modules_installed() or hook_modules_enabled()?
Comment #5
Anonymous (not verified) CreditAttribution: Anonymous commentedI cannot use hook_modules_enabled because forum_enabled is called before that module is invoked. It has to be in hook_modules_installed. Unfortunately, simpletest refuses to execute these hooks. This test will have massive fails for this reason despite the fact that enabling the forum module by hand works beautifully. This is the saddest panda of all, at least for my code freeze eve... :'(
Comment #7
catchDrupal 8, sadly.
Comment #8
Anonymous (not verified) CreditAttribution: Anonymous commentedWe need to create follow up issues for the testing bot. We can't go into Drupal 8 with a test bot that deliberately bypasses core hooks.
Comment #9
sunIt's totally insane that this wonderful patch is moved to D8, just because #347959: modules_installed is broken during testing, resp. the initial Field API patch, totally broke SimpleTest.
That last patch looks just nice + correct and was ready months ago.
Comment #10
Dries CreditAttribution: Dries commentedLet's see if we can fix #347959: modules_installed is broken during testing quickly, so we can get this one in before January 15th.
Comment #11
Anonymous (not verified) CreditAttribution: Anonymous commentedHot damn! That's pretty good news!
Comment #12
AaronBaumanPostponing, pending #836748: Improve documentation about install/enable/etc. hook invocation order
If 836748 does not get in, this will have to be done with an ugly workaround.
Otherwise, this is a reroll of #5 with a fix to field_name in forum_enable that was causing forum.install to always try to create a field regardless of whether it already existed.
Comment #13
AaronBaumanUnfortunately it looks like forum.module is not the best example for hook_taxonomy_vocabulary_info. hook_taxonomy_vocabulary_info() is a great idea and a good* implementation, but it seems like it's not going to work for any module that needs the vocabularies during install / enable.
In the case of forum.module, the problem boils down to a circular dependency: forum_enable() expects to find a vocabulary exposed by forum_taxonomy_vocabulary_info(), but the vocabulary isn't registered in the system until taxonomy_modules_installed() is run. taxonomy_modules_installed() won't find the vocabulary unless forum_enable() has already been run.
Short of major changes to the install/enable process, there's simply no way that the vocabulary defined in forum_taxonomy_vocabulary_info() will be available during forum_enable().
So, the attached patch is another reroll of #5 with the change:
*An ideal solution for hook_taxonomy_vocabulary_info would be to treat vocabularies defined in implementations of the hook as first-class citizens, a la ctools exportables. In other words, eliminate the requirement that vocabularies be stored in the database. Abstract this idea up to entities, and we're talking about some major rethinking of some Drupal fundamentals.
Comment #14
sunMove the code from forum_enable() into forum_modules_installed() or forum_modules_enabled(), check whether 'forum' is in the installed/enabled modules, and if it is, you can rely on the vocabulary being installed.
Comment #16
AaronBaumanBrilliant, sun. That is why you make the big bucks.
Comment #18
AaronBaumanone more instance of field_name needed to be updated.
Comment #20
AaronBaumanwrong name for field_name
Comment #22
AaronBauman... and another.
Comment #23
Anonymous (not verified) CreditAttribution: Anonymous commentedShould taxonomy_modules_installed() be written so that the module property on the vocabularies returned from hook_taxonomy_vocabulary_info can be inferred? Can (hypothetical) betterforum module create a vocabulary on behalf of forum module?
Thanks for picking up this issue aaronbauman. Please remember to strip white space from the end of your lines. The code comments have some superfluous space.
46 critical left. Go review some!
Comment #24
hefox CreditAttribution: hefox commentedInstalled forum, vocabulary created, field attached with correct vocabulary, etc.
Re: module; As module isn't doing much anymore as far as I can tell (no hook_term_path, forum is doing enetity alter to change the path I think?), and it involves a bit of messy code to do module_implements, then foreach over each result to add in module, might as well say screw it imo.
As far as I can tell, there's are the only two referencing using module (excluding schema):
(Twitter 'discussion', asked bangpound why no alter hook; can't really change much, and as there's no revert, ie this is just on install, wouldn't be too useful, would need the module to be enabled before the one defining the vocabulary to alter it!)
(Hm, users can delete vocabularies despite what module created it. :O; though in the case of forums can do variable_set('forum_nav_vocabulary', new vid) to recover from that).
Comment #25
Anonymous (not verified) CreditAttribution: Anonymous commentedFYI @hefox: The module property is only used in core by forum, but it's used extensively in contrib. We can't drop it because MODULE_term_path is still in D7 API.
Comment #26
AaronBaumanRerolled patch:
Comment #28
sunum, didn't read the issue, but introducing a constant for a machine readable taxonomy vocabulary name sounds a bit odd to me.
If I'm not mistaken, then the hook_modules_enabled() code can stay in the .install file.
Strange wrapping here. Only comments should wrap at 80 chars.
No quotes for array keys, just the key, followed by a colon. http://drupal.org/node/1354
Stale trailing blank docblock line.
Missing function docblock.
Usually, we do
$vocab_info += array(...);
to merge in any defaults.
Powered by Dreditor.
Comment #29
AaronBaumanOK, thanks for the feedback sun.
I have rerolled with the suggested changes and a couple others:
Comment #30
AaronBaumanComment #32
AaronBaumanforum_form_alter() was calling taxonomy_vocabulary_machine_name_load for all forms, which broke update.php. changed multiple if statements therein to switch-case.
updated documentation for forum_update_7002().
Comment #34
AaronBaumanreplaced a few straggling
variable_get('forum_nav_vocabulary', '')
's in forum.admin.incComment #35
retester2010 CreditAttribution: retester2010 commented#34: 569326-hook_taxonomy_vocabulary_info_8.patch queued for re-testing.
Comment #37
catchAlmost a year later, moving to D8 again, should try to get it in early there.
Comment #38
jibranI don't think it is valid anymore see taxonomy.vocabulary.forums.yml.
Comment #44
joachim CreditAttribution: joachim as a volunteer commented> I don't think it is valid anymore see taxonomy.vocabulary.forums.yml.
Agreed.