2018-04-29 07:22:16 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Contains opencase_entities.module.
|
|
|
|
*/
|
|
|
|
|
|
|
|
use Drupal\Core\Routing\RouteMatchInterface;
|
2018-07-09 17:36:47 +00:00
|
|
|
use Drupal\opencase_entities\CaseInvolvement;
|
2018-04-29 07:22:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_help().
|
|
|
|
*/
|
|
|
|
function opencase_entities_help($route_name, RouteMatchInterface $route_match) {
|
|
|
|
switch ($route_name) {
|
|
|
|
// Main module help for the opencase_entities module.
|
|
|
|
case 'help.page.opencase_entities':
|
|
|
|
$output = '';
|
|
|
|
$output .= '<h3>' . t('About') . '</h3>';
|
2018-04-29 11:52:36 +00:00
|
|
|
$output .= '<p>' . t('Entity Types for OpenCase') . '</p>';
|
2018-04-29 07:22:16 +00:00
|
|
|
return $output;
|
|
|
|
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_theme().
|
|
|
|
*/
|
|
|
|
function opencase_entities_theme() {
|
2018-04-29 11:58:46 +00:00
|
|
|
$theme = [];
|
|
|
|
$theme['opencase_entities'] = [
|
|
|
|
'render element' => 'children',
|
2018-04-29 07:22:16 +00:00
|
|
|
];
|
2018-04-29 11:58:46 +00:00
|
|
|
$theme['oc_actor'] = [
|
|
|
|
'render element' => 'elements',
|
|
|
|
'file' => 'oc_actor.page.inc',
|
|
|
|
'template' => 'oc_actor',
|
|
|
|
];
|
|
|
|
$theme['oc_actor_content_add_list'] = [
|
|
|
|
'render element' => 'content',
|
|
|
|
'variables' => ['content' => NULL],
|
|
|
|
'file' => 'oc_actor.page.inc',
|
|
|
|
];
|
|
|
|
$theme['oc_case'] = [
|
|
|
|
'render element' => 'elements',
|
|
|
|
'file' => 'oc_case.page.inc',
|
|
|
|
'template' => 'oc_case',
|
|
|
|
];
|
|
|
|
$theme['oc_case_content_add_list'] = [
|
|
|
|
'render element' => 'content',
|
|
|
|
'variables' => ['content' => NULL],
|
|
|
|
'file' => 'oc_case.page.inc',
|
|
|
|
];
|
|
|
|
$theme['oc_activity'] = [
|
|
|
|
'render element' => 'elements',
|
|
|
|
'file' => 'oc_activity.page.inc',
|
|
|
|
'template' => 'oc_activity',
|
|
|
|
];
|
|
|
|
$theme['oc_activity_content_add_list'] = [
|
|
|
|
'render element' => 'content',
|
|
|
|
'variables' => ['content' => NULL],
|
|
|
|
'file' => 'oc_activity.page.inc',
|
|
|
|
];
|
|
|
|
return $theme;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_theme_suggestions_HOOK().
|
|
|
|
*/
|
|
|
|
function opencase_entities_theme_suggestions_oc_actor(array $variables) {
|
|
|
|
$suggestions = [];
|
|
|
|
$entity = $variables['elements']['#oc_actor'];
|
|
|
|
$sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
|
|
|
|
|
|
|
|
$suggestions[] = 'oc_actor__' . $sanitized_view_mode;
|
|
|
|
$suggestions[] = 'oc_actor__' . $entity->bundle();
|
|
|
|
$suggestions[] = 'oc_actor__' . $entity->bundle() . '__' . $sanitized_view_mode;
|
|
|
|
$suggestions[] = 'oc_actor__' . $entity->id();
|
|
|
|
$suggestions[] = 'oc_actor__' . $entity->id() . '__' . $sanitized_view_mode;
|
|
|
|
return $suggestions;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_theme_suggestions_HOOK().
|
|
|
|
*/
|
|
|
|
function opencase_entities_theme_suggestions_oc_case(array $variables) {
|
|
|
|
$suggestions = [];
|
|
|
|
$entity = $variables['elements']['#oc_case'];
|
|
|
|
$sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
|
|
|
|
|
|
|
|
$suggestions[] = 'oc_case__' . $sanitized_view_mode;
|
|
|
|
$suggestions[] = 'oc_case__' . $entity->bundle();
|
|
|
|
$suggestions[] = 'oc_case__' . $entity->bundle() . '__' . $sanitized_view_mode;
|
|
|
|
$suggestions[] = 'oc_case__' . $entity->id();
|
|
|
|
$suggestions[] = 'oc_case__' . $entity->id() . '__' . $sanitized_view_mode;
|
|
|
|
return $suggestions;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_theme_suggestions_HOOK().
|
|
|
|
*/
|
|
|
|
function opencase_entities_theme_suggestions_oc_activity(array $variables) {
|
|
|
|
$suggestions = [];
|
|
|
|
$entity = $variables['elements']['#oc_activity'];
|
|
|
|
$sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
|
|
|
|
|
|
|
|
$suggestions[] = 'oc_activity__' . $sanitized_view_mode;
|
|
|
|
$suggestions[] = 'oc_activity__' . $entity->bundle();
|
|
|
|
$suggestions[] = 'oc_activity__' . $entity->bundle() . '__' . $sanitized_view_mode;
|
|
|
|
$suggestions[] = 'oc_activity__' . $entity->id();
|
|
|
|
$suggestions[] = 'oc_activity__' . $entity->id() . '__' . $sanitized_view_mode;
|
|
|
|
return $suggestions;
|
2018-04-29 07:22:16 +00:00
|
|
|
}
|
2018-07-09 17:36:47 +00:00
|
|
|
|
|
|
|
function opencase_views_query_alter(Drupal\views\ViewExecutable $view, $query) {
|
2018-07-17 14:19:25 +00:00
|
|
|
if ($view->getBaseEntityType() && $view->getBaseEntityType()->id() == 'oc_case') {
|
2018-07-09 17:36:47 +00:00
|
|
|
$query->addTag('oc_case_access');
|
|
|
|
}
|
2018-07-19 14:22:26 +00:00
|
|
|
if ($view->getBaseEntityType() && $view->getBaseEntityType()->id() == 'oc_activity') {
|
|
|
|
$query->addTag('oc_activity_access');
|
|
|
|
}
|
2018-07-09 17:36:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function opencase_query_oc_case_access_alter($query) {
|
|
|
|
if (\Drupal::currentUser()->hasPermission('view published case entities')) {
|
|
|
|
return;
|
2018-07-09 18:26:11 +00:00
|
|
|
}
|
|
|
|
$linked_actor_id = CaseInvolvement::getLinkedActorId(\Drupal::currentUser());
|
|
|
|
$query->addJoin('INNER', 'oc_case__actors_involved', 'access_filter', 'access_filter.entity_id = oc_case_field_data.id');
|
|
|
|
$query->condition('access_filter.actors_involved_target_id', $linked_actor_id);
|
2018-07-09 17:36:47 +00:00
|
|
|
}
|
2018-07-19 14:22:26 +00:00
|
|
|
|
|
|
|
function opencase_query_oc_activity_access_alter($query) {
|
|
|
|
if (\Drupal::currentUser()->hasPermission('view published case entities')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$linked_actor_id = CaseInvolvement::getLinkedActorId(\Drupal::currentUser());
|
|
|
|
$query->addJoin('INNER', 'oc_case__actors_involved', 'access_filter', 'access_filter.entity_id = oc_activity_field_data.oc_case');
|
|
|
|
$query->condition('access_filter.actors_involved_target_id', $linked_actor_id);
|
|
|
|
}
|