I've created a preprocess function in addition to the twig template, however I'm unable to test locally due to errors (attached screenshot)
Fatal error: Maximum function nesting level of '100' reached, aborting! in /Users/jason/Sites/1750250/core/includes/bootstrap.inc on line 2655

Comments

EVIIILJ’s picture

Status: Needs work » Needs review
StatusFileSize
new119.13 KB
new1.74 KB

I forgot the screenshot :(
While I'm at it here is the patch including the template preprocess function in addition to the image-widget.html.twig template.

EVIIILJ’s picture

Category: support » task
EVIIILJ’s picture

StatusFileSize
new1.77 KB

Fixed code spacing from tabs to spaces.

decafdennis’s picture

Status: Needs review » Needs work
+  {% if preview is defined %}
+    <div class="image-preview">
+      {{ preview }}
+    </div>
+   {% endif %}

The line containing endif has an extraneous space at the beginning of the line / has a different indentation than the matching if line.

EVIIILJ’s picture

Status: Needs work » Needs review
StatusFileSize
new1.77 KB

Thank you for the feedback. Attached is an updated patch which eliminates the extra space.

decafdennis’s picture

Thanks :)

podarok’s picture

+++ b/core/modules/image/image.field.incundefined
@@ -460,6 +460,25 @@ function theme_image_widget($variables) {
+    $element['filename']['#markup'] .= ' <span class="file-size">(' . format_size($element['#file']->filesize) . ')</span> ';

we do not need extra space before span here ' <span class="file-size">

+++ b/core/themes/stark/templates/image/image-widget.html.twigundefined
@@ -0,0 +1,26 @@
+#}
+<div{{ -attributes }}>

why minus ? -attributes
did I missing here something?

vlad.dancer’s picture

Status: Needs review » Needs work
+++ b/core/modules/image/image.field.inc
@@ -460,6 +460,25 @@ function theme_image_widget($variables) {
+function template_preprocess_image_widget(&$variables) {

replace template_preprocess to image_preprocess

+++ b/core/modules/image/image.field.inc
@@ -460,6 +460,25 @@ function theme_image_widget($variables) {
+  $attributes['class'] = array('image-widget', 'form-managed-file', 'clearfix');

Replace this to Attributes.
Example: http://drupal.org/files/1807166-textarea-twig-4.patch

+++ b/core/themes/stark/templates/image/image-widget.html.twig
@@ -0,0 +1,26 @@
+ * @file
+ * Returns HTML for an image field widget.
...
+ * @param array $variables

Need doc update.
Please, read this

+++ b/core/themes/stark/templates/image/image-widget.html.twig
@@ -0,0 +1,26 @@
+<div{{ -attributes }}>

Why did u used minus here, have i missed something too?

EVIIILJ’s picture

Status: Needs work » Needs review
StatusFileSize
new1.86 KB

[1] Not sure I'm following why we need to change template_preprocess to image_preprocess. Can you clarify?
[2] Attributes have been converted to using the Attribute Class.
[3] Updated docs.
[4] the minus was a typo in an attempt to use the white space control available to the Twig engine

A patch is included with the updated docs, use of Attribute class and fixing the white space control. Both the template and preprocess function are included.

vlad.dancer’s picture

Status: Needs review » Reviewed & tested by the community

@EVIIILJ
I've learned this post about template vs/ module/theme preprocess and agree with you about template_preprocess, but i've prefered module_preprocess for myself.

podarok’s picture

Status: Reviewed & tested by the community » Fixed

#9 thanks for pointing to docs about whitespace control
+1 RTBC

Thanks!

commited / pushed to front-end

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Project: » Lost & found issues

This issue’s project has disappeared. Most likely, it was a sandbox project, which can be deleted by its maintainer. See the Lost & found issues project page for more details. (The missing project ID was 1750250)