class PlaceholdersTest in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/Tests/Core/Render/RendererTestBase.php \Drupal\Tests\Core\Render\PlaceholdersTest
- 10 core/tests/Drupal/Tests/Core/Render/RendererTestBase.php \Drupal\Tests\Core\Render\PlaceholdersTest
Hierarchy
- class \Drupal\Tests\Core\Render\PlaceholdersTest implements TrustedCallbackInterface
Expanded class hierarchy of PlaceholdersTest
File
- core/
tests/ Drupal/ Tests/ Core/ Render/ RendererTestBase.php, line 261 - Contains \Drupal\Tests\Core\Render\RendererTestBase.
Namespace
Drupal\Tests\Core\RenderView source
class PlaceholdersTest implements TrustedCallbackInterface {
/**
* #lazy_builder callback; attaches setting, generates markup.
*
* @param string $animal
* An animal.
*
* @return array
* A renderable array.
*/
public static function callback($animal, $use_animal_as_array_key = FALSE) {
$value = $animal;
if ($use_animal_as_array_key) {
$value = [
$animal => TRUE,
];
}
return [
'#markup' => '<p>This is a rendered placeholder!</p>',
'#attached' => [
'drupalSettings' => [
'dynamic_animal' => $value,
],
],
];
}
/**
* #lazy_builder callback; attaches setting, generates markup, user-specific.
*
* @param string $animal
* An animal.
*
* @return array
* A renderable array.
*/
public static function callbackPerUser($animal) {
$build = static::callback($animal);
$build['#cache']['contexts'][] = 'user';
return $build;
}
/**
* #lazy_builder callback; attaches setting, generates markup, cache tag.
*
* @param string $animal
* An animal.
*
* @return array
* A renderable array.
*/
public static function callbackTagCurrentTemperature($animal) {
$build = static::callback($animal);
$build['#cache']['tags'][] = 'current-temperature';
return $build;
}
/**
* {@inheritdoc}
*/
public static function trustedCallbacks() {
return [
'callbackTagCurrentTemperature',
'callbackPerUser',
'callback',
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PlaceholdersTest:: |
public static | function | #lazy_builder callback; attaches setting, generates markup. | |
PlaceholdersTest:: |
public static | function | #lazy_builder callback; attaches setting, generates markup, user-specific. | |
PlaceholdersTest:: |
public static | function | #lazy_builder callback; attaches setting, generates markup, cache tag. | |
PlaceholdersTest:: |
public static | function |
Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface:: |
|
TrustedCallbackInterface:: |
constant | Untrusted callbacks throw exceptions. | ||
TrustedCallbackInterface:: |
constant | Untrusted callbacks trigger silenced E_USER_DEPRECATION errors. | ||
TrustedCallbackInterface:: |
constant | Untrusted callbacks trigger E_USER_WARNING errors. |