You are here

redhen_org.module in RedHen CRM 8

Same filename and directory in other branches
  1. 7 modules/redhen_org/redhen_org.module

Contains redhen_org.module..

File

modules/redhen_org/redhen_org.module
View source
<?php

/**
 * @file
 * Contains redhen_org.module..
 */
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\redhen_org\Entity\OrgType;

/**
 * Denotes that the org is not active.
 */
const REDHEN_ORG_INACTIVE = 0;

/**
 * Denotes that the org is active.
 */
const REDHEN_ORG_ACTIVE = 1;

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

    // Main module help for the redhen_org module.
    case 'help.page.redhen_org':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Defines the base org entity and features.') . '</p>';
      return $output;
    default:
  }
}

/**
 * Implements hook_theme().
 */
function redhen_org_theme() {
  $theme = [];
  $theme['redhen_org'] = [
    'render element' => 'elements',
    'file' => 'redhen_org.page.inc',
    'template' => 'redhen_org',
  ];
  $theme['redhen_org_content_add_list'] = [
    'render element' => 'content',
    'variables' => [
      'content' => NULL,
    ],
    'file' => 'redhen_org.page.inc',
  ];
  return $theme;
}

/**
 * Implements hook_theme_suggestions_HOOK().
 */
function redhen_org_theme_suggestions_redhen_org(array $variables) {
  $suggestions = [];
  $org = $variables['elements']['#redhen_org'];
  $sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
  $suggestions[] = 'redhen_org__' . $sanitized_view_mode;
  $suggestions[] = 'redhen_org__' . $org
    ->getType();
  $suggestions[] = 'redhen_org__' . $org
    ->getType() . '__' . $sanitized_view_mode;
  $suggestions[] = 'redhen_org__' . $org
    ->id();
  $suggestions[] = 'redhen_org__' . $org
    ->id() . '__' . $sanitized_view_mode;
  return $suggestions;
}

/**
 * Return an associative array of org types to be used as an options list.
 *
 * @return array
 *   Keyed by name with a label value.
 */
function redhen_org_type_options_list() {
  $options = [];
  foreach (OrgType::loadMultiple() as $type) {
    $options[$type
      ->id()] = $type
      ->label();
  }
  return $options;
}

/**
 * Implements hook_tokens().
 */
function redhen_org_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
  $replacements = [];
  if ($type == 'entity' && isset($data['entity_type']) && $data['entity_type'] == 'redhen_org') {
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'id':
          $replacements[$original] = $data['entity']
            ->id();
          break;
        case 'name':
          $replacements[$original] = $data['entity']
            ->getName();
          break;
        case 'type':
          $replacements[$original] = $data['entity']
            ->getType();
          break;
        case 'status':
          $replacements[$original] = $data['entity']
            ->isActive();
          break;
        case 'created':
          $replacements[$original] = $data['entity']
            ->getCreatedTime();
          break;
      }
    }
  }
  return $replacements;
}

/**
 * Implements hook_token_info().
 */
function redhen_org_token_info() {
  $type = [
    'name' => t('Organization'),
    'description' => t('Tokens related to an individual Organizations.'),
    'needs-data' => 'redhen_org',
  ];
  $redhen_org['id'] = [
    'name' => t('Organization ID'),
    'description' => t('The unique ID of the Organization.'),
  ];
  $redhen_org['name'] = [
    'name' => t('Organization Name'),
    'description' => t('The name of the Organization.'),
  ];
  $redhen_org['type'] = [
    'name' => t('Organization Type'),
    'description' => t('The type (bundle) of the Organization.'),
  ];
  $redhen_org['status'] = [
    'name' => t('Organization Status'),
    'description' => t('The status of the Organization.'),
  ];
  $redhen_org['created'] = [
    'name' => t('Organization Created'),
    'description' => t('The timestamp the Organization was created.'),
  ];
  return [
    'types' => [
      'redhen_org' => $type,
    ],
    'tokens' => [
      'redhen_org' => $redhen_org,
    ],
  ];
}

Functions

Namesort descending Description
redhen_org_help Implements hook_help().
redhen_org_theme Implements hook_theme().
redhen_org_theme_suggestions_redhen_org Implements hook_theme_suggestions_HOOK().
redhen_org_tokens Implements hook_tokens().
redhen_org_token_info Implements hook_token_info().
redhen_org_type_options_list Return an associative array of org types to be used as an options list.

Constants

Namesort descending Description
REDHEN_ORG_ACTIVE Denotes that the org is active.
REDHEN_ORG_INACTIVE Denotes that the org is not active.