arlo-1.x-dev/arlo.module

arlo.module
<?php

/**
 * @file
 * Contains arlo.module.
 */

use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Routing\TrustedRedirectResponse;

/**
 * Implements hook_help().
 */
function arlo_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    // Main module help for the arlo module.
    case 'help.page.arlo':
      $output = '<h4>' . t('Overview') . '</h4>';
      return $output;
      break;
    default:
      break;
  }
}

/**
 * Implements hook_node_view().
 */
function arlo_node_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
  if ($entity->bundle() == 'arlo_event') {
    $link = $entity->get('field_arlo_link')->getValue();
    $uri = $link[0]['uri'];
    $redirect = new TrustedRedirectResponse($uri);
    $redirect->send();
  }
}

/**
 * Implements hook_theme().
 */
function arlo_theme($existing, $type, $theme, $path) {

  /**
   * The Arlo calendar block template
   */
  $data['arlo_calendar'] = [
    'variables' => [
      'platform_id' => NULL,
    ],
    'template' => 'arlo-calendar',
  ];

  /**
   * The Arlo search block templates.
   */
  for ($i = 1; $i <= 2 ; $i++) {
    $data['arlo_search_' . $i] = [
      'variables' => [
       'platform_id' => NULL,
      ],
      'template' => 'arlo-search-' . $i,
    ];
  }

  /**
   * Themes for upcoming events block. This is diffferent than the single event
   * block and is separated as such.
   */
  for ($i = 1; $i <= 6; $i++) {
    $data['arlo_upcoming_events_' . $i]['variables'] = [
      'platform_id' => NULL,
      'show_load_more' => NULL,
      'load_more_text' => NULL,
      'dev_mode' => NULL,
      'locations' => NULL,
      'tag' => NULL,
      'template_category_id' => NULL,
      'event_ids' => NULL,
      'template_id' => NULL,
      'max_count' => NULL,
    ];
    $data['arlo_events_' . $i]['template'] = 'arlo-upcoming_events-' . $i;
  }

  /**
   * Pull in any upcoming event custom templates configured in hooks.
   */
  $options = [];
  $hook = 'custom_upcoming_event_templates';
  \Drupal::moduleHandler()->invokeAllWith($hook, function (callable $hook, string $module) use (&$options) {
    $options = $hook();
  });

  foreach ($options as $key => $result) {
    $data['arlo_upcoming_events_' . $key]['variables'] = [
      'platform_id' => NULL,
      'show_load_more' => NULL,
      'load_more_text' => NULL,
      'dev_mode' => NULL,
      'locations' => NULL,
      'tag' => NULL,
      'template_category_id' => NULL,
      'event_ids' => NULL,
      'template_id' => NULL,
      'max_count' => NULL,
    ];
    $data['arlo_upcoming_events_' . $key]['template'] = 'arlo-upcoming-events-' . $key;
  }

  /**
   * Themes for the individual event block. This is diffferent than the 
   * upcoming events block and is separated as such.
   */
  for ($i = 1; $i <= 5; $i++) {
    $data['arlo_event_' . $i]['variables'] = [
      'platform_id' => NULL,
      'template_id' => NULL,
    ];
    $data['arlo_event_' . $i]['template'] = 'arlo-event-' . $i;
  }

  /**
   * Pull in any individual event custom templates configured in hooks.
   */
  $options = [];
  $hook = 'custom_event_templates';
  \Drupal::moduleHandler()->invokeAllWith($hook, function (callable $hook, string $module) use (&$options) {
    $options = $hook();
  });

  foreach ($options as $key => $result) {
    $data['arlo_event_' . $key]['variables'] = [
      'platform_id' => NULL,
      'template_id' => NULL,
    ];
    $data['arlo_event_' . $key]['template'] = 'arlo-event-' . $key;
  }
  return $data;
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc