+ All Categories
Home > Documents > Drupal 7 Render Array

Drupal 7 Render Array

Date post: 12-Mar-2015
Category:
Upload: wizzlern
View: 646 times
Download: 5 times
Share this document with a friend
Description:
The Render Array is introduced in Drupal 7 to give the themer more control over the content and its presentation. This presentation shows backgrounds and practical examples. You find the source code with this presentation at http://wizzlern.nl/drupal/presentatie-render-array
29
1 The Scary Render Array donderdag 23 juni 2011
Transcript
Page 1: Drupal 7 Render Array

1

The Scary Render Array

donderdag 23 juni 2011

Page 2: Drupal 7 Render Array

2

‣ What is the problem?

‣ The Render Array

‣ Case: Change the User Profile page

Outline

donderdag 23 juni 2011

Page 3: Drupal 7 Render Array

Sutharsan @sutharsanSkilip @skilip

@wizzlernwww.wizzlern.nl

3

donderdag 23 juni 2011

Page 4: Drupal 7 Render Array

4

What’s the problem?

donderdag 23 juni 2011

Page 5: Drupal 7 Render Array

What’s the problem?

5

donderdag 23 juni 2011

Page 6: Drupal 7 Render Array

The abstract problem

‣ HTML is generated by modules

‣ Theme layer receives fully build HTML

6

donderdag 23 juni 2011

Page 7: Drupal 7 Render Array

The abstract problem

7

‣ Young Hahn (http://bitly.com/cIYWkt)Limitations of the Drupal Theme Layer:

‣ Move something out of its ‘vertical stack’

‣ Change the formatting of an element

donderdag 23 juni 2011

Page 8: Drupal 7 Render Array

The abstract problem

‣ Parents knows little of their children

‣ Children know little of their parent (context)

‣ Siblings don’t know each other.

8

donderdag 23 juni 2011

Page 9: Drupal 7 Render Array

How does Drupal 7 solve your problem?

9

donderdag 23 juni 2011

Page 10: Drupal 7 Render Array

Render Array

10

donderdag 23 juni 2011

Page 11: Drupal 7 Render Array

11 http://www.funnyanimalpictures.netdonderdag 23 juni 2011

Page 12: Drupal 7 Render Array

The Render Array

12

donderdag 23 juni 2011

Page 13: Drupal 7 Render Array

Render example

‣ Renderable element $user_profile from user-profile.tpl.php

‣ 2 elements: ‘user_picture’ and ‘summary’.

‣ #markup = HTML

13

Array ( [user_picture] => Array ( [#markup] => '<div class="user-picture"> ... </div>' [#weight] => -10 ) [summary] => Array ( ... ))

donderdag 23 juni 2011

Page 14: Drupal 7 Render Array

Render example

‣ #type = Set of default properties. Defined in hook_element_info()

‣ #attributes, #weight, #title, #access: See FAPI

‣ Without ‘#’ = Children. Will be rendered too.

14

Array ( ... [summary] => Array ( [#type] => user_profile_category [#attributes] => Array ( ... ) [#weight] => 5 [#title] => History [member_for] => Array ( ... ) [#access] => 1 ))

donderdag 23 juni 2011

Page 15: Drupal 7 Render Array

Render example

‣ Children rendered by drupal_render() recursively.

15

Array ( ... [summary] => Array ( ... [member_for] => Array ( [#type] => user_profile_item [#title] => Member for [#markup] => 2 weeks 5 days ) ))

donderdag 23 juni 2011

Page 16: Drupal 7 Render Array

Advantages of Render Array

‣ Everything is possible in the theme layer

‣ Change theme function of a single item.

‣ Change field wrapper.

‣ Move (parts of) content to other region.

‣ Duplicate existing content.

‣ etc.

16

donderdag 23 juni 2011

Page 17: Drupal 7 Render Array

More Drupal 7 goodies

‣ All theme functions have a preprocess.e.g. THEME_preprocess_item_list(&$variables)

‣ Template functions:render(&$element)show(&$element)hide(&$element)

‣ Crazy form/render array properties:#attached, #maxlength, #state, #theme_wrappers,

#title_display

17

donderdag 23 juni 2011

Page 18: Drupal 7 Render Array

But still a bit scary ...

18

donderdag 23 juni 2011

Page 19: Drupal 7 Render Array

The Render Process

19

donderdag 23 juni 2011

Page 20: Drupal 7 Render Array

Drupal 7 Theme process

20

1. Bootstrap

2. Handle URL

3. Get page content

4. Return HTML?

5. Last call for changes

6. Render output

donderdag 23 juni 2011

Page 21: Drupal 7 Render Array

Render process

21

‣ Traversing down from the page to the 'leaves'.

hook_page_build() // Last call to modules to ADD items to the page array.hook_page_alter() // For both modules and themes to alter the page array.THEME_preprocess_page() // $variables['page'] holds page render array + childrenTHEME_process_page() // Every ‘preprocess’ is followed by a ‘process’ function.page.tpl.phpTHEME_preprocess_node() // $variables['content'] holds node render array + childrennode.tpl.php// Next: comment-wrapper, comment, etc.

donderdag 23 juni 2011

Page 22: Drupal 7 Render Array

Practice

22

donderdag 23 juni 2011

Page 23: Drupal 7 Render Array

Practice

23

donderdag 23 juni 2011

Page 24: Drupal 7 Render Array

(Pre)process functions

24

‣ template_preprocess

‣ $variables

‣ Attributes (#weight, #access, #attached)

donderdag 23 juni 2011

Page 25: Drupal 7 Render Array

hook_form_FORMID_alter

25

‣ #states attribute

‣ Vertical tabs

‣ element_children(), render(), hide()

‣ #theme attribute

donderdag 23 juni 2011

Page 26: Drupal 7 Render Array

Summary

26

donderdag 23 juni 2011

Page 27: Drupal 7 Render Array

Summary

27

‣ Problems: Vertical stack, Content awareness

‣ Solutions:

‣ Render Array, hook_page_alter()

‣ render(), show(), hide(), form #properties

donderdag 23 juni 2011

Page 28: Drupal 7 Render Array

28

Maby it was all just a bad dreamMaby it was all just a bad dream

donderdag 23 juni 2011


Recommended