Several things in forum_form_alter():

1.

D7 regression - forum vocabulary could be deleted.

At admin/structure/taxonomy/forums/edit it says:
'This is the designated forum vocabulary. Some of the normal vocabulary options have been removed.'
This was true on D6. On D7, the form looks identical to the one for tags.
$form['delete']['#access'] = FALSE; should be $form['actions]['delete']['#access']

this appears to have no effect -- at least, as admin I can delete the forums vocab.

2.

Fieldset element for parents and weight been renamed to $form['relations']

in D6 it was $form['advanced'] see #10566-18: Forum can not appear in multiple containers

3.

Forum's vocabulary always has single hierarchy

comment added and 1 changed to TAXONOMY_HIERARCHY_SINGLE
$form['hierarchy'] = array('#type' => 'value', '#value' => 1);

This appears to come as a value anyway. Is the idea that the forum forces this in case a contrib module opens this up? If so, we need a code comment to explain it.

4. D7 only
if ($form_id == 'forum_node_form') {

Does this form even exist any more? I can't find that string anywhere else in the codebase, so it probably is.

Though this raises a question -- how do we prevent an admin use from removing the Forum vocab field from Forum posts?

Comments

joachim’s picture

Title: Form vocabulary alterations possibly obsolete » Forum vocabulary alterations possibly obsolete -- possible to delete forum vocab

Fixing typo and making title a bit clearer.

andypost’s picture

Seems reasonable and could be easily fixed. But first need UX attention

larowlan’s picture

Status: Active » Closed (duplicate)

There is an existing issue dealing with this. It's a bug in the form alter code, the form is has. changed so the vocabulary options are the same.
Re forum node form, that's from node_forms. The dup issue is #10566: Forum can not appear in multiple containers

andypost’s picture

Version: 7.x-dev » 8.x-dev
Status: Closed (duplicate) » Active

This issues are different. Pointed issue should fix visibility of forum in multiple containers (multi-parented)

But this issue about all forum_form_alter() so let's not mix them.

andypost’s picture

Status: Active » Needs review
StatusFileSize
new1.29 KB

Just a tests

Status: Needs review » Needs work

The last submitted patch, 787652-tests.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new1.61 KB

A bit smarter tests, now we can be sure that fieldset has relations name in form definition

andypost’s picture

Issue tags: +Needs backport to D7
StatusFileSize
new3.52 KB

Introduced hook_form_alter() split into forum_form_taxonomy_form_vocabulary_alter() and forum_form_taxonomy_form_term_alter() for performance reasons.

Not sure this split could be allowed for D7...

andypost’s picture

StatusFileSize
new3.69 KB

Updated issue summary for D8. patch with better comments

andypost’s picture

StatusFileSize
new3.73 KB

Finally added @see to hooks doc block

andypost’s picture

I don't think we should prevent ability to remove forum's field from forum node type

andypost’s picture

Version: 8.x-dev » 7.x-dev
StatusFileSize
new2.73 KB

D7 patch to test

Status: Needs review » Needs work

The last submitted patch, 787652-forum-form_alter.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new2.71 KB

D7 has no TAXONOMY_HIERARCHY_* contants

andypost’s picture

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

Back to 8.x

andypost’s picture

Priority: Normal » Major

This could cause deletion of vocabulary

#10 - patch for D8
#14 - D7

larowlan’s picture

larowlan’s picture

Assigned: Unassigned » larowlan
larowlan’s picture

Status: Needs review » Needs work
+++ b/core/modules/forum/forum.module
@@ -575,24 +575,34 @@ function forum_field_storage_pre_update($entity_type, $entity, &$skip_fields) {
+  if (isset($form['vid']['#value']) && $form['vid']['#value'] == $vid) {

I think we should add a test that verifies this field exists as well, so if it is removed we don't end up with broken logic again.

Powered by Dreditor.

larowlan’s picture

StatusFileSize
new1.61 KB

This one without patch, to verify tests fail.
SHOULD FAIL.

larowlan’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 787652-forum-form_alter-split_FAIL.patch, failed testing.

larowlan’s picture

Status: Needs work » Needs review
StatusFileSize
new4.04 KB

This one adds test for vid field as per 19

Status: Needs review » Needs work

The last submitted patch, 787652-forum-form_alter-split_22.patch, failed testing.

larowlan’s picture

Status: Needs work » Needs review
StatusFileSize
new4.11 KB

helps if I load the include...

andypost’s picture

+++ b/core/modules/forum/forum.moduleundefined
@@ -575,24 +575,34 @@ function forum_field_storage_pre_update($entity_type, $entity, &$skip_fields) {
+ * @see taxonomy_form_vocabulary()

+++ b/core/modules/forum/forum.testundefined
@@ -246,6 +246,34 @@ class ForumTestCase extends DrupalWebTestCase {
+    // Test vid value field exists
+    $vocabulary = taxonomy_vocabulary_machine_name_load('forum');
+    module_load_include('inc', 'taxonomy', 'taxonomy.admin');
+    $form = drupal_get_form('taxonomy_form_vocabulary', $vocabulary);
+    $this->assertNotNull($form['vid'], t('Vocabulary Id field found'));
+    $this->assertNotNull($form['vid']['#value'], t('Vocabulary Id found'));

I think this is a over-engineering because if we are adding/editing vocabulary then vID field could be optional. For this purpose taxonomy_form_vocabulary() mentioned in @see
so if core would going to tremove primary key for vocabulary then we find this place

EDIT inline comments should end-up with comma

larowlan’s picture

StatusFileSize
new4.12 KB

Hey, the way I'm invoking it, vid should never be null (I'm passing $vocabulary).
Patch attached fixes inline comments and also changes assert from notNull to true.

Status: Needs review » Needs work

The last submitted patch, 787652-forum-form_alter-split_27.patch, failed testing.

larowlan’s picture

Status: Needs work » Needs review
StatusFileSize
new4.12 KB

Wrong machine name

Niklas Fiekas’s picture

Status: Needs review » Needs work
+++ b/core/modules/forum/forum.moduleundefined
@@ -575,24 +575,34 @@ function forum_field_storage_pre_update($entity_type, $entity, &$skip_fields) {
- * Implements hook_form_alter().
+ * Implements hook_form_FORM_ID_alter().
+ *
+ * @see taxonomy_form_vocabulary()

This should be hook_form_FORM_ID_alter() for xyz(). See: http://drupal.org/node/1354#hookimpl.

+++ b/core/modules/forum/forum.moduleundefined
@@ -575,24 +575,34 @@ function forum_field_storage_pre_update($entity_type, $entity, &$skip_fields) {
+    // Forum's vocabulary always has single hierarchy. Forums and containers has
+    // only one parent or no parent for root items. By default this value is 0.

Forums and containers have?

+++ b/core/modules/forum/forum.moduleundefined
@@ -575,24 +575,34 @@ function forum_field_storage_pre_update($entity_type, $entity, &$skip_fields) {
+ * Implements hook_form_FORM_ID_alter().
+ *
+ * @see taxonomy_form_term()

Another hook_form_FORM_ID_alter() implementation, as above.

+++ b/core/modules/forum/forum.testundefined
@@ -246,6 +246,34 @@ class ForumTestCase extends DrupalWebTestCase {
+    $this->assertFieldByName('op', t('Save'), t('Save button found.'));

Messages that are only used in tests shouldn't be translated. That means: Yes, do use t('Save'), but don't use t() for 'Save button found.'. The same thing goes for the other assertions.

andypost’s picture

Status: Needs work » Needs review

Let's get one more opinions

+++ b/core/modules/forum/forum.moduleundefined
@@ -575,24 +575,34 @@ function forum_field_storage_pre_update($entity_type, $entity, &$skip_fields) {
+  if (isset($form['vid']['#value']) && $form['vid']['#value'] == $vid) {

suppose we should remove isset() so if once 'vid' would be removed this alter fails

+++ b/core/modules/forum/forum.testundefined
@@ -246,6 +246,34 @@ class ForumTestCase extends DrupalWebTestCase {
+    // Test vid value field exists.
+    $vocabulary = taxonomy_vocabulary_machine_name_load('forums');
+    module_load_include('inc', 'taxonomy', 'taxonomy.admin');
+    $form = drupal_get_form('taxonomy_form_vocabulary', $vocabulary);
+    $this->assertTrue(isset($form['vid']), t('Vocabulary Id field found'));
+    $this->assertTrue(!empty($form['vid']['#value']), t('Vocabulary Id found'));
+

this make this part useless

larowlan’s picture

StatusFileSize
new3.93 KB

OK, anypost and I spoke on IRC about this and I realise the test I proposed at #19 is superfluous - other tests will fail if this field is removed upstream.

So this is the patch at #14 rerolled to take into account comments from #30 plus some other comment amendments.

Niklas Fiekas’s picture

Status: Needs review » Needs work

Excellent :)
One minor point:

+++ b/core/modules/forum/forum.moduleundefined
@@ -575,29 +575,40 @@ function forum_field_storage_pre_update($entity_type, $entity, &$skip_fields) {
+ *
+ * @see taxonomy_form_vocabulary()

(And sorry, I could have made it clearer.) The @see is superflous now.

+++ b/core/modules/forum/forum.moduleundefined
@@ -575,29 +575,40 @@ function forum_field_storage_pre_update($entity_type, $entity, &$skip_fields) {
+ *
+ * @see taxonomy_form_term()

This one, too.

larowlan’s picture

Status: Needs work » Needs review
StatusFileSize
new3.85 KB

All good

andypost’s picture

+1 to RTBC, @larowlan thanx for fixing comments and grammar

Niklas Fiekas’s picture

+++ b/core/modules/forum/forum.moduleundefined
@@ -575,29 +575,36 @@ function forum_field_storage_pre_update($entity_type, $entity, &$skip_fields) {
+}
+/**

Ugg. Another tiny thing I missed. An empty line is supposed to be here. Leaving needs review for a real review.

larowlan’s picture

StatusFileSize
new3.86 KB

Nice catch

catch’s picture

Status: Needs review » Reviewed & tested by the community

This looks good to me, so I'm marking RTBC. I'll commit in a couple of days if no objections.

catch’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed/pushed. Moving to 7.x for backport.

Tor Arne Thune’s picture

Version: 7.x-dev » 8.x-dev
Status: Patch (to be ported) » Reviewed & tested by the community

This was reverted.

webchick’s picture

Issue tags: -Needs backport to D7

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs backport to D7

The last submitted patch, 787652-forum-form_alter-split_37.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new4.35 KB

Testing profile used for test now has no Tags vocabulary

larowlan’s picture

Patch seems to be mangled, can't view it, can you please reattach?
Weird that tests passed!

andypost’s picture

StatusFileSize
new4.35 KB

Same patch

This looks very strange, I've seen this patch after upload and it was ok. Probably there's some troubles with d.o infra

larowlan’s picture

Status: Needs review » Reviewed & tested by the community

This one worked fine.

webchick’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Oof. What a mess. :) Good catch!

Committed and pushed to 8.x. This needs a quick re-roll for D7, for the TAXONOMY_HIERARCHY_* stuff if nothing else.

andypost’s picture

Status: Patch (to be ported) » Needs review
Issue tags: -Needs backport to D7
StatusFileSize
new4 KB
new2.63 KB

patches for D7

787652-forum-form_alter-FULL-split-48.patch splits hook_form_alter to 3 hooks

787652-forum-form_alter-split-48.patch just fixes wrong keys

for performance reasons it's recommended to commit FULL patch because it's just a hook split

Let's leave it for @webchick to decide

EDIT: is D7 uses testing profile? Looks like Tags vocabulary is still created and used in tests.

Status: Needs review » Needs work

The last submitted patch, 787652-forum-form_alter-FULL-split-48.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review
andypost’s picture

@larowlan please review this

larowlan’s picture

Status: Needs review » Reviewed & tested by the community

+1 for the FULL version but either are fine.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

I think it's fine to rename hook implementations. Committed and pushed the FULL patch 7.x for parity with 8.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Updated issue summary.