Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ashutoshsngh’s picture

Removed all occurences of drupal_process_form().

ashutoshsngh’s picture

Status: Needs work » Needs review
tim.plunkett’s picture

Issue tags: -Novice. @deprecated +Novice, +@deprecated

Great! Can you also please remove the function?

er.pushpinderrana’s picture

Function also removed as mentioned in #3.

tim.plunkett’s picture

Status: Needs review » Postponed

This will conflict (only slightly) with the very large #2335659: Remove FormState ArrayAccess usage from core, so postponing for now. Otherwise this would be RTBC.

tim.plunkett’s picture

Status: Postponed » Needs work

The other issue went in, this can be rerolled.

ashutoshsngh’s picture

Status: Needs work » Needs review
FileSize
4.61 KB

Patch rerolled.

Status: Needs review » Needs work

The last submitted patch, 7: drupal8-remove-drupal_process_form-2335673-7.patch, failed testing.

Status: Needs work » Needs review
oenie’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Amsterdam2014

I think this missed the RTBC tag after the reroll.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/file/src/Controller/FileWidgetAjaxController.php
@@ -58,7 +58,7 @@ public function upload(Request $request) {
-    drupal_process_form($form['#form_id'], $form, $form_state);
+    \Drupal::formBuilder()->processForm($form['#form_id'], $form, $form_state);

+++ b/core/modules/system/src/Controller/FormAjaxController.php
@@ -64,7 +64,7 @@ public static function create(ContainerInterface $container) {
-    drupal_process_form($form['#form_id'], $form, $form_state);
+    \Drupal::formBuilder()->processForm($form['#form_id'], $form, $form_state);

We should inject the form builder into these two classes.

oenie’s picture

Status: Needs work » Needs review
FileSize
6.43 KB
3.43 KB

My first real take on dependency injection in D8. Try me :)

legolasbo’s picture

skipyT’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/system/src/Controller/FormAjaxController.php
    @@ -28,13 +29,24 @@ class FormAjaxController implements ContainerInjectionInterface {
    +    $this->formBuilder = $form_builder;
    

    I like this solution, injecting the formBuilder into the constructor, but in #2355179 we didn't do it for form_get_cache. we should be consequent I think

  2. +++ b/core/modules/system/src/Tests/Form/FormTest.php
    @@ -117,7 +117,7 @@ function testRequiredFields() {
    +          \Drupal::formBuilder()->processForm($form_id, $form, $form_state);
    

    we have 2 times the \Drupal::formBuilder called here, why we don't extract it into a variable?

oenie’s picture

So what you're saying is that:

1) I need to remove the injection again and that change needs to move to a new issue (as in #2355179)
2) Extract the formbuilder into a variable

I'm not really fond of retracing my steps, but i suppose splitting up the patch shouldn't be that difficult.
I suppose the new issue should wait till this one (once changed) goes in ...

tim.plunkett’s picture

Just because #2355179: Remove usage of form_get_cache() and form_set_cache() did it incorrectly doesn't mean this issue should. Please use injection.

#14.2 is just $form_builder = \Drupal::formBuilder(); above the first usage, and then $form_builder->processForm when its needed.

oenie’s picture

I'm noticing a bunch of \Drupal::formBuilder() statements in the /core/modules/system/src/Tests/Form/FormTest.php file, in different methods.

Are you suggesting, tim.plunkett, that all of these should be replaced by just a local variable ? Or did you only mean to do this when the variable is used multiple times in the same function ?

I'm assuming that in this case a class-wide formbuilder variable that is initialized in the setup method of the test would be the cleanest way to go. 5 extra lines just extracting into a local variable sounds like nonsense to me :)

Right ?

rudins’s picture

So, here is patch for latest D8 code version.

rudins’s picture

Status: Needs work » Needs review
oenie’s picture

Status: Needs review » Needs work

rudins, i appreciate the gesture but i was still waiting for some comment on the dependency injection.
You removed only part of it, yet as timplunkett mentioned in #16, dependency injection is to be preferred.
Also, i noticed a few unsused 'use' statements.

I'm uploading a new patch and interdiff in a minute

  1. +++ b/core/modules/file/src/Controller/FileWidgetAjaxController.php
    @@ -10,10 +10,12 @@
    +use Drupal\Core\Form\FormBuilderInterface;
    ...
    +use Symfony\Component\DependencyInjection\ContainerInterface;
    

    These use statements aren't needed, the dependency injection is happening in the parent class FormAjaxController.

  2. +++ b/core/modules/system/src/Controller/FormAjaxController.php
    @@ -71,7 +84,7 @@ public function content(Request $request) {
    -    drupal_process_form($form['#form_id'], $form, $form_state);
    

    As timplunkett mentioned in #16, dependency injection is preferred. You left in the added code for the form_builder to inject, but then removed the usage of the variable.

oenie’s picture

Status: Needs work » Needs review
FileSize
6.39 KB
2.97 KB

I've updated the patch, and patched some newly added \Drupal->formbuilder() call while i was at it.

After speaking to timplunkett, i'm moving the replacement of the other mentioned \Drupal::formbuilder() calls by a class-variable in the test classes to a new issue. I'll link it here (as it will be depending on this patch to go in first).

oenie’s picture

rpayanm’s picture

Status: Needs review » Reviewed & tested by the community

Look fine for me and no occurrence of drupal_process_form().

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/includes/form.inc
@@ -54,18 +54,6 @@ function drupal_form_submit($form_arg, FormStateInterface $form_state) {
 /**
- * Processes a form submission.
- *
- * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
- *   Use \Drupal::formBuilder()->processForm().
- *
- * @see \Drupal\Core\Form\FormBuilderInterface::processForm().
- */
-function drupal_process_form($form_id, &$form, FormStateInterface $form_state) {
-  \Drupal::formBuilder()->processForm($form_id, $form, $form_state);
-}

Plus don't remove the function in the same issue that removes all the usages.

Also can we attach the correct CR to this issue.

ashutoshsngh’s picture

Status: Needs work » Needs review
FileSize
5.62 KB

Patch rerolled

ashutoshsngh’s picture

Patch rerolled

ianthomas_uk’s picture

Status: Needs review » Reviewed & tested by the community

#25 has been addressed, patch is otherwise unchanged.

rpayanm’s picture

@ashutoshsngh interdiff please.
CR referenced.

ashutoshsngh’s picture

FileSize
789 bytes

Interdiff attached.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This issue is a prioritized change (removing deprecated code usage) as per https://www.drupal.org/core/beta-changes and it's benefits outweigh any disruption. Committed 2ec3fbc and pushed to 8.0.x. Thanks!

  • alexpott committed 2ec3fbc on 8.0.x
    Issue #2335673 by ashutoshsngh, oenie, rudins, er.pushpinderrana: Remove...

Status: Fixed » Closed (fixed)

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