public function TestCachingField::build in Display Suite 8.4
Same name and namespace in other branches
- 8.3 tests/modules/ds_test/src/Plugin/DsField/TestCachingField.php \Drupal\ds_test\Plugin\DsField\TestCachingField::build()
Renders a field.
Return value
array A renderable array representing the content of the field.
Overrides DsFieldBase::build
File
- tests/
modules/ ds_test/ src/ Plugin/ DsField/ TestCachingField.php, line 22
Class
- TestCachingField
- Test caching field plugin.
Namespace
Drupal\ds_test\Plugin\DsFieldCode
public function build() {
$build = [];
$cache = CacheableMetadata::createFromRenderArray($build);
$cache
->addCacheTags([
'ds_my_custom_tags',
])
->applyTo($build);
if (\Drupal::state()
->get('ds_test_show_field', FALSE)) {
$build['#markup'] = 'DsField Shown';
return $build;
}
// Returning the cache object when we only have cache data allows our field
// to appear when the node changes status.
return $cache;
}