Skip to content

Send missing variables to the TIMS template#29

Open
mfairchild365 wants to merge 2 commits intounlcms:7.x-1.xfrom
mfairchild365:preprocess
Open

Send missing variables to the TIMS template#29
mfairchild365 wants to merge 2 commits intounlcms:7.x-1.xfrom
mfairchild365:preprocess

Conversation

@mfairchild365
Copy link

I've descovered, and I know @ericras has too, that not all variables make it to the TIMS template. A specific example of this is the views_view template seen here: https://api.drupal.org/api/views/theme!views-view.tpl.php/7

In TIMS, none of those contextual variables are available, which makes the template useless.

I've discovered that this is because of the way that we are altering the theme registry.

The theme registry has an item for views_view which is as follows:

[views_view] => Array
        (
            [pattern] => views_view__
            [file] => theme.inc
            [path] => sites/all/modules/views/theme
            [variables] => Array
                (
                    [view_array] => Array
                        (
                        )

                    [view] => 
                )

            [template] => views-view
            [type] => module
            [theme path] => sites/all/modules/views
            [includes] => Array
                (
                    [0] => sites/all/modules/views/theme/theme.inc
                )

            [preprocess functions] => Array
                (
                    [0] => template_preprocess
                    [1] => template_preprocess_views_view
                    [2] => contextual_preprocess
                    [3] => views_ui_preprocess_views_view
                )

            [process functions] => Array
                (
                    [0] => template_process
                    [1] => template_process_views_view
                    [2] => ctools_process
                )

        )

Then, the TIMS module adds its own entry like this:

[views_view__test__page] => Array
        (
            [function] => tims_render
            [theme path] => sites/all/modules/tims/theme
            [process functions] => Array
                (
                    [0] => tims_set_template
                )

        )

Thus, we have lost the process and preprocess hooks along with other important information.

So, this change merges the two so that it becomes:

Array
(
    [pattern] => views_view__
    [file] => theme.inc
    [path] => sites/all/modules/views/theme
    [variables] => Array
        (
            [view_array] => Array
                (
                )

            [view] => 
        )

    [template] => views-view
    [type] => module
    [theme path] => Array
        (
            [0] => sites/all/modules/views
            [1] => sites/all/modules/tims/theme
        )

    [includes] => Array
        (
            [0] => sites/all/modules/views/theme/theme.inc
        )

    [preprocess functions] => Array
        (
            [0] => template_preprocess
            [1] => template_preprocess_views_view
            [2] => contextual_preprocess
            [3] => views_ui_preprocess_views_view
        )

    [process functions] => Array
        (
            [0] => template_process
            [1] => template_process_views_view
            [2] => ctools_process
            [3] => tims_set_template
        )

    [function] => tims_render
)

I'm not very familiar with how all of this works, and I'm not quite sure how to know which entry to merge in the case where there are multiple hook patterns that match. I'm also only doing this for entries with patterns, but I think it should be okay to do it to everything?

Any thoughts/feedback is welcome.

@ericras
Copy link
Member

ericras commented Jul 2, 2015

Did you happen across something without a 'pattern' defined? Without looking into it, I would assume there would always be a pattern.

@mfairchild365
Copy link
Author

Yeah, there are plenty of cases where a pattern is not defined.

