Split hooks into separate files, load with Finder
This commit is contained in:
parent
fafe64dac7
commit
c25eaf4ee1
|
@ -7,24 +7,12 @@
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
use Drupal\discoverable_entity_bundle_classes\Storage\Node\NodeStorage;
|
use Symfony\Component\Finder\Finder;
|
||||||
|
|
||||||
/**
|
$finder = Finder::create()
|
||||||
* Implements hook_entity_type_build().
|
->in(__DIR__ . DIRECTORY_SEPARATOR . 'hooks')
|
||||||
*/
|
->name('/.[php|inc]$/');
|
||||||
function custom_entity_type_build(array &$entityTypes): void {
|
|
||||||
/** @var \Drupal\Core\Entity\EntityTypeInterface[] $entityTypes */
|
|
||||||
if (isset($entityTypes['node'])) {
|
|
||||||
$entityTypes['node']->setStorageClass(NodeStorage::class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
foreach ($finder as $file) {
|
||||||
* Implements hook_preprocess_HOOK().
|
include $file->getPathname();
|
||||||
*/
|
|
||||||
function custom_preprocess_block(array &$variables): void {
|
|
||||||
// Add the 'markup' class to blocks.
|
|
||||||
if (in_array($variables['plugin_id'], ['views_block:featured_blog_posts-block_1'])) {
|
|
||||||
$variables['attributes']['class'][] = 'markup';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
20
web/modules/custom/custom/hooks/entity_type/build.inc
Normal file
20
web/modules/custom/custom/hooks/entity_type/build.inc
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Entity type build hooks.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Drupal\discoverable_entity_bundle_classes\Storage\Node\NodeStorage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_entity_type_build().
|
||||||
|
*/
|
||||||
|
function custom_entity_type_build(array &$entityTypes): void {
|
||||||
|
/** @var \Drupal\Core\Entity\EntityTypeInterface[] $entityTypes */
|
||||||
|
if (isset($entityTypes['node'])) {
|
||||||
|
$entityTypes['node']->setStorageClass(NodeStorage::class);
|
||||||
|
}
|
||||||
|
}
|
18
web/modules/custom/custom/hooks/preprocess/block.inc
Normal file
18
web/modules/custom/custom/hooks/preprocess/block.inc
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Block preprocess hooks.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_preprocess_HOOK().
|
||||||
|
*/
|
||||||
|
function custom_preprocess_block(array &$variables): void {
|
||||||
|
// Add the 'markup' class to blocks.
|
||||||
|
if (in_array($variables['plugin_id'], ['views_block:featured_blog_posts-block_1'])) {
|
||||||
|
$variables['attributes']['class'][] = 'markup';
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue