Add a normalize method to prop sources

Created on 19 December 2024, 4 months ago

Overview

In ClientServerConversionTrait we're currently doing this

$props_prepared_for_saving = [];
    foreach ($props as $component_instance_uuid => $component_instance_props) {
      foreach ($component_instance_props as $prop_name => $prop_source) {
        $props_prepared_for_saving[$component_instance_uuid][$prop_name] = json_decode((string) $prop_source, TRUE);
      }
    }

This relies on the `__toString` method of propsources which transforms the value into JSON and then we immediately `json_decode` it.

Proposed resolution

Add a normalize method to each of the prop source classes and use that instead of casting to and from JSON to get an array representation

User interface changes

📌 Task
Status

Active

Version

0.0

Component

Data model

Created by

🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @larowlan
  • 🇮🇳India Akhil Babu Chengannur
  • 🇮🇳India Akhil Babu Chengannur

    As suggested by @larowan, I have added a new method toArray() to the prop source classes

  • Pipeline finished with Success
    4 months ago
    Total: 767s
    #382524
  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    This looks good to me, thanks @akhil babu

  • First commit to issue fork.
  • 🇬🇧United Kingdom longwave UK

    Made some improvements:

    • toArray() is abstract on the base class (we don't have an interface)
    • __toString() is moved to the base class to avoid repetition
    • Also added JSON_THROW_ON_ERROR to appease PHPStan
  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    Nice improvement 🙌 - merge on green, re-ran the failing e2e 🤞

  • 🇺🇸United States tedbow Ithaca, NY, USA

    Looks good, I can't merge it until @wim leers or @f.mazeikis approves the merge request

  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Title did not match actual MR.

    Also: +1, this is long overdue!

  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Can't run phpstan locally while testing what I'm doing, due to:

    $ php vendor/bin/phpstan analyze modules/contrib/experience_builder --memory-limit=256M --configuration=modules/contrib/experience_builder/phpstan.neon  -vvv
    Invalid entries in excludePaths:
    Path /Users/wim.leers/core/modules/contrib/experience_builder/modules/same_page_preview is neither a directory, nor a file path, nor a fnmatch pattern.
    
    Path /Users/wim.leers/core/modules/contrib/experience_builder/tests/src/Cypress/node_modules is neither a directory, nor a file path, nor a fnmatch pattern.
    
    If the excluded path can sometimes exist, append (?)
    to its config entry to mark it as optional.
    

    Fix: remove the first one, because it's obsolete. Make the second one optional.

    This must be the new PHPStan version that Drupal 11.x HEAD is installing — CI is pinning to 11.1.x since that is the current minor, and hence it's not spotting this problem. Doing that here is a distraction, so opened 📌 CI: also test against next minor: 11.2.x aka Drupal 11.x HEAD Active to do that.

  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Fortunately, the PHPStan shape work was already done — I'd forgotten about that!

    I did also find one more place where we can use the new method 🥳

  • Pipeline finished with Skipped
    3 months ago
    #388514
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    @wim w.r.t phpstan locally, I've got a `phpstan.larowlan.neon` and inside it I have

    includes:
    	- phpstan.neon
    parameters:
        scanDirectories:
          - ../metatag
        excludePaths:
          - tests/src/Cypress/node_modules/flatted/php/flatted.php
    

    I've added this to .git/info/exclude so it doesn't get checked in.

    In my pre-commit hooks I've got this (the ../../../bin/phpstan is the path in my setup to the phpstan binary)

    ../../../bin/phpstan analyse -c ./phpstan.larowlan.neon .
    

    This lets me tweak the phpstan setup without impacting the checked in version.

    I've got similar things for phpcs and cspell too, also in my pre-commit

    Happy to share if they're useful

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

Production build 0.71.5 2024