This patch corrects three bugs that are interrelated in order to support organic groups fields and taxonomy tags.

Also, the patch modifies _msnf_restore_values_recursive() to use element_children() instead of testing $child['#type'] to determine if $child is a form attribute or a form element.

Organic groups fields are not correctly displayed in the field ordering page

msnf_extra_fields() only support 'extra' fields as defined by the content (cck) module. However, cck has a hook that enables other modules (organic groups, among others) to add more extra field. This patch changes msnf_extra_fields() to use cck hook to retrieve extra fields.

Extra code that did just that have been removed from _msnf_content_type_info().

Some organic group fields values are not restored

In the form definition, 'og_nodeapi' extra field looks like this:

$form = array(
    ...
    [og_nodeapi] => Array
        (
            [#group] => additional_settings
            [#weight] => 34
            [visible] => Array
                (
                    [og_groups] => Array
                        (
                            [#type] => checkboxes
                            [#title] => Collections
                            [#attributes] => Array
                                (
                                    [class] => og-audience
                                )

                            [#options] => Array
                                (
                                    [18219] => group1
                                    [18213] => group2
                                    [18215] => group3
                                )

                            [#required] => 1
                            [#description] => Blah
                            [#default_value] => Array
                                (
                                )

                            [#multiple] => 1
                        )
                )

            [#type] => fieldset
            [#title] => Groups
            [#collapsible] => 1
            [#collapsed] => 
            [og_public] => Array
                (
                    [#type] => value
                    [#value] => 1
                )

        )

and in $form_state['values'] it looks like this:

Array
(
    ...
    [og_groups] => Array
        (
            [18219] => 18219
            [18213] => 0
            [18215] => 0
        )

    [og_public] => 1
)

Since 'visible' is an array without the '#tree' attribute, and og_groups value is stored in form_states['values'], _msnf_restore_values_recursive() skips restoring og_groups value. The patch modifies _msnf_restore_values_recursive() to treat this case (the final else of the inner if).

Taxonomy tags are not restored

Taxonomy tag values are stored in a peculiar way.

Here is the form:

[taxonomy] => Array
        (
            [tags] => Array
                (
                    [1] => Array
                        (
                            [#type] => textfield
                            [#title] => Tags Vocabulary 1
                            [#required] => 1
                            [#default_value] => 
                            [#autocomplete_path] => taxonomy/autocomplete/1
                            [#weight] => -9
                            [#maxlength] => 1024
                        )

                    [7] => Array
                        (
                            [#type] => textfield
                            [#title] => Tags Vocabulary 2
                            [#required] => 0
                            [#default_value] => 
                            [#autocomplete_path] => taxonomy/autocomplete/7
                            [#weight] => -8
                            [#maxlength] => 1024
                        )

                    [9] => Array
                        (
                            [#type] => textfield
                            [#title] => Tags Vocabulary 3
                            [#required] => 0
                            [#default_value] => 
                            [#autocomplete_path] => taxonomy/autocomplete/9
                            [#weight] => -7
                            [#maxlength] => 1024
                        )
                )

            [3] => Array
                (
                    [#type] => select
                    [#title] => Normal taxonomy
                    [#default_value] => Array
                        (
                        )

                    [#options] => Array
                        (
                            [] => - Aucun -
                            [0] => stdClass Object
                                (
                                    [option] => Array
                                        (
                                            [12] => Term 1
                                        )

                                )

                            [1] => stdClass Object
                                (
                                    [option] => Array
                                        (
                                            [13] => Term 2
                                        )

                                )

                        )

                    [#description] => 
                    [#multiple] => 0
                    [#size] => 0
                    [#weight] => -4
                    [#theme] => taxonomy_term_select
                    [#required] => 0
                )

            [#type] => fieldset
            [#title] => Classification
            [#collapsible] => 1
            [#collapsed] => 
            [#weight] => -3
            [#tree] => 1
            [#group] => additional_settings
        )

and here is $form_state['values']:

    [taxonomy] => Array
        (
            [tags] => Array
                (
                    [1] => Foo
                    [7] => Bar
                    [9] => 
                    [8] => 
                    [2] => 
                    [5] => 
                    [4] => 
                )

            [3] => 
        )

As you can see, each tag is a textfield in the form, but all tag values are grouped in $form_state['values']['taxonomy']['tags'] array. The patch adds some code to treat this case (the if ($key == 'taxonomy' && $k == 'tags')).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

stBorchert’s picture

Status: Needs review » Needs work

Thanks for the patch. I didn't had a chance to test this yet but here are some notes on the patch.

+++ msnf/msnf.info	2011-12-02 23:43:41.863755301 -0500
@@ -1,6 +1,7 @@
+dependencies[] = content

CCK is *no requirement* of msnf since the module works without installing CCK (at least it was intended to do so).

+++ msnf/msnf.module	2011-12-05 01:52:23.083754528 -0500
@@ -374,17 +374,27 @@
+  foreach ($children as $k) {

Please use not one-character variables. I know, the original code uses $k too, but this was a plain copy from CCK and now we get the chance to make this somehow more readable ;)

pfournier’s picture

Status: Needs work » Needs review
FileSize
2.8 KB

I added the dependency to content because the way I rewrote msnf_extra_fields(), the content module is needed.

I re-included content_content_extra_fields() code in order to remove this dependency. I also renamed the $k variable.

Here is a revised patch.

pfournier’s picture

Here is a nicer patch that includes whitespace differences.

stBorchert’s picture

Version: 6.x-1.2 » 6.x-1.x-dev
Status: Needs review » Needs work

The last patch breaks Multistep Nodeform totally when working without CCK.

/me working on it ...

stBorchert’s picture

Status: Needs work » Needs review

Well, I've rewritten some parts of your patch (there were some more parts broken, e.g. "publishing options") and fixed some small bugs noone noticed before :)

Committed to 6.x-1.x-dev so it should be in the next dev release (in a couple of hours).

pfournier’s picture

Thanks! I did not tested without CCK. As they say, if it not tested, it does not work :-)

stBorchert’s picture

Status: Needs review » Fixed

Fixed in 6.x-1.3.

Status: Fixed » Closed (fixed)

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