diff --git a/core/modules/field/field.api.php b/core/modules/field/field.api.php index b159f59579d4679d62a3de703f45b22f65b17658..75a99df2c8943a621bb83f66ad7af51b8751d091 100644 --- a/core/modules/field/field.api.php +++ b/core/modules/field/field.api.php @@ -970,7 +970,7 @@ function hook_field_attach_update(\Drupal\Core\Entity\EntityInterface $entity) { /** * Alter field_attach_preprocess() variables. * - * This hook is invoked while preprocessing the field.tpl.php template file in + * This hook is invoked while preprocessing field templates in * field_attach_preprocess(). * * @param $variables diff --git a/core/modules/field/field.module b/core/modules/field/field.module index bf0ac5699add0bf7a184fd21d70b83d99ca21603..a429eea515b81a8e77fd87fec7fed5e450c1ba7b 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -985,10 +985,17 @@ function field_page_build(&$page) { } /** - * Theme preprocess function for theme_field() and field.tpl.php. + * Prepares variables for field templates. * - * @see theme_field() - * @see field.tpl.php + * Default template: field.html.twig. + * + * @param array $variables + * An associative array containing: + * - element: A render element representing the field. + * - attributes: A string containing the attributes for the wrapping div. + * - title_attributes: A string containing the attributes for the title. + * - content_attributes: A string containing the attributes for the content's + * div. */ function template_preprocess_field(&$variables, $hook) { $element = $variables['element']; @@ -1041,10 +1048,10 @@ function template_preprocess_field(&$variables, $hook) { } /** - * Theme process function for theme_field() and field.tpl.php. + * Theme process function for theme_field() and field.html.twig. * * @see theme_field() - * @see field.tpl.php + * @see field.html.twig */ function template_process_field(&$variables, $hook) { static $default_attributes; @@ -1084,23 +1091,23 @@ function template_process_field(&$variables, $hook) { * - THEMENAME_field() * * Theme developers who prefer to customize templates instead of overriding - * functions may copy the "field.tpl.php" from the "modules/field/theme" folder - * of the Drupal installation to somewhere within the theme's folder and + * functions may copy the "field.html.twig" from the "modules/field/theme" + * folder of the Drupal installation to somewhere within the theme's folder and * customize it, just like customizing other Drupal templates such as - * page.tpl.php or node.tpl.php. However, it takes longer for the server to + * page.html.twig or node.html.twig. However, it takes longer for the server to * process templates than to call a function, so for websites with many fields * displayed on a page, this can result in a noticeable slowdown of the website. - * For these websites, developers are discouraged from placing a field.tpl.php + * For these websites, developers are discouraged from placing a field.html.twig * file into the theme's folder, but may customize templates for specific * fields. For example, for a field named 'body' displayed on the 'article' * content type, any of the following templates will override this default * implementation. The first of these templates that exists is used: - * - field--body--article.tpl.php - * - field--article.tpl.php - * - field--body.tpl.php - * - field.tpl.php + * - field--body--article.html.twig + * - field--article.html.twig + * - field--body.html.twig + * - field.html.twig * So, if the body field on the article content type needs customization, a - * field--body--article.tpl.php file can be added within the theme's folder. + * field--body--article.html.twig file can be added within the theme's folder. * Because it's a template, it will result in slightly more time needed to * display that field, but it will not impact other fields, and therefore, is * unlikely to cause a noticeable change in website performance. A very rough @@ -1125,7 +1132,7 @@ function template_process_field(&$variables, $hook) { * * @see template_preprocess_field() * @see template_process_field() - * @see field.tpl.php + * @see field.html.twig * * @ingroup themeable */ diff --git a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php index 7e7de463319bd0e06ce55f82236e181baca0bdde..19fe3e163ca01b63cfc2cb0678ddd6b8563d8350 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php +++ b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php @@ -371,7 +371,7 @@ public function buildOptionsForm(&$form, &$form_state) { '#title' => t('Use field template'), '#type' => 'checkbox', '#default_value' => $this->options['field_api_classes'], - '#description' => t('If checked, field api classes will be added using field.tpl.php (or equivalent). This is not recommended unless your CSS depends upon these classes. If not checked, template will not be used.'), + '#description' => t('If checked, field api classes will be added by field templates. This is not recommended unless your CSS depends upon these classes. If not checked, template will not be used.'), '#fieldset' => 'style_settings', '#weight' => 20, ); diff --git a/core/modules/field/templates/field.html.twig b/core/modules/field/templates/field.html.twig new file mode 100644 index 0000000000000000000000000000000000000000..4b1336668475802414aedb3618cd53344bbd64d1 --- /dev/null +++ b/core/modules/field/templates/field.html.twig @@ -0,0 +1,48 @@ +{# +/** + * @file + * Default theme implementation for a field. + * + * To override output, copy the "field.html.twig" from the templates directory + * to your theme's directory and customize it, just like customizing other + * Drupal templates such as page.html.twig or node.html.twig. + * + * For example, for a field named 'body' displayed on the 'article' content + * type, any of the following templates will override this default + * implementation. The first of these templates that exists is used: + * - field--body--article.html.twig + * - field--article.html.twig + * - field--body.html.twig + * - field.html.twig + * + * Available variables: + * - attributes: HTML attributes for the containing element. + * - label_hidden: Whether to show the field label or not. + * - title_attributes: HTML attributes for the title. + * - label: The label for the field. + * - content_attributes: HTML attributes for the content. + * - items: List of all the field items. + * - item_attributes: List of HTML attributes for each item. + * + * @see template_preprocess_field() + * @see theme_field() + * + * @ingroup themeable + */ +#} + + + {% if not label_hidden %} +
{{ label }}: 
+ {% endif %} +
+ {% for delta, item in items %} +
{{ item }}
+ {% endfor %} +
+ diff --git a/core/modules/field/templates/field.tpl.php b/core/modules/field/templates/field.tpl.php deleted file mode 100644 index a8ffe322af5f48a63c6f69f341669c1dc33b1898..0000000000000000000000000000000000000000 --- a/core/modules/field/templates/field.tpl.php +++ /dev/null @@ -1,59 +0,0 @@ - - -
> - -
>
- -
> - $item): ?> -
>
- -
-