Skip to content
Snippets Groups Projects
Verified Commit e55cf5ca authored by Dave Long's avatar Dave Long
Browse files

Issue #3352944 by Spokje: Fix PHPStan L1 errors "#pre_render/#lazy_builder...

Issue #3352944 by Spokje: Fix PHPStan L1 errors "#pre_render/#lazy_builder callback '\Foo\Bar' at key 'n' is not trusted."
parent cc5e3477
Branches
Tags
26 merge requests!54479.5.x SF update,!5014Issue #3071143: Table Render Array Example Is Incorrect,!4868Issue #1428520: Improve menu parent link selection,!4289Issue #1344552 by marcingy, Niklas Fiekas, Ravi.J, aleevas, Eduardo Morales...,!4114Issue #2707291: Disable body-level scrolling when a dialog is open as a modal,!4100Issue #3249600: Add support for PHP 8.1 Enums as allowed values for list_* data types,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1591Issue #3199697: Add JSON:API Translation experimental module,!1484Exposed filters get values from URL when Ajax is on,!1255Issue #3238922: Refactor (if feasible) uses of the jQuery serialize function to use vanillaJS,!1162Issue #3100350: Unable to save '/' root path alias,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!925Issue #2339235: Remove taxonomy hard dependency on node module,!877Issue #2708101: Default value for link text is not saved,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links,!844Resolve #3036010 "Updaters",!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!485Sets the autocomplete attribute for username/password input field on login form.,!30Issue #3182188: Updates composer usage to point at ./vendor/bin/composer
...@@ -5,13 +5,15 @@ ...@@ -5,13 +5,15 @@
* Element info test. * Element info test.
*/ */
use Drupal\element_info_test\ElementInfoTestNumberBuilder;
/** /**
* Implements hook_element_info_alter(). * Implements hook_element_info_alter().
*/ */
function element_info_test_element_info_alter(array &$info) { function element_info_test_element_info_alter(array &$info) {
$info['number'] += ['#pre_render' => []]; $info['number'] += ['#pre_render' => []];
/* @see \Drupal\KernelTests\Core\Render\Element\WeightTest::testProcessWeightSelectMax() */ /* @see \Drupal\KernelTests\Core\Render\Element\WeightTest::testProcessWeightSelectMax() */
$info['number']['#pre_render'][] = 'element_info_test_element_pre_render'; $info['number']['#pre_render'][] = [ElementInfoTestNumberBuilder::class, 'preRender'];
} }
/** /**
...@@ -22,12 +24,3 @@ function element_info_test_element_plugin_alter(array &$definitions) { ...@@ -22,12 +24,3 @@ function element_info_test_element_plugin_alter(array &$definitions) {
unset($definitions['weight']); unset($definitions['weight']);
} }
} }
/**
* {@inheritdoc}
*
* @see \Drupal\KernelTests\Core\Render\Element\WeightTest::testProcessWeightSelectMax()
*/
function element_info_test_element_pre_render(array $element) {
return $element;
}
<?php
namespace Drupal\element_info_test;
use Drupal\Core\Security\TrustedCallbackInterface;
/**
* Provides a trusted callback to alter the element_info_test number element.
*
* @see element_info_test_element_info_alter()
*/
class ElementInfoTestNumberBuilder implements TrustedCallbackInterface {
/**
* {@inheritdoc}
*/
public static function trustedCallbacks() {
return ['preRender'];
}
/**
* Sets element_info_test - #pre_render callback.
*/
public static function preRender(array $element): array {
return $element;
}
}
...@@ -3380,11 +3380,6 @@ parameters: ...@@ -3380,11 +3380,6 @@ parameters:
count: 1 count: 1
path: tests/Drupal/KernelTests/Core/KeyValueStore/GarbageCollectionTest.php path: tests/Drupal/KernelTests/Core/KeyValueStore/GarbageCollectionTest.php
-
message: "#^\\#pre_render callback 'element_info_test…' at key '1' is not trusted\\.$#"
count: 1
path: tests/Drupal/KernelTests/Core/Render/Element/WeightTest.php
- -
message: "#^@covers value drupal_rewrite_settings\\(\\) references an invalid class or function\\.$#" message: "#^@covers value drupal_rewrite_settings\\(\\) references an invalid class or function\\.$#"
count: 1 count: 1
...@@ -3830,16 +3825,6 @@ parameters: ...@@ -3830,16 +3825,6 @@ parameters:
count: 1 count: 1
path: tests/Drupal/Tests/Core/Plugin/TestPluginManager.php path: tests/Drupal/Tests/Core/Plugin/TestPluginManager.php
-
message: "#^\\#lazy_builder callback '\\\\\\\\Drupal\\\\\\\\Tests\\\\\\\\Core…' at key '0' is not trusted\\.$#"
count: 1
path: tests/Drupal/Tests/Core/Render/RendererCallbackTest.php
-
message: "#^\\#pre_render callback '\\\\\\\\Drupal\\\\\\\\Tests\\\\\\\\Core…' at key '0' is not trusted\\.$#"
count: 1
path: tests/Drupal/Tests/Core/Render/RendererCallbackTest.php
- -
message: "#^Missing call to parent\\:\\:setUp\\(\\) method\\.$#" message: "#^Missing call to parent\\:\\:setUp\\(\\) method\\.$#"
count: 1 count: 1
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
use Drupal\Core\Render\Element\Number; use Drupal\Core\Render\Element\Number;
use Drupal\Core\Render\Element\Select; use Drupal\Core\Render\Element\Select;
use Drupal\Core\Render\Element\Weight; use Drupal\Core\Render\Element\Weight;
use Drupal\element_info_test\ElementInfoTestNumberBuilder;
use Drupal\KernelTests\KernelTestBase; use Drupal\KernelTests\KernelTestBase;
/** /**
...@@ -117,8 +118,8 @@ public function testProcessWeightSelectMax() { ...@@ -117,8 +118,8 @@ public function testProcessWeightSelectMax() {
'#pre_render' => [ '#pre_render' => [
[Number::class, 'preRenderNumber'], [Number::class, 'preRenderNumber'],
// The custom callback is appended. // The custom callback is appended.
/* @see element_info_test_element_info_alter() */ /* @see \Drupal\element_info_test\ElementInfoTestNumberBuilder::preRender */
'element_info_test_element_pre_render', [ElementInfoTestNumberBuilder::class, 'preRender'],
], ],
]); ]);
} }
......
...@@ -42,6 +42,9 @@ public function testCallback(array $render_array, $expected_deprecation) { ...@@ -42,6 +42,9 @@ public function testCallback(array $render_array, $expected_deprecation) {
public function providerTestCallback() { public function providerTestCallback() {
return [ return [
'Procedural function pre render' => [ 'Procedural function pre render' => [
// We specifically test an untrusted callback here. We need to let
// PHPStan ignore it.
// @phpstan-ignore-next-line
['#pre_render' => ['\Drupal\Tests\Core\Render\callback'], '#type' => 'container'], ['#pre_render' => ['\Drupal\Tests\Core\Render\callback'], '#type' => 'container'],
'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was \Drupal\Tests\Core\Render\callback. See https://www.drupal.org/node/2966725', 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was \Drupal\Tests\Core\Render\callback. See https://www.drupal.org/node/2966725',
], ],
...@@ -60,6 +63,9 @@ public function providerTestCallback() { ...@@ -60,6 +63,9 @@ public function providerTestCallback() {
'Render #access_callback callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was Drupal\Tests\Core\Render\RendererCallbackTest::renderCallback. See https://www.drupal.org/node/2966725', 'Render #access_callback callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was Drupal\Tests\Core\Render\RendererCallbackTest::renderCallback. See https://www.drupal.org/node/2966725',
], ],
'Procedural function lazy builder' => [ 'Procedural function lazy builder' => [
// We specifically test an untrusted callback here. We need to let
// PHPStan ignore it.
// @phpstan-ignore-next-line
['#lazy_builder' => ['\Drupal\Tests\Core\Render\callback', []]], ['#lazy_builder' => ['\Drupal\Tests\Core\Render\callback', []]],
'Render #lazy_builder callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was \Drupal\Tests\Core\Render\callback. See https://www.drupal.org/node/2966725', 'Render #lazy_builder callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was \Drupal\Tests\Core\Render\callback. See https://www.drupal.org/node/2966725',
], ],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment