- Issue created by @eelkeblok
- Merge request !25Resolve #3412400: Try to apply Json::decode() to each value β (Open) created by eelkeblok
- Status changed to Needs review
12 months ago 7:50pm 4 January 2024 - π―π΄Jordan Rajab Natshah Jordan
Thanks, Eelke, for reporitng and the MR
Empty arrays, and empty Objects too like empty attrubutes
Maybe your fix will make sure not to have issues in call cases
after changes intwig/twig
Faced issues only with Sotrybook after updates for :
- Drupal 10.2.0
- cl_server 2.0.0-beta5
- @lullabot/storybook-drupal-addon 2.0.6
Response body: The website encountered an unexpected error. Try again later.<br><br><em class="placeholder">Twig\Error\RuntimeError</em>: The merge filter only works with arrays or "Traversable", got "string" for argument 2. in <em class="placeholder">twig_array_merge()</em>
the use of array_merge in Drupal is changing!!
Drupal 10 is using
"twig/twig": "^3.5.0",
twig/twig3.8.0
is out and in use for now
But3.9.0
will be out and it will have deprecations.https://github.com/twigphp/Twig/blob/v3.5.1/src/Extension/CoreExtension....
/** * Merges an array with another one. * * {% set items = { 'apple': 'fruit', 'orange': 'fruit' } %} * * {% set items = items|merge({ 'peugeot': 'car' }) %} * * {# items now contains { 'apple': 'fruit', 'orange': 'fruit', 'peugeot': 'car' } #} * * @param array|\Traversable $arr1 An array * @param array|\Traversable $arr2 An array * * @return array The merged array */ function twig_array_merge($arr1, $arr2) { if (!twig_test_iterable($arr1)) { throw new RuntimeError(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as first argument.', \gettype($arr1))); } if (!twig_test_iterable($arr2)) { throw new RuntimeError(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as second argument.', \gettype($arr2))); } return array_merge(twig_to_array($arr1), twig_to_array($arr2)); }
Storybook + CL Server having issues passing values and doing twig merge array
Move functions for CoreExtensionfabpot committed 3 weeks ago
https://github.com/twigphp/Twig/blob/v3.8.0/src/Extension/CoreExtension....
function twig_array_merge(...$arrays) { $result = []; foreach ($arrays as $argNumber => $array) { if (!is_iterable($array)) { throw new RuntimeError(sprintf('The merge filter only works with arrays or "Traversable", got "%s" for argument %d.', \gettype($array), $argNumber + 1)); } $result = array_merge($result, twig_to_array($array)); } return $result; }
π Fix Storybook issues with Drupal 10.2.0 after cl_server 2.0.0-beta5 and @lullabot/storybook-drupal-addon 2.0.6 Fixed
Testing changes with empty arrays, or empty objects - π³π±Netherlands eelkeblok Netherlands π³π±
My fix for complex values breaks true values for booleans, it appears. Will update to check for that specifically.
- π³π±Netherlands basvredeling Amsterdam
I took a similar approach and added this to the end of the ServerEndpointController::getArguments() method:
private function getArguments(Request $request): array { # ... # ... # ... if ($request->getMethod() === 'POST') { $params = $request->getContent(); $params = Json::decode($params); // Also decode any json encoded parameters. foreach ($params as $key => $value) { if (is_string($value) && $this->isJson($value)) { $params[$key] = Json::decode($value); } } return $params; } return []; } /** * Determine if given string is json. * * @param string $string * * @return bool * * @deprecated * Replace with json_validate() after PHP 8.3. */ private function isJson(string $string): bool { json_decode($string); return json_last_error() === JSON_ERROR_NONE; }
- Status changed to RTBC
10 months ago 7:03pm 12 February 2024 - π΅πͺPeru marvil07
@eelkeblok, thanks for reporting this problem, and also providing a solution for it! π
I got into the same problem, and the changes on the MR solved it!
BTW, both phpstan and phpcs reports that are not passing, are the same as the status on current
2.x
branch; in other words no new warnings around those checks has been introduced in this patch.Marking as RTBC.
- First commit to issue fork.
- Status changed to Needs review
10 months ago 3:55pm 22 February 2024 - πΊπΈUnited States agentrickard Georgia (US)
Pushed up code style changes after running phpstan / phpcbf etc.
- Status changed to RTBC
10 months ago 3:59pm 22 February 2024 - Status changed to Needs review
10 months ago 4:15pm 22 February 2024 - πΊπΈUnited States agentrickard Georgia (US)
Turns out that you cannot inject the extension list without throwing "Typed property Drupal\cl_server\Theme\ClServerThemeNegotiator::$extensionList must not be accessed before initialization"
- πΊπΈUnited States agentrickard Georgia (US)
Sorry. I am bouncing between two docroots to test this. I simply forgot to assign the propery value.
Fixed again, and required `drush cr`