function TestDisplayVariant::build
Same name in other branches
- 9 core/modules/system/tests/modules/display_variant_test/src/Plugin/DisplayVariant/TestDisplayVariant.php \Drupal\display_variant_test\Plugin\DisplayVariant\TestDisplayVariant::build()
- 8.9.x core/modules/system/tests/modules/display_variant_test/src/Plugin/DisplayVariant/TestDisplayVariant.php \Drupal\display_variant_test\Plugin\DisplayVariant\TestDisplayVariant::build()
- 11.x core/modules/system/tests/modules/display_variant_test/src/Plugin/DisplayVariant/TestDisplayVariant.php \Drupal\display_variant_test\Plugin\DisplayVariant\TestDisplayVariant::build()
Overrides VariantInterface::build
File
-
core/
modules/ system/ tests/ modules/ display_variant_test/ src/ Plugin/ DisplayVariant/ TestDisplayVariant.php, line 88
Class
- TestDisplayVariant
- Provides a display variant that requires configuration.
Namespace
Drupal\display_variant_test\Plugin\DisplayVariantCode
public function build() {
$config = $this->getConfiguration();
if (empty($config['required_configuration'])) {
throw new \Exception('Required configuration is missing!');
}
$contexts = $this->getContexts();
if (!isset($contexts['context'])) {
throw new \Exception('Required context is missing!');
}
$build = [];
$build['content']['default'] = [
'#markup' => $config['required_configuration'] . ' ' . $contexts['context']->getContextValue(),
];
CacheableMetadata::createFromObject($this)->applyTo($build);
return $build;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.