sir_trevor-8.x-1.x-dev/sir_trevor.module
sir_trevor.module
<?php
use Drupal\sir_trevor\Plugin\SirTrevorBlockPlugin;
use Drupal\sir_trevor\Plugin\SirTrevorPlugin;
use Drupal\sir_trevor\Plugin\SirTrevorPluginManagerInterface;
/**
* Implements hook_theme().
*/
function sir_trevor_theme($existing, $type, $theme, $path) {
/** @var SirTrevorPluginManagerInterface $blockManager */
$blockManager = \Drupal::service('plugin.manager.sir_trevor');
$themes = [];
/** @var SirTrevorPlugin $plugin */
foreach ($blockManager->createInstances() as $plugin) {
if ($plugin instanceof SirTrevorBlockPlugin) {
$themes["sir_trevor_{$plugin->getMachineName()}"] = [
'variables' => [
'data' => [],
'entity' => NULL,
],
'path' => drupal_get_path('module', $plugin->getDefiningModule()),
'template' => $plugin->getTemplate(),
];
}
}
return $themes;
}
/**
* Implements hook_library_info_alter() to register libraries on behalf of
* modules implementing Sir Trevor blocks. This way modules can define their
* plugins in a single location instead of having to define the plugin in one
* place and it's assets in another.
*/
function sir_trevor_library_info_alter(&$libraries, $extension) {
$libraryBuilder = \Drupal::service('sir_trevor.libraries.info.builder');
/** @var \Drupal\sir_trevor\LibraryInfoBuilder $libraryBuilder */
$libraryInfo = $libraryBuilder->getLibraryInfo();
if (!empty($libraryInfo[$extension])) {
foreach ($libraryInfo[$extension] as $name => $library) {
$libraries[$name] = $library;
}
}
}
