Problem/Motivation

#2311393: Remove hook_element_info() and all references to it replaced hook_element_info with plugins, but there's a todo left in the code

// @todo Once all elements are converted to plugins in
      //   https://www.drupal.org/node/2311393, rely on
      //   $element['#value_callback'] directly.

Proposed resolution

Remove dynamic value callback of form form_type_TYPE_value

Remaining tasks

Review

User interface changes

API changes

Data model changes

Release notes snippet

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

larowlan created an issue. See original summary.

larowlan’s picture

Status: Active » Needs review
FileSize
967 bytes
mstrelan’s picture

Patch does exactly as per the @todo that it removes, the blocker is fixed and the tests are passing. LGTM.

guilhermevp’s picture

Status: Needs review » Reviewed & tested by the community

I agree with @mstrelan, the blocker is done and so is the @todo, all are green there is nothing much left to say other than RTBC.

tim.plunkett’s picture

+++ b/core/lib/Drupal/Core/Form/FormBuilder.php
@@ -1221,10 +1221,7 @@ protected function handleInputElement($form_id, &$element, FormStateInterface &$
+      $value_callable = $element['#value_callback'] ?? NULL;
       if (!is_callable($value_callable)) {
         $value_callable = '\Drupal\Core\Render\Element\FormElement::valueCallback';
       }

My first instinct is that the FormElement::valueCallback should be used instead of NULL. But currently this code protects against someone setting a non-callable as the #value_callback, and while that should be happening, it's probably not worth removing the protection.

So unless someone else disagrees, I think this is a great change.

Eric_A’s picture

  1. What are the odds of someone having migrated from D7 to D8 with such procedural value callbacks still in place and working? (Without deprecation notice)
  2. There are some references to form_type_checkboxes_value() in other files. I'm not sure if those are being tackled elsewhere or not. And if fixing those is in scope here or not.
larowlan’s picture

Status: Reviewed & tested by the community » Needs review

There are some references to form_type_checkboxes_value() in other files. I'm not sure if those are being tackled elsewhere or not. And if fixing those is in scope here or not.

Yeah I think fix that here

What are the odds of someone having migrated from D7 to D8 with such procedural value callbacks still in place and working? (Without deprecation notice)

http://grep.xnddx.ru/search?text=form_type_TYPE_value&filename= yields no references to the hook name, but that's not really telling us much.

So perhaps we should be triggering a deprecation notice now, and then removing in D10?

@tim.plunkett thoughts?

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

tunic’s picture

There are some references to form_type_checkboxes_value() in other files. I'm not sure if those are being tackled elsewhere or not. And if fixing those is in scope here or not.

Currently, Drupal 9.4.1 ha only two references to form_type_checkboxes_value and they are inside comments:

Drupal\Core\Command\InstallCommand:

'enable_update_status_module' => TRUE,
// form_type_checkboxes_value() requires NULL instead of FALSE values   <---------
// for programmatic form submissions to disable a checkbox.
'enable_update_status_emails' => NULL,

Drupal\Core\Test\FunctionalTestSetupTrait:

// form_type_checkboxes_value() requires NULL instead of FALSE values   <---------
// for programmatic form submissions to disable a checkbox.
'enable_update_status_module' => NULL,
'enable_update_status_emails' => NULL,

So I guess that's not a concern anymore.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work

I think it would be nice to have a deprecation just in case someone has custom code. Better safe then sorry

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

alexpott’s picture

I don't think we need to do a deprecation dance here - see http://grep.xnddx.ru/search?text=function+form_type_&filename= all the calls here would be broken due to the core functions no longer existing.

We do need to update the document in \Drupal\Core\Form\FormBuilderInterface::doBuildForm() though as this says:

   * - $element['#value_callback']: A callable that implements how user input is
   *   mapped to an element's #value property. This defaults to a function named
   *   'form_type_TYPE_value' where TYPE is $element['#type'].
pradhumanjain2311’s picture

Status: Needs work » Needs review
FileSize
1.98 KB

Made changes as per comment #14.

FatherShawn’s picture

Thanks @larowan. I fixed this before I saw your comment in the course of working on #value_callback in #2966711: Limit what can be called by a callback in form arrays and did it just as you did in your patch. My only difference is the stated default. The logic of the code sets the default to \Drupal\Core\Render\Element\FormElement::valueCallback. I'll leave a comment on the other issue and perhaps we can close them together?

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Talking in slack wtih @FatherShawn and the two tickets do overlap but think we agreed this could probably land first (or has a better shot of it) while the larger task of #2966711: Limit what can be called by a callback in form arrays is worked on.

longwave’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/lib/Drupal/Core/Form/FormBuilderInterface.php
@@ -257,8 +257,7 @@ public function prepareForm($form_id, &$form, FormStateInterface &$form_state);
    * - $element['#value_callback']: A callable that implements how user input is
+   *   mapped to an element's #value property. This defaults to a function is NULL.

Not sure what this sentence is trying to say. I think we can just say something like:

    * - $element['#value_callback']: A optional callable that implements how user
    *   input is mapped to an element's #value property.
alexpott’s picture

Status: Needs work » Reviewed & tested by the community

Discussed with @longwave and the change from form_type_* functions to valueCallback is part of https://www.drupal.org/node/2320115 - a very old CR indeed!

Going fix the comment on commit (after discussing with @longwave).

alexpott’s picture

Version: 11.x-dev » 10.2.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed 5cbb5c9f46f to 11.x and 884929d80ba to 10.2.x. Thanks!

  • alexpott committed 382e811b on 10.2.x
    Issue #3221798 by larowlan, pradhumanjain2311, alexpott, tim.plunkett,...

  • alexpott committed 016718a8 on 11.x
    Issue #3221798 by larowlan, pradhumanjain2311, alexpott, tim.plunkett,...

Status: Fixed » Closed (fixed)

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