in file.field.inc:
file_field_widget_value()
file_field_widget_multiple_count_validate()
file_field_widget_process()
file_field_widget_process_multiple()
_file_field_get_description_from_element()
file_field_widget_submit()

in image.field.inc:
image_field_widget_process()
_image_field_required_fields_validate()

It seems those should move to the FileWidget / ImageWidget classes ?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

yched’s picture

Title: FAPI callbacks for file widgets should move in the widget class » FAPI callbacks for file/image widgets should move in the widget classes

same in image.field.inc, actually - updated the OP

yched’s picture

Note: those functions were probably left out during the patches that converted the widgets to classes several months ago because FAPI / render API didn't support "callbacks as methods" for all callbacks (process, pre_render...).
I'm not 100% sure where we stand right now on this regard, would need to be double checked for each callback type involved here.

claudiu.cristea’s picture

Assigned: Unassigned » claudiu.cristea

Let me try :)

claudiu.cristea’s picture

Title: FAPI callbacks for file/image widgets should move in the widget classes » Move FAPI callbacks for file/image widgets in classes
Status: Active » Needs work
claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
36.52 KB

Voilà!

Status: Needs review » Needs work

The last submitted patch, file-widget-callbacks-2072995-5.patch, failed testing.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
2.71 KB
37.74 KB

To be honest, even now I'm not sure how to pass by reference with call_user_func_array() in 5.3 compared to 5.4. This works on PHP 5.4, let's see the bot.

claudiu.cristea’s picture

+++ b/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php
@@ -258,4 +259,265 @@ public function massageFormValues(array $values, array $form, array &$form_state
+    // If there are more files uploaded via the same widget, we have to separate
+    // them, as we display each file in it's own widget.
+    $new_values = array();
+    foreach ($submitted_values as $delta => $submitted_value) {
+      if (is_array($submitted_value['fids'])) {
+        foreach ($submitted_value['fids'] as $fid) {
+          $new_value = $submitted_value;
+          $new_value['fids'] = array($fid);
+          $new_values[] = $new_value;
+        }
+      }
+      else {
+        $new_value = $submitted_value;
+      }
+    }
+

I just copied this piece of code from the legacy callback but looking a little bit inside it doesn't look good to me. Isn't this wrong? I mean the "else" part $new_value = $submitted_value;? It seems that we drop out the submitted value when $submitted_value['fids'] is not an array?

claudiu.cristea’s picture

Issue summary: View changes

image

claudiu.cristea’s picture

Status: Needs review » Needs work

The last submitted patch, 7: file-widget-callbacks-2072995-7.patch, failed testing.

claudiu.cristea’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
37.65 KB

Reworked the patch. The interdiff is not relevant as the patch was seriously outdated. @yched please check also the comment from #8.

yched’s picture

Would love if someone could help review that one ;-)

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

Looks fine to me.

LinL’s picture

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 11: file-widget-callbacks-2072995-11.patch, failed testing.

yched’s picture

Anyone up for a reroll ?

If the patch doesn't apply anymore, it probably means that some changes have been committed inside the old functions meanwhile, so the reroll will need to make sure that those changes are correclty reported in the new methods...

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
37.8 KB

rerolled

yched’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @claudiu.cristea !

xjm’s picture

xjm’s picture

Issue tags: +RTBC 4+ weeks

This patch has been in the reroll-and-RTBC cycle for more than four weeks, so tagging accordingly.

yched’s picture

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 17: file-widget-callbacks-2072995-17.patch, failed testing.

xjm’s picture

Issue tags: -RTBC 4+ weeks +RTBC 4 weeks, +Needs reroll
xjm’s picture

Issue tags: -RTBC 4 weeks +RTBC over 4 weeks

d.o doesn't like the + apparently.

yched’s picture

Anyone up for reroll ? :-)

longwave’s picture

Status: Needs work » Needs review

No reroll needed that I can see, testbot ran out of disk space on the last run.

17: file-widget-callbacks-2072995-17.patch queued for re-testing.

claudiu.cristea’s picture

Needs re-RTBC, @yched?

yched’s picture

Status: Needs review » Reviewed & tested by the community

Oh, sorry. Damn random fails :-/

webchick’s picture

Title: Move FAPI callbacks for file/image widgets in classes » Change notice: Move FAPI callbacks for file/image widgets in classes
Priority: Normal » Major
Status: Reviewed & tested by the community » Active
Issue tags: +Needs change record

Committed and pushed to 8.x.

We'll need a change notice for this.

j4’s picture

Status: Active » Needs review

Change Record created.

yched’s picture

@j4: thanks for this !

A couple remarks:

- The change notice should reference this issue (there's an "Issues" reference field to fill in (you have to paste the current title of the issue for the autocomplete to work)

- The text should include the names of the functions that were moved around, so that the change records shows up when people search for a function name at https://drupal.org/list-changes/drupal when their code breaks with "fatal, undefined function foobar()"

- It should also outline how to fix the broken code. In this case, a simple map of "old function() -> new class::method()" would be enough.
See https://drupal.org/node/2064123 for an example of table formatting.

j4’s picture

Hi yched,

Thank you for the mentoring! Am not a very technical person, but wanted to pitch in...:)

Have added the issue to the change record (was having an issue with the auto-complete, the auto-complete text appears at the top of the screen and not below the field).

Will try and understand the other two recommendations and make the corrections as soon as I get the hang of it.

Jaya

xjm’s picture

Issue tags: -Needs reroll, -RTBC over 4 weeks +Missing change record

Tagging "Missing change record", as completing the change record updates here blocks a beta: #2083415: [META] Write up all outstanding change notices before release

xjm’s picture

Status: Needs review » Needs work

Marking "Needs work" to incorporate @yched's feedback in the change record.

webchick’s picture

Change record is there, just needs a bit more tweaking.

swentel’s picture

Mm, fileWidget contains an unused variable on line 519 ($new_value).
Also, if you set images to multiple (or at least unlimited in our testing), it somehow forgets it's multiple and the widget printing looks bad.
Coming from #2172241: Files and image widgets completely broken which plopsec was investigating the file validation there, but also stumbled on the fact that valid images/files are now bad too when being multiple. Note that we're not sure yet if this issue caused that second regression.

mgifford’s picture

Assigned: claudiu.cristea » Unassigned

Just unassigning issues that haven't been developed for a bit in the D8 queue.

claudiu.cristea’s picture

Title: Change notice: Move FAPI callbacks for file/image widgets in classes » Move FAPI callbacks for file/image widgets in classes
Status: Needs work » Reviewed & tested by the community

Updated the change notice. Back to RTBC for closing.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 17: file-widget-callbacks-2072995-17.patch, failed testing.

claudiu.cristea’s picture

Status: Needs work » Fixed

I think "Fixed" is better :)

Status: Fixed » Closed (fixed)

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