preprocessors-8.x-1.0-beta8/modules/preprocessors_example/src/Plugin/preprocessors/NodeBundlePreprocessor.php
modules/preprocessors_example/src/Plugin/preprocessors/NodeBundlePreprocessor.php
<?php
namespace Drupal\preprocessors_example\Plugin\preprocessors;
use Drupal\preprocessors\Attribute\Preprocessor;
use Drupal\preprocessors\PreprocessorPluginBase;
/**
* Provide plugin to preprocess variables for nodes of a given bundle.
*/
#[Preprocessor(
id: 'preprocessors_example.preprocessor.node_bundle',
hooks: [
"node__bundle"
],
themes: "*",
weight: 0
)]
final class NodeBundlePreprocessor extends PreprocessorPluginBase {
/**
* Preprocess your variables.
*
* This method works just like a 'hook_preprocess_HOOK()' function.
*
* {@inheritdoc}
*/
public function preprocess(array &$variables, string $hook, array $info) : void {
$variables['foo'] = "bar";
}
}
