Problem/Motivation

Deprecate drupal_process_states() as part of #2999721: [META] Deprecate the legacy include files before Drupal 9.

Proposed resolution

Add a new public static method \Drupal\Core\Form\FormHelper::processStates().

Remaining tasks

None.

User interface changes

None.

API changes

  1. New method ::processStates() in class \Drupal\Core\Form\FormHelper.
  2. drupal_process_states() is deprecated.

Data model changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

claudiu.cristea created an issue. See original summary.

claudiu.cristea’s picture

Issue summary: View changes
FileSize
10.03 KB

Patch.

claudiu.cristea’s picture

Status: Active » Needs review
claudiu.cristea’s picture

FileSize
9.99 KB
545 bytes

Forgot a wrong use statement.

The last submitted patch, 2: 3000068-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

andypost’s picture

+++ b/core/lib/Drupal/Core/Render/Renderer.php
@@ -401,7 +402,7 @@ protected function doRender(&$elements, $is_root_call = FALSE) {
     if (!empty($elements['#states'])) {
-      drupal_process_states($elements);
+      FormHelper::processStates($elements);

As it more about any elements then maybe better to move it to \Drupal\Core\Render\Element?

andypost’s picture

Reroll + added tests

andypost’s picture

FileSize
1020 bytes
13.22 KB

Function does not return value, fixed test

claudiu.cristea’s picture

+++ b/core/includes/common.inc
@@ -583,7 +583,7 @@ function drupal_js_defaults($data = NULL) {
-  @trigger_error('drupal_process_states() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Form\FormHelper::processStates() instead. See https://www.drupal.org/node/3000069.', E_USER_DEPRECATED);
+  @trigger_error('drupal_process_states() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Form\FormHelper::processStates() instead. See https://www.drupal.org/node/3000069', E_USER_DEPRECATED);

Why was removed the end dot? I see that the official deprecation policy still adds a dot at the end https://www.drupal.org/core/deprecation:

@trigger_error('baz() is deprecated in Drupal 8.3.0 and will be removed before Drupal 9.0.0. Use \Drupal\Foo\Bar::baz() instead. See http://drupal.org/node/the-change-notice-nid.', E_USER_DEPRECATED);
andypost’s picture

Yes, that raised in drupal attributes and we need separate issue to make it consistent and another issue to fix coding standards

Btw my test is wrong because it passed in #7

andypost’s picture

Mile23’s picture

The period at the end of deprecation messages is inconsistent throughout core. It's an accident of English that incorrect but valid URL elements are also grammatically correct.

It's fine either way, until there's a coder rule for it, though I like it without the period.

  1. +++ b/core/lib/Drupal/Core/Form/FormHelper.php
    @@ -67,4 +68,135 @@ protected static function processStatesArray(array &$conditions, $search, $repla
    +   * A "state" means a certain property on a DOM element, such as "visible" or
    +   * "checked". A state can be applied to an element, depending on the state of
    

    +1 on more docs.

  2. +++ b/core/lib/Drupal/Core/Form/FormHelper.php
    @@ -67,4 +68,135 @@ protected static function processStatesArray(array &$conditions, $search, $repla
    +  public static function processStates(array &$elements) {
    

    When this is in, FormHelper will have three methods: processStates(), rewriteStatesSelector(), and processStatesArray().

    processStatesArray() is protected so we get a clue as to how (not to) use it, but it's still not very clear how it's different from processStates(array $array). Especially with this remarkably unhelpful summary line: "Helper function for self::rewriteStatesSelector()."

    rewriteStatesSelector() could have a more descriptive docblock, too.

    This is mostly a nit, tho if I encountered this helper without knowing it's history I'd be confused. Maybe this nit is out of scope here.

voleger’s picture

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Mile23’s picture

Status: Needs review » Needs work

NW based on #12.

pingwin4eg’s picture

Assigned: Unassigned » pingwin4eg
Issue tags: +dckyiv2019
pingwin4eg’s picture

Assigned: pingwin4eg » Unassigned
Status: Needs work » Needs review
FileSize
14.75 KB
2.77 KB

Updated doc blocks to be more clear. I did my best)

voleger’s picture

Status: Needs review » Needs work
  1. +++ b/core/includes/common.inc
    @@ -589,16 +589,14 @@ function drupal_js_defaults($data = NULL) {
    + * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use
    ...
    +  @trigger_error('drupal_process_states() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Form\FormHelper::processStates() instead. See https://www.drupal.org/node/3000069', E_USER_DEPRECATED);
    

    CS issue, needs to be fixed.
    Also version need to be updated 8.7.0 => 8.8.0.

  2. +++ b/core/tests/Drupal/KernelTests/Core/Render/RendererLegacyTest.php
    @@ -37,4 +38,47 @@ public function providerAttributes() {
    +   * @expectedDeprecation drupal_process_states() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Form\FormHelper::processStates() instead. See https://www.drupal.org/node/3000069
    

    Same here

andypost’s picture

Status: Needs work » Needs review
FileSize
3.17 KB
14.85 KB

Re-roll & fix CS

Status: Needs review » Needs work

The last submitted patch, 19: 3000068-19.patch, failed testing. View results

johnwebdev’s picture

Seems to be a unrelated test fail. RTBC once ✅

Also updated change record.

johnwebdev’s picture

Status: Needs work » Reviewed & tested by the community

  • catch committed 2a5c62d on 8.8.x
    Issue #3000068 by andypost, claudiu.cristea, pingwin4eg, Mile23, voleger...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed 2a5c62d and pushed to 8.8.x. Thanks!

Status: Fixed » Closed (fixed)

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