0

I have a Drupal 7 setup. I want to remove few Content types from the Content Type checklist that appears in Advanced Search form. I could see that advanced search form comes in 'advanced' field-set of 'search_form'.

I tried to implement the solution given here, but I am not able to find the advanced array in $form.

I would also like to add styling changes and prefix elements to default text-fields that comes within Advanced Search form Advanced Search form fields

Please find the below code that displays content of $form ($form_id = search_form), as I can't find advanced array within it.

    Array
(
    [#action] => /demodrupal7/search/node
    [#attributes] => Array
        (
            [class] => Array
                (
                    [0] => search-form
                )

        )

    [module] => Array
        (
            [#type] => value
            [#value] => node
        )

    [basic] => Array
        (
            [#type] => container
            [#attributes] => Array
                (
                    [class] => Array
                        (
                            [0] => container-inline
                        )

                )

            [keys] => Array
                (
                    [#type] => textfield
                    [#title] => Enter your keywords
                    [#default_value] => 
                    [#size] => 40
                    [#maxlength] => 255
                )

            [processed_keys] => Array
                (
                    [#type] => value
                    [#value] => 
                )

            [submit] => Array
                (
                    [#type] => submit
                    [#value] => Search
                )

        )

    [#form_id] => search_form
    [#type] => form
    [#build_id] => form-wAV_M_UAj5lbJgb-6vcdpmtxls5NpioPam6uNtkzRnw
    [form_build_id] => Array
        (
            [#type] => hidden
            [#value] => form-wAV_M_UAj5lbJgb-6vcdpmtxls5NpioPam6uNtkzRnw
            [#id] => form-wAV_M_UAj5lbJgb-6vcdpmtxls5NpioPam6uNtkzRnw
            [#name] => form_build_id
            [#parents] => Array
                (
                    [0] => form_build_id
                )

        )

    [#token] => search_form
    [form_token] => Array
        (
            [#id] => edit-search-form-form-token
            [#type] => token
            [#default_value] => 374_q2sHn_uhIvUhwOdrriFMIM3UgfVoc7Jzsh_DHrE
            [#parents] => Array
                (
                    [0] => form_token
                )

        )

    [form_id] => Array
        (
            [#type] => hidden
            [#value] => search_form
            [#id] => edit-search-form
            [#parents] => Array
                (
                    [0] => form_id
                )

        )

    [#id] => search-form
    [#method] => post
    [#theme_wrappers] => Array
        (
            [0] => form
        )

    [#icon] => 
    [#icon_position] => before
    [#process] => Array
        (
            [0] => bootstrap_form_process
        )

    [#pre_render] => Array
        (
            [0] => bootstrap_pre_render
        )

    [#tree] => 
    [#parents] => Array
        (
        )

    [#validate] => Array
        (
            [0] => search_form_validate
        )

    [#submit] => Array
        (
            [0] => search_form_submit
        )

    [#theme] => Array
        (
            [0] => search_form
        )

)

Can anyone help me with this. Thanks in advance.

1

The advanced fields are added by the node.module in node_form_search_form_alter() (a hook_form_FORM_ID_alter() implementation). It sounds like your module's hook_form_alter() is getting called before the node.module one, so you're not seeing it's additions.

The ordering of when hooks are fired is controlled by the weight column in the system table. Have you altered that previously for your module? Usually, node.module has a weight of 0 so if your module comes before that in the rows in the system table when sorted by weight then that will be your problem.

| improve this answer | |
  • 1
    Good catch! As for the hook execution order, if two modules have the same weight, the alphabetical order is used. If mynode.module has weight 0 too, its hooks are executed before the hooks from node.module. (That point should be made clearer to the OP.) – kiamlaluno May 20 at 15:44
  • The order can be changed via hook_module_implements_alter. The target hook would be form_alter then. – leymannx May 20 at 16:26
  • Thanks @Leigh. Increasing weight of custom module worked for me. – Vik Durve May 20 at 16:30
  • Both modules (node.module and custom_tasks.module) were having same weight as zero and as @kiamlaluno stated due to alphabetical ordering custom_tasks.module was getting executed before node.module. Once I increased the weight of custom_tasks.module in system table, my hook_form_alter got executed and expected output was achieved. Thanks again. – Vik Durve May 20 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.