diff --git a/core/modules/file/file.field.inc b/core/modules/file/file.field.inc
index de03e50..a5fe46d 100644
--- a/core/modules/file/file.field.inc
+++ b/core/modules/file/file.field.inc
@@ -7,6 +7,7 @@
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Template\Attribute;
/**
* Implements hook_field_info().
@@ -638,15 +639,16 @@ function file_field_widget_submit($form, &$form_state) {
}
/**
- * Returns HTML for an individual file upload widget.
+ * Prepares variables for file form widget templates.
*
- * @param $variables
- * An associative array containing:
- * - element: A render element representing the widget.
+ * Default template: file-widget.html.twig.
*
- * @ingroup themeable
+ * @param array $variables
+ * An associative array containing:
+ * - element: A render element representing the file.
+ * - element_attributes: An Array of HTML attributes.
*/
-function theme_file_widget($variables) {
+function template_preprocess_file_widget(&$variables) {
$element = $variables['element'];
$output = '';
@@ -657,22 +659,21 @@ function theme_file_widget($variables) {
$file = reset($element['#files']);
$element['file_' . $file->fid]['filename']['#markup'] .= ' (' . format_size($file->filesize) . ') ';
}
- $output .= drupal_render_children($element);
- $output .= '';
-
- return $output;
+ $variables['element'] = drupal_render_children($element);
+ // The "form-managed-file" class is required for proper Ajax functionality.
+ $variables['attributes'] = new Attribute(array('class' => array('file-widget', 'form-managed-file', 'clearfix')));
}
/**
- * Returns HTML for a group of file upload widgets.
+ * Prepares variables for multi file form widget templates.
+ *
+ * Default template: file-widget-multiple.html.twig.
*
- * @param $variables
+ * @param array $variables
* An associative array containing:
* - element: A render element representing the widgets.
- *
- * @ingroup themeable
*/
-function theme_file_widget_multiple($variables) {
+function template_preprocess_file_widget_multiple(&$variables) {
$element = $variables['element'];
// Special ID and classes for draggable tables.
@@ -754,6 +755,7 @@ function theme_file_widget_multiple($variables) {
}
$row[] = $weight;
$row[] = $operations;
+
$rows[] = array(
'data' => $row,
'class' => isset($widget['#attributes']['class']) ? array_merge($widget['#attributes']['class'], array('draggable')) : array('draggable'),
@@ -762,26 +764,28 @@ function theme_file_widget_multiple($variables) {
drupal_add_tabledrag($table_id, 'order', 'sibling', $weight_class);
- $output = '';
- $output = empty($rows) ? '' : theme('table', array('header' => $headers, 'rows' => $rows, 'attributes' => array('id' => $table_id)));
- $output .= drupal_render_children($element);
- return $output;
+ $variables['table'] = array(
+ '#theme' => 'table',
+ '#header' => $headers,
+ '#rows' => $rows,
+ '#attributes' => array('id' => $table_id),
+ );
+ $variables['element'] = drupal_render_children($element);
}
-
/**
- * Returns HTML for help text based on file upload validators.
+ * Prepares variables for help text templates.
+ *
+ * Default template: file-upload-help.html.twig
*
- * @param $variables
+ * @param array $variables
* An associative array containing:
* - description: The normal description for this field, specified by the
* user.
* - upload_validators: An array of upload validators as used in
* $element['#upload_validators'].
- *
- * @ingroup themeable
*/
-function theme_file_upload_help($variables) {
+function template_preprocess_file_upload_help(&$variables) {
$description = $variables['description'];
$upload_validators = $variables['upload_validators'];
$cardinality = $variables['cardinality'];
@@ -822,7 +826,7 @@ function theme_file_upload_help($variables) {
}
}
- return implode('
', $descriptions);
+ $variables['descriptions'] = $descriptions;
}
/**
@@ -849,23 +853,35 @@ function file_field_find_file_reference_column($field) {
}
/**
- * Returns HTML for a file attachments table.
+ * Prepares variables for file attachments table templates.
+ *
+ * Default template: file-formatter-table.html.twig.
*
- * @param $variables
+ * @param array $variables
* An associative array containing:
* - items: An array of file attachments.
- *
- * @ingroup themeable
*/
-function theme_file_formatter_table($variables) {
+function template_preprocess_file_formatter_table(&$variables) {
$header = array(t('Attachment'), t('Size'));
$rows = array();
foreach ($variables['items'] as $delta => $item) {
$rows[] = array(
- theme('file_link', array('file' => (object) $item)),
- format_size($item['filesize']),
+ array(
+ 'data' => array(
+ '#theme' => 'file_link',
+ '#file' => (object) $item,
+ ),
+ ),
+ array('data' => format_size($item['filesize'])),
);
}
- return empty($rows) ? '' : theme('table', array('header' => $header, 'rows' => $rows));
+ $variables['content'] = array();
+ if (!empty($rows)) {
+ $variables['content'] = array(
+ '#theme' => 'table',
+ '#header' => $header,
+ '#rows' => $rows,
+ );
+ }
}
diff --git a/core/modules/file/file.module b/core/modules/file/file.module
index 3fcd034..e74ca30 100644
--- a/core/modules/file/file.module
+++ b/core/modules/file/file.module
@@ -589,26 +589,28 @@ function file_get_content_headers(File $file) {
*/
function file_theme() {
return array(
- // file.module.
+ // From file.module.
'file_link' => array(
'variables' => array('file' => NULL, 'icon_directory' => NULL, 'description' => NULL),
- ),
- 'file_icon' => array(
- 'variables' => array('file' => NULL, 'icon_directory' => NULL),
+ 'template' => 'file-link',
),
'file_managed_file' => array(
'render element' => 'element',
+ 'template' => 'file-managed-file',
),
- // file.field.inc.
+ // From file.field.inc.
'file_widget' => array(
'render element' => 'element',
+ 'template' => 'file-widget',
),
'file_widget_multiple' => array(
'render element' => 'element',
+ 'template' => 'file-widget-multiple'
),
'file_formatter_table' => array(
'variables' => array('items' => NULL),
+ 'template' => 'file-formatter-table',
),
'file_upload_help' => array(
'variables' => array('description' => NULL, 'upload_validators' => NULL, 'cardinality' => NULL),
@@ -1220,15 +1222,16 @@ function file_managed_file_save_upload($element) {
}
/**
- * Returns HTML for a managed file element.
+ * Prepares variables for file form widget templates.
+ *
+ * Default template: file-managed-file.html.twig.
*
- * @param $variables
+ * @param array $variables
* An associative array containing:
* - element: A render element representing the file.
- *
- * @ingroup themeable
+ * - element_attributes: An Array of HTML attributes.
*/
-function theme_file_managed_file($variables) {
+function template_preprocess_file_managed_file(&$variables) {
$element = $variables['element'];
$attributes = array();
@@ -1240,12 +1243,8 @@ function theme_file_managed_file($variables) {
}
$attributes['class'][] = 'form-managed-file';
- // This wrapper is required to apply JS behaviors and CSS styling.
- $output = '';
- $output .= '