View source
<?php
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\redhen_org\Entity\OrgType;
const REDHEN_ORG_INACTIVE = 0;
const REDHEN_ORG_ACTIVE = 1;
function redhen_org_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
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:
}
}
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;
}
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;
}
function redhen_org_type_options_list() {
$options = [];
foreach (OrgType::loadMultiple() as $type) {
$options[$type
->id()] = $type
->label();
}
return $options;
}
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;
}
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,
],
];
}