homebox.module in Homebox 8
Same filename and directory in other branches
Homebox module hooks.
File
homebox.moduleView source
<?php
/**
* @file
* Homebox module hooks.
*/
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function homebox_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the homebox module.
case 'help.page.homebox':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Port Homebox to Drupal 8') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_theme().
*/
function homebox_theme() {
return [
'homebox' => [
'render element' => 'children',
],
'homebox_block' => [
'template' => 'homebox-block',
'variables' => [
'close_link' => NULL,
'block_id' => NULL,
'block_content' => NULL,
'block_title' => NULL,
'page' => NULL,
],
],
];
}
/**
* Implements hook_ENTITY_TYPE_insert().
*/
function homebox_homebox_insert(EntityInterface $entity) {
// @todo Check for existing aliases with the same alias name.
/* @var \Drupal\homebox\Entity\HomeboxInterface $entity */
\Drupal::service('path.alias_storage')
->save('/homebox-page/' . $entity
->id() . '/' . \Drupal::currentUser()
->id(), '/' . $entity
->getPath(), "en");
}
/**
* Implements hook_local_tasks_alter().
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
function homebox_local_tasks_alter(&$local_tasks) {
// Add route to display on the user profile page.
$homebox_storage = \Drupal::entityTypeManager()
->getStorage('homebox');
$homeboxes = $homebox_storage
->loadMultiple();
/* @var \Drupal\homebox\Entity\HomeboxInterface $homebox */
foreach ($homeboxes as $homebox) {
if ($homebox
->getOptions()['menu']) {
$local_tasks['homebox.user_profile.layout.' . $homebox
->id()] = [
'id' => 'homebox.user_profile.layout.' . $homebox
->id(),
'title' => $homebox
->label(),
'route_name' => 'homebox.page',
'base_route' => 'entity.user.canonical',
'weight' => -100,
'route_parameters' => [
'homebox' => $homebox
->id(),
],
'class' => '\\Drupal\\Core\\Menu\\LocalTaskDefault',
'provider' => 'homebox',
'options' => [],
];
}
}
}
Functions
Name | Description |
---|---|
homebox_help | Implements hook_help(). |
homebox_homebox_insert | Implements hook_ENTITY_TYPE_insert(). |
homebox_local_tasks_alter | Implements hook_local_tasks_alter(). |
homebox_theme | Implements hook_theme(). |