Problem/Motivation
Now that the Twig engine is in core, we must convert all existing core *.tpl.php template files andtheme_
functions to use Twig templates. Preprocess functions and hook_theme definitions must also be updated.
TODO
DOCS: Coding standards for conversion:
Resources
- Watch the Twig screencast for help:http://www.youtube.com/watch?v=HS4yKJjrb2E
- Read more about Twig best practices for preprocess functions and templates in Drupal docs.
Proposed resolution
See sub-issues below.
Remaining tasks
Template file conversions:
Replace all tpl.php files with .html.twig equivalentsUpdate preprocess functions for the .html.twig versions of .tpl.php templates, to use renderablesBenchmark the .html.twig versions of template files to assure they aren't very much slower
Convert theme_* functions to Twig templates.
- Replace all theme functions with .html.twig equivalent templates
- Add new preprocess functions for the .html.twig versions of theme functions (if necessary)
- Benchmark the .html.twig versions of theme functions to assure they aren't very much slower
- Update all hook_theme definitions to include
'template' => 'foo',
where foo.html.twig is the template being added
The total count of remaining (not including test functions or theme overrides) theme functions in core is displayed in the issue title. This search can be run in ack 2.x to get the current number:
ack 'function theme_[^(]+\([^$]*(\$variables)*\) ?{' -h -c --ignore-dir=core/modules/system/tests core
Remove the -c to get a list of remaining theme functions. Not all these theme functions will end up as Twig templates but our goal is to be rid of all them for 8.0.0.
RTBC
Needs review
@see Documentation for reviewing patches
- language module: #1898422: language.module - Convert theme_ functions to Twig
- image module: #1898420: image.module - Convert theme_ functions to TwigAssigned to: Cottser
- update module: #1898466: update.module - Convert theme_ functions to Twig
- seven theme: #1987424: seven.theme - Convert theme_ functions to TwigAssigned to: mark.labrecque
Needs profiling
@see Documentation for profiling twig patches
- Issues that need profiling
- simpletest module: #1898452: simpletest.module - Convert theme_simpletest_result_summary functions to Twig
- user module theme_ functions: #1987418: user.module - Convert theme_ functions to Twig
Needs manual testing
@see Documentation for manually testing twig patches
- theme.maintenance.inc (authorize.php testing): #1885564: theme.maintenance.inc - Convert theme_ functions to TwigAssigned to: trevorkjorlien
- #2152205: Convert theme_date() to #theme input__date
- menu.inc: #1898478: menu.inc - Convert theme_ functions to Twig
- file module: #1898070: file.module - Convert theme_ functions to Twig
Needs work
- #2152227: Convert theme_tableselect() to #theme table__tableselect
- #2151821: Convert theme_system_config_form() to Twig
- #2152219: Convert theme_input() to Twig
- #2151109: Convert theme_system_modules_details() to TwigAssigned to: gnuget
Needs work (needs Tests)
@see Documentation for writing automated tests
- remove theme_more_link #2031301: Remove theme_more_link() and replace with #type 'more_link'Assigned to: mark.labrecque
Needs work (performance tuning)
- picture module: #1898442: responsive_image.module - Convert theme_ functions to TwigAssigned to: jayeshanandani
Sub Metas
- system module meta (@todo add sub-issues here): #1987410: [meta] system.module - Convert theme_ functions to Twig
- form.inc meta (@todo add sub-issues here): #1898480: [meta] form.inc - Convert theme_ functions to Twig
Postponed
- theme_test module theme_ functions: #1987414: theme_test.module - Convert theme_ functions to Twig
- mark #1939092: Convert theme_mark() to Twig
- #1963980: Convert theme_views_ui_expose_filter_form() to Twig
- #1963982: Convert theme_views_ui_rearrange_filter_form() to Twig
- menu module: #1898430: menu.module - Convert theme_ functions to Twig
- forum module: #1987400: forum.module - Convert theme_ functions to Twig
Fixed/closed (roughly reverse chronological)
- #2152217: Remove theme_form_required_marker() from the theme system - use CSS instead
- #2151105: Convert theme_system_admin_index() to Twig
- #2151123: Remove theme_system_modules_incompatible()
- table #1939008: Convert theme_table() to TwigAssigned to: sun
- #2152201: Convert theme_checkboxes() to Twig
- #2151113: Convert theme_system_modules_uninstall() to TwigAssigned to: martin107
- #2152211: Convert theme_form() to Twig
- field module theme_ functions: #1987398: field.module - Convert theme_ functions to Twig
- #2151089: Convert theme_admin_block() to Twig
- #2151095: Convert theme_admin_page() to Twig
- #2151097: Convert theme_confirm_form() to Twig
- #2151107: Convert theme_system_compact_link() to Twig
- #2152221: Convert theme_radios() to Twig
- image: #1939068: Convert theme_image() to Twig
- #2151119: Convert theme_system_themes_page() to Twig
- #2152203: Convert theme_container() to Twig
- #2151093: Convert theme_admin_block_content() to Twig
- #2152209: Convert theme_fieldset() to Twig
- #2152225: Convert theme_select() to Twig
- node module theme_ functions: #1987406: node.module - Convert theme_ functions to Twig
- item list #1939062: Convert theme_item_list() to Twig
- #2152207: Convert theme_details() to Twig
- theme links #1939064: Convert theme_links() to Twig
- forum topic list #2092343: Consolidate forum.module and remove call to _theme_table_cell() within template_preprocess_forum_topic_list()
- #2152213: Convert theme_form_element() to Twig
- #2152229: Convert theme_textarea() to Twig
- #2151117: Remove theme_system_powered_by()
- #2151101: Convert theme_status_report() to Twig
- #2152231: Convert theme_vertical_tabs() to Twig [small followup]
- comment module: #1987396: Refactor & Clean-up comment.module theme functions
- filter module: #1898416: filter.module - Convert theme_ functions to Twig
- toolbar module: #1898464: toolbar.module - Convert theme_ functions to Twig
- ckeditor module: #1963474: ckeditor.module - Convert theme_ functions to Twig
- rdf module: #1898444: rdf.module - Convert theme_ functions to Twig
- indentation: #1939102: Convert theme_indentation() to Twig
- aggregator module theme_ functions: #1987390: aggregator.module - Convert theme_ functions to Twig
- status messages: #1939082: Convert theme_status_messages() to Twig
- feed icon: #1939096: Convert theme_feed_icon() to Twig
- theme_views_mini_pager: #1912604: Convert theme_views_mini_pager to twig
- #1918648: Convert theme_views_ui_style_plugin_table to Twig
- #1912600: Remove theme_views_form_views_form in favour of a prerender callback.
- #1912606: Remove theme_views_view_grouping function
- #1939086: Convert theme_dropbutton_wrapper() to Twig
- #1939100: Convert theme_progress_bar() to Twig
- #1915026: Convert theme_views_ui_container to Twig
- #1963476: datetime.module - Convert theme_ functions to Twig
- #1963986: Convert theme_views_ui_view_info() to Twig
- #2031305: Remove theme_more_help_link() and replace with a #type link render array
- #1898474: pager.inc - Convert theme_ functions to Twig
- #1898426: link.module - Convert theme_ functions to Twig
- #1963988: Convert theme_views_ui_view_preview_section() to Twig
- #1963764: Convert theme_views_view_mapping_test() to Twig
- #1939066: Convert theme_breadcrumb() to Twig
- #1939090: Convert theme_tablesort_indicator() to Twig
- #1939080: Convert theme_datetime() to Twig
- #1898428: locale.module - Convert theme_ functions to Twig
- #1898456: common_test.module - Convert theme_ functions to Twig
- #1898060: Remove all (useless) theme functions from dblog module, so we don't have to convert to Twig
- #1898038: custom_block.module - Convert theme_ functions to Twig
- #1898052: color.module - Convert theme_ functions to Twig
- #1898448: search.module - Convert PHPTemplate templates to Twig
- overlay module theme_ functions: #1987408: overlay.module - Convert theme_ functions to Twig
- options module: #1898434: Remove theme_options_none, use an alter hook instead for changing empty option label
- theme_views_view_field() will be removed in #1843746: Convert views/templates/views-view-field.tpl.php to Twig
- #1939104: Convert theme_html_tag() to Twig
- #1963978: Convert theme_views_ui_build_group_filter_form() to Twig
- shortcut module: #1898450: shortcut.module - Convert theme_ functions to Twig
- field_ui module: #1898068: field_ui.module - Convert theme_ functions to Twig
- [meta] theme.inc: #1885560: [meta] Convert everything in theme.inc to Twig
- link: #1961876: Convert theme_link() to Twig
- more link #1939098: Convert theme_more_link() to Twig
- more help link: #1939094: Convert theme_more_help_link() to Twig
User interface changes
None.
API changes
Likely minimal to no API changes.
Possible new theme layer process order:
http://gist.io/5650535
Resources
Google Docs:
- Twig Conversion Instructions (All conversions have been moved to the core queue, we would like to have a handbook page on Drupal.org similar to this document to detail converting templates and theme functions to Twig)
- Twig Consolidation Suggestions (after this issue is fixed).
Twig sandbox: http://drupal.org/sandbox/pixelmord/1750250 (all conversions have been moved over from the sandbox and we are working directly in the core queue, the sandbox link is only here for reference).
Related Issues
- #1987510: [meta] Convert all core *.tpl.php templates to Twig as singular patch
- #1843650: Remove the process layer (hook_process and hook_process_HOOK)
### These issues were actually blocking progress ###
- #1922454: Gut l(), fix theme('link'), have a working framework for consistently generated links inside and outside of TwigAssigned to: catch
- #1867090: Nested Twig 'for' loops behaving strange
- #1975442: drupal_render() should always return a string.
## This issue will decrease the work we need to do ##
These issues are related to our work, and will block the release of D8
- #1938948: Temporarily allow PHPTemplate themes to use .html.twig templates during Twig conversion
- #1920886: drupal_render() should check if it's rendering a 'render element' and if so call drupal_render_children() (inline) insteadAssigned to: Fabianx
- #1938430: Don't add a default theme hook class in template_preprocess()
- #1649780: Remove first/last/odd/even classes in favor of CSS3 pseudo selectors
Twig engine issues
- #2082845: Remove end of file newline from twig files automatically.
- #1970960: Twig implementation does not print int(0)Assigned to: alexrayu
- #1975462: Allow and test for NULL and integer 0 values in Twig templates.
- #1971860: Document that Twig debug mode breaks tests
- #1964156: Contrib cannot define additional Twig extensions
- #2006282: Refactor Attribute classes - Cleanup, Security, and Readability and minor performance
- #2048637: Add #type => 'attributes' and wrap in Attribute class with drupal_pre_render_attributes
- #1927584: Add support for the Twig {% trans %} tag extensionAssigned to: Mark Carver
- #1922304: Remove TwigReference objects in favor of a high speed implementation by using NodeVisitors more cleverly
Performance issues
- #1982018: [meta] Refactor template_preprocess()
- Remove unnecessary preprocessing (no issue yet)
- #1982024: Lazy-load Attribute objects later in the rendering process only if needed
- #1920886: drupal_render() should check if it's rendering a 'render element' and if so call drupal_render_children() (inline) insteadAssigned to: Fabianx
- #1986116: Improve performance by replacing very small and simple templates and theme function with "Markup Utility Functions"
After Commit Issues
- Update preprocess functions for the .html.twig versions of .tpl.php templates - remove unnecessary preprocessing:
- #1963942: Change all instances of $vars to $variables
- #1905584: Move base theme system templates into /core/templatesAssigned to: joelpittet
- #1825952: Turn on twig autoescape by default.
- #1818266: [meta] A secure theme system (with twig)Assigned to: Fabianx
- #1804614: [meta] Consolidate theme functions and properly use theme suggestions in core
- #1993512: template_preprocess_views_ui_display_tab_setting() doesn't need two variables that mean the same thing.
Notes for reviewing Twig Patches manually
To find a list of patches that are theoretically good to go but manual testing is holding them back see http://drupal.org/project/issues/search/drupal?text=convert&status%5B%5D....
It is helpful to use Dreditor to review patches and to test patches applied to fresh install of Drupal8 via simplytest.me.
Generally, you are trying to see if the HTML output has changed from a clean install of Drupal 8 versus a patched install. Many Twig issues have a "To test this code" section in the issue summary that will direct you how to test the patch. If you find that testing the patch using simplytest.me has not produced the results you expected, or only some of the expected output, you will want to test the patch manually.
Check out this screencast on how to use Daisy Diff to compare markup:http://www.youtube.com/watch?v=Bv4PY_ZEP4Q