65 lines
1.6 KiB
Plaintext
65 lines
1.6 KiB
Plaintext
|
<?php
|
||
|
|
||
|
/**
|
||
|
* @file
|
||
|
* Contains opencase_cases.module.
|
||
|
*/
|
||
|
|
||
|
use Drupal\Core\Routing\RouteMatchInterface;
|
||
|
|
||
|
/**
|
||
|
* Implements hook_help().
|
||
|
*/
|
||
|
function opencase_cases_help($route_name, RouteMatchInterface $route_match) {
|
||
|
switch ($route_name) {
|
||
|
// Main module help for the opencase_cases module.
|
||
|
case 'help.page.opencase_cases':
|
||
|
$output = '';
|
||
|
$output .= '<h3>' . t('About') . '</h3>';
|
||
|
$output .= '<p>' . t('Provides case entities and a required field on activities linking them to a case.') . '</p>';
|
||
|
return $output;
|
||
|
|
||
|
default:
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Implements hook_theme().
|
||
|
*/
|
||
|
function opencase_cases_theme() {
|
||
|
return [
|
||
|
'opencase_cases' => [
|
||
|
'render element' => 'children',
|
||
|
],
|
||
|
];
|
||
|
}
|
||
|
|
||
|
function opencase_cases_entity_base_field_info($entity_type) {
|
||
|
$fields = array();
|
||
|
|
||
|
// Add Case field to Activity
|
||
|
if ($entity_type->id() === 'oc_activity') {
|
||
|
$fields['oc_case'] = BaseFieldDefinition::create('entity_reference')
|
||
|
->setLabel(t('Case'))
|
||
|
->setDescription(t('The case this activity belongs to.'))
|
||
|
->setSetting('target_type', 'oc_case')
|
||
|
->setSetting('handler', 'default')
|
||
|
->setTranslatable(TRUE)
|
||
|
->setCardinality(1)
|
||
|
->setDefaultValueCallback('opencase_cases_default_activity_case_value')
|
||
|
->setDisplayOptions('view', [
|
||
|
'type' => 'string',
|
||
|
'weight' => -3,
|
||
|
])
|
||
|
->setRequired(TRUE);
|
||
|
}
|
||
|
return $fields;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* When creating an activity, it sets the case id from the URL.
|
||
|
*/
|
||
|
public static function opencase_cases_default_activity_case_value() {
|
||
|
return array(\Drupal::request()->query->get('case_id'));
|
||
|
}
|