butils-8.x-1.x-dev/butils.module
butils.module
<?php
/**
* @file
* Contains butils.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Entity\EntityInterface;
/**
* Implements hook_help().
*/
function butils_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the butils module.
case 'help.page.butils':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Backend utilities for Drupal 8') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_ENTITY_TYPE_insert().
*/
function butils_node_insert(EntityInterface $entity) {
return butils_handle_node_save($entity);
}
/**
* Implements hook_ENTITY_TYPE_update().
*/
function butils_node_update(EntityInterface $entity) {
return butils_handle_node_save($entity);
}
/**
* Node save hook handler.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* Node entity.
*
* @return \Drupal\Core\Entity\EntityInterface
* Node entity.
*/
function butils_handle_node_save(EntityInterface $entity) {
\Drupal::moduleHandler()->invokeAll('node_save', [$entity]);
return $entity;
}
/**
* Gets the current page main entity.
*
* @return \Drupal\Core\Entity\EntityInterface
* Current page main entity.
*/
function butils_page_entity() {
return \Drupal::service('butils')->currentEntity();
}
