It provides a place where a module can define its own topics, which can then be redefined by any other module / theme. It will also provide the ability for any module to use a hook such as mymodule_preprocess_theme_name to modify the variables passed to the theme's final function or template file.
There are two ways to initialize a theme function:
theme('poll_results', array('raw_title' => 'title', 'results' => $results, etc...));
and
$build = array( '#theme' => 'poll_results', '#raw_title' => 'title', '#results' => $results, etc... );
Please keep in mind that you should avoid calling the topic directly () (for documentation in the .inc theme), as it:
- Caching Circumvents.
- The default restriction on types defined in hook_element_info (), including attached assets
- Zeroes the stages of pre_render and post_render.
- JavaScript circulators contain information.
In Drupal 8, topic () is a private function, _theme (). See www.drupal.org/node/2173655 for more details.
When you compare two of these elements with the poll_results element in the above example, you can probably decide what happens ... since PHP is not a strongly typed language. Drupal provides "named arguments" through an array passed to the theme function, or as hashed keys in a rendering array.
As for the "render element", this basically tells the system that this theme function will be called using a rendering array with one named argument (in this case, form ). The code will look something like this:
$build = array( '#theme' => 'poll_choices', '#form' => $form );
This will cause the theme function to be used in the $form variable as the only argument.
Regarding the template key:
'poll_vote' => array( 'template' => 'poll-vote', 'render element' => 'form', )
defines a topic called poll_vote that uses a template file (hence the template key) with the name "poll-vote.tpl.php" (this is by agreement). The path to this template file will be found using the path to the module that implements it (for example, modules / poll / poll-vote.tpl.php), so you can place the template files in subfolders in the main module folder.
There are two ways to return the result for a theme function, by implementing the name of the physical function (in this case it will be theme_poll_vote ) or by using a template file. If the template key is empty, Drupal will assume that you have implemented a physical function and try to call it.
Template files are preferable if you have a fair bit of HTML to output for the theme, or you just don't like writing HTML in lines inside PHP (I personally don't). However, in any case, the variables passed when the theme was called (either using theme() or the visualization array, as described above) are themselves transferred to the template file or theme function. So:
function theme_poll_results(&$vars) { $raw_title = $vars['raw_title']; $results = $vars['results'];
If you used the template file instead of the same method, the variables will be available as $raw_title , $results , etc., since Drupal runs extract in $vars before $vars template file.
Iβm sure thereβs a lot that I missed, but if you have any more specific questions, try it and I will try to help.