You are here

build_hooks.module in Build Hooks 8

Same filename and directory in other branches
  1. 8.2 build_hooks.module
  2. 3.x build_hooks.module

Contains build_hooks.module.

File

build_hooks.module
View source
<?php

/**
 * @file
 * Contains build_hooks.module.
 */
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Url;

/**
 * Implements hook_help().
 */
function build_hooks_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {

    // Main module help for the build_hooks module.
    case 'help.page.build_hooks':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('build hooks') . '</p>';
      return $output;
    default:
  }
}

/**
 * Implement hook_cron
 */
function build_hooks_cron() {
  getTriggerService()
    ->executeCron();
}

/**
 * Implements hook_entity_update().
 */
function build_hooks_entity_update(EntityInterface $entity) {
  getTriggerService()
    ->executeNode($entity
    ->getType());
}

/**
 * Implements hook_toolbar().
 */
function build_hooks_toolbar() {
  if (getTriggerService()
    ->showMenu()) {
    $items['build_hooks'] = [
      '#cache' => [
        'contexts' => [
          'user.permissions',
        ],
      ],
      '#weight' => 999,
      '#type' => 'toolbar_item',
      'tab' => [
        '#type' => 'link',
        '#title' => t('Execute Build Hook'),
        '#url' => Url::fromRoute('build_hooks.trigger_controller_execute'),
      ],
    ];
    return $items;
  }
}
function getTriggerService() {
  return \Drupal::service('build_hooks.trigger');
}

Functions