[status_messages] => Array
        (
            [function] => unl_four_status_messages
            [type] => theme_engine
            [theme path] => sites/all/themes/unl_four
            [variables] => Array
                (
                    [display] => 
                )

        )

    [breadcrumb] => Array
        (
            [function] => unl_four_breadcrumb
            [type] => theme_engine
            [theme path] => sites/all/themes/unl_four
            [variables] => Array
                (
                    [breadcrumb] => 
                )

        )

    [pager] => Array
        (
            [function] => unl_four_pager
            [type] => theme_engine
            [theme path] => sites/all/themes/unl_four
            [variables] => Array
                (
                    [tags] => Array
                        (
                        )

                    [element] => 0
                    [parameters] => Array
                        (
                        )

                    [quantity] => 9
                )

        )

    [menu_tree] => Array
        (
            [function] => unl_four_menu_tree
            [type] => theme_engine
            [theme path] => sites/all/themes/unl_four
            [render element] => tree
            [preprocess functions] => Array
                (
                    [0] => template_preprocess_menu_tree
                )

        )

    [menu_local_task] => Array
        (
            [function] => unl_four_menu_local_task
            [type] => theme_engine
            [theme path] => sites/all/themes/unl_four
            [render element] => element
        )

    [menu_local_tasks] => Array
        (
            [function] => unl_four_menu_local_tasks
            [type] => theme_engine
            [theme path] => sites/all/themes/unl_four
            [variables] => Array
                (
                    [primary] => Array
                        (
                        )

                    [secondary] => Array
                        (
                        )

                )

        )

    [file] => Array
        (
            [function] => unl_four_file
            [type] => theme_engine
            [theme path] => sites/all/themes/unl_four
            [render element] => element
        )

    [form_element] => Array
        (
            [function] => unl_four_form_element
            [type] => theme_engine
            [theme path] => sites/all/themes/unl_four
            [render element] => element
        )

    [file_icon] => Array
        (
            [function] => unl_four_file_icon
            [type] => theme_engine
            [theme path] => sites/all/themes/unl_four
            [variables] => Array
                (
                    [file] => 
                    [icon_directory] => 
                )

        )

    [webform_element] => Array
        (
            [function] => unl_four_webform_element
            [type] => theme_engine
            [theme path] => sites/all/themes/unl_four
            [render element] => element
        )

    [webform_time] => Array
        (
            [function] => unl_four_webform_time
            [type] => theme_engine
            [theme path] => sites/all/themes/unl_four
            [includes] => Array
                (
                    [0] => sites/all/modules/webform/components/time.inc
                )

            [render element] => element
        )

    [block] => Array
        (
            [template] => block
            [path] => sites/all/themes/unl_four
            [type] => theme_engine
            [theme path] => sites/all/themes/unl_four
            [render element] => elements
            [preprocess functions] => Array
                (
                    [0] => template_preprocess
                    [1] => template_preprocess_block
                    [2] => context_preprocess_block
                    [3] => contextual_preprocess
                    [4] => system_preprocess_block
                    [5] => unl_four_preprocess_block
                )

            [process functions] => Array
                (
                    [0] => template_process
                    [1] => ctools_process
                )

        )

    [field] => Array
        (
            [template] => field
            [path] => sites/all/themes/unl_four
            [type] => theme_engine
            [theme path] => sites/all/themes/unl_four
            [render element] => element
            [preprocess functions] => Array
                (
                    [0] => template_preprocess_field
                    [1] => unl_four_preprocess_field
                )

            [process functions] => Array
                (
                    [0] => template_process_field
                )

        )

    [html] => Array
        (
            [template] => html
            [path] => sites/all/themes/unl_four
            [type] => theme_engine
            [theme path] => sites/all/themes/unl_four
            [render element] => page
            [preprocess functions] => Array
                (
                    [0] => template_preprocess
                    [1] => template_preprocess_html
                    [2] => context_preprocess_html
                    [3] => contextual_preprocess
                    [4] => toolbar_preprocess_html
                    [5] => views_preprocess_html
                    [6] => unl_four_preprocess_html
                )

            [process functions] => Array
                (
                    [0] => template_process
                    [1] => template_process_html
                    [2] => ctools_process
                    [3] => unl_four_process_html
                )

        )

    [page] => Array
        (
            [template] => page
            [path] => sites/all/themes/unl_four
            [type] => theme_engine
            [theme path] => sites/all/themes/unl_four
            [render element] => page
            [preprocess functions] => Array
                (
                    [0] => template_preprocess
                    [1] => template_preprocess_page
                    [2] => context_preprocess_page
                    [3] => contextual_preprocess
                    [4] => shortcut_preprocess_page
                    [5] => unl_preprocess_page
                    [6] => unl_four_preprocess_page
                )

            [process functions] => Array
                (
                    [0] => template_process
                    [1] => template_process_page
                    [2] => ctools_process
                    [3] => unl_four_process_page
                )

        )

    [region] => Array
        (
            [template] => region
            [path] => sites/all/themes/unl_four
            [type] => theme_engine
            [theme path] => sites/all/themes/unl_four
            [render element] => elements
            [preprocess functions] => Array
                (
                    [0] => template_preprocess
                    [1] => template_preprocess_region
                    [2] => contextual_preprocess
                    [3] => unl_four_preprocess_region
                )

            [process functions] => Array
                (
                    [0] => template_process
                    [1] => ctools_process
                )

        )

    [region__navlinks] => Array
        (
            [template] => region--navlinks
            [path] => sites/all/themes/unl_four
            [render element] => elements
            [base hook] => region
            [type] => theme_engine
            [theme path] => sites/all/themes/unl_four
        )

    [node__unl_newsitem] => Array
        (
            [template] => node--unl-newsitem
            [path] => sites/all/themes/unl_four
            [render element] => elements
            [base hook] => node
            [type] => theme_engine
            [theme path] => sites/all/themes/unl_four
        )

@ericras
Copy link
Member

ericras commented Jul 2, 2015

Ah, of course. I think it would be ok to do it with everything. There's at least one thing in there that we'd want merged: 'field' since we did stuff with unl_four_preprocess_field that's not currently being respected due to this issue.

Use the logic found in the drupal theme() function as a guideline here. This should handle specificity issues.
@mfairchild365
Copy link
Author

@ericras I've updated the pull request to include hooks without patterns and to also find the most generic hook to merge, using the logic from the drupal theme() function.

@mfairchild365
Copy link
Author

@ericras is this still relevant?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants