Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chachasikes’s picture

this 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.

Anonymous’s picture

@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.

Anonymous’s picture

Status: Needs work » Needs review
FileSize
6.9 KB

this patch applies to head.

catch’s picture

It looks a bit odd to me doing this in taxonomy_get_vocabularies() - why not a hook_modules_installed() or hook_modules_enabled()?

Anonymous’s picture

I 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... :'(

Status: Needs review » Needs work

The last submitted patch failed testing.

catch’s picture

Version: 7.x-dev » 8.x-dev

Drupal 8, sadly.

Anonymous’s picture

We 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.

sun’s picture

Version: 8.x-dev » 7.x-dev
Category: feature » task

It'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.

Dries’s picture

Let's see if we can fix #347959: modules_installed is broken during testing quickly, so we can get this one in before January 15th.

Anonymous’s picture

Hot damn! That's pretty good news!

AaronBauman’s picture

Status: Needs work » Postponed
FileSize
6.27 KB

Postponing, 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.

AaronBauman’s picture

Status: Postponed » Needs review
FileSize
6.17 KB

Unfortunately 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:

  • 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
  • during forum_enable(), call forum_taxonomy_vocabulary_info() directly and save the vocabulary with taxonomy_vocabulary_save().

*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.

sun’s picture

Move 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.

Status: Needs review » Needs work

The last submitted patch, 569326-hook_taxonomy_vocabulary_info_0.patch, failed testing.

AaronBauman’s picture

Status: Needs work » Needs review
FileSize
9.47 KB

Brilliant, sun. That is why you make the big bucks.

Status: Needs review » Needs work

The last submitted patch, 569326-hook_taxonomy_vocabulary_info_1.patch, failed testing.

AaronBauman’s picture

Status: Needs work » Needs review
FileSize
9.63 KB

one more instance of field_name needed to be updated.

Status: Needs review » Needs work

The last submitted patch, 569326-hook_taxonomy_vocabulary_info_2.patch, failed testing.

AaronBauman’s picture

Status: Needs work » Needs review
FileSize
9.61 KB

wrong name for field_name

Status: Needs review » Needs work

The last submitted patch, 569326-hook_taxonomy_vocabulary_info_3.patch, failed testing.

AaronBauman’s picture

Status: Needs work » Needs review
FileSize
10.02 KB

... and another.

Anonymous’s picture

+++ modules/taxonomy/taxonomy.api.php	25 Jun 2010 19:44:59 -0000
@@ -86,6 +86,48 @@ function hook_taxonomy_vocabulary_delete
+ * @return
+ *   An associative array of information defining the vocabularies. The array
+ *   is indexed by a machine-readable name as the key. The values are several
+ *   attributes. Possible attributes:
+ *   - "name": the human-readable name of the vocabulary. Required.
+ *   - "description": a brief description of the vocabulary. Required.
+ *   - "hierarchy": hierarchy. Not required.
+ *   - "relations": Not required.
+ *   - "module": the name of your module. Required.
+ *   - "weight": the weight of the vocabulay. Not required.
+ * ¶

+++ modules/taxonomy/taxonomy.module	25 Jun 2010 19:44:59 -0000
@@ -673,6 +678,25 @@ function taxonomy_terms_static_reset() {
+  foreach ($info_array as $machine_name => $info) {
+    if (!isset($vocabulary_names[$machine_name])) {
+      $vocabulary = (object) $info;
+      $vocabulary->machine_name = $machine_name;
+      $status = taxonomy_vocabulary_save($vocabulary);
+    }
+  }

Should 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!

hefox’s picture

Installed 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):

taxonomy.admin.inc forum (appear to use it cept for saving)
$form['module'] = array('#type' => 'value', '#value' => $vocabulary->module);
taxonomy.module vocabulary save
  if (!isset($vocabulary->module)) {
    $vocabulary->module = 'taxonomy';
  }
taxonomy.install's scehma
      'module' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The module which created the vocabulary.',
      ),

(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).

Anonymous’s picture

FYI @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.

AaronBauman’s picture

Rerolled patch:

  • changes 'module' attribute of hook from required to optional. Iterating over module_implements() is not much different than iterating over the result of module_invoke_all(), so this seemed like a decent compromise.
  • defines a constant for forum's vocabulary machine name, FORUM_VOCAB_MACHINE_NAME.
  • removes vid variable forum_nav_vocabulary - there's no reason for it since we can more reliably use taxonomy_vocabulary_machine_name_load(FORUM_VOCAB_MACHINE_NAME).
  • fixes some trailing whitespace.
  • updates forum tests.

Status: Needs review » Needs work

The last submitted patch, 569326-hook_taxonomy_vocabulary_info_5.patch, failed testing.

sun’s picture

um, 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.

+++ modules/forum/forum.module	28 Jun 2010 15:35:17 -0000
@@ -229,7 +317,9 @@ function forum_init() {
+  $forum_vocabulary =
+    taxonomy_vocabulary_machine_name_load(FORUM_VOCAB_MACHINE_NAME);

+++ modules/forum/forum.test	28 Jun 2010 15:35:17 -0000
@@ -100,8 +100,9 @@ class ForumTestCase extends DrupalWebTes
+    $vocabulary =
+      taxonomy_vocabulary_machine_name_load(FORUM_VOCAB_MACHINE_NAME);

@@ -181,8 +182,8 @@ class ForumTestCase extends DrupalWebTes
-    $original_settings = taxonomy_vocabulary_load($vid);
+    $original_settings =
+      taxonomy_vocabulary_machine_name_load(FORUM_VOCAB_MACHINE_NAME);

@@ -201,7 +202,8 @@ class ForumTestCase extends DrupalWebTes
-    $current_settings = taxonomy_vocabulary_load($vid);
+    $current_settings =
+      taxonomy_vocabulary_machine_name_load(FORUM_VOCAB_MACHINE_NAME);

@@ -210,7 +212,8 @@ class ForumTestCase extends DrupalWebTes
+    $current_settings =
+      taxonomy_vocabulary_machine_name_load(FORUM_VOCAB_MACHINE_NAME);

@@ -244,7 +247,9 @@ class ForumTestCase extends DrupalWebTes
+    $vocabulary =
+      taxonomy_vocabulary_machine_name_load(FORUM_VOCAB_MACHINE_NAME);

Strange wrapping here. Only comments should wrap at 80 chars.

+++ modules/taxonomy/taxonomy.api.php	28 Jun 2010 15:35:17 -0000
@@ -86,6 +86,48 @@ function hook_taxonomy_vocabulary_delete
+ * @return
+ *   An associative array of information defining the vocabularies. The array
...
+ *   - "name": the human-readable name of the vocabulary. Required.

No quotes for array keys, just the key, followed by a colon. http://drupal.org/node/1354

+++ modules/taxonomy/taxonomy.api.php	28 Jun 2010 15:35:17 -0000
@@ -86,6 +86,48 @@ function hook_taxonomy_vocabulary_delete
+ *
+ */
+function hook_taxonomy_vocabulary_info(){

Stale trailing blank docblock line.

+++ modules/taxonomy/taxonomy.module	28 Jun 2010 15:35:17 -0000
@@ -673,6 +678,31 @@ function taxonomy_terms_static_reset() {
+function taxonomy_modules_installed($modules) {

Missing function docblock.

+++ modules/taxonomy/taxonomy.module	28 Jun 2010 15:35:17 -0000
@@ -673,6 +678,31 @@ function taxonomy_terms_static_reset() {
+  $defaults = array('hierarchy' => 0, 'relations' => 0, 'module' => FALSE, 'weight' => 0);
...
+    foreach ($info as $machine_name => $vocab_info) {
+      $vocab_info = array_merge($defaults, $vocab_info);

Usually, we do

$vocab_info += array(...);

to merge in any defaults.

Powered by Dreditor.

AaronBauman’s picture

OK, thanks for the feedback sun.

I have rerolled with the suggested changes and a couple others:

  • Since the variable forum_nav_vocabulary is going away, implemented forum_update_7002() to update forum vocabulary's machine_name when upgrading from D6.
  • Updated documentation for forum_modules_enabled to explain why it lives in forum.install
  • Removed some trailing whitespace.
AaronBauman’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 569326-hook_taxonomy_vocabulary_info_6.patch, failed testing.

AaronBauman’s picture

Status: Needs work » Needs review
FileSize
18.8 KB

forum_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().

Status: Needs review » Needs work

The last submitted patch, 569326-hook_taxonomy_vocabulary_info_7.patch, failed testing.

AaronBauman’s picture

Status: Needs work » Needs review
FileSize
21.92 KB

replaced a few straggling variable_get('forum_nav_vocabulary', '')'s in forum.admin.inc

retester2010’s picture

Status: Needs review » Needs work

The last submitted patch, 569326-hook_taxonomy_vocabulary_info_8.patch, failed testing.

catch’s picture

Version: 7.x-dev » 8.x-dev

Almost a year later, moving to D8 again, should try to get it in early there.

jibran’s picture

Issue summary: View changes

I don't think it is valid anymore see taxonomy.vocabulary.forums.yml.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

joachim’s picture

Status: Needs work » Closed (outdated)

> I don't think it is valid anymore see taxonomy.vocabulary.forums.yml.

Agreed.