' . t('About') . ''; $output .= '
' . t('Provides case entities and a required field on activities linking them to a case, plus case fee and case provision entities.') . '
'; return $output; default: } } /** * Implements hook_theme(). */ function opencase_cases_theme() { return [ 'opencase_cases' => [ 'render element' => 'children', ], 'oc_case' => [ 'render element' => 'elements', 'file' => 'oc_case.page.inc', 'template' => 'oc_case', ], 'oc_case_content_add_list' => [ 'render element' => 'content', 'variables' => ['content' => NULL], 'file' => 'oc_case.page.inc', ], 'oc_case_provision' => [ 'render element' => 'elements', 'file' => 'oc_case_provision.page.inc', 'template' => 'oc_case_provision', ], 'oc_case_provision_content_add_list' => [ 'render element' => 'content', 'variables' => ['content' => NULL], 'file' => 'oc_case_provision.page.inc', ], 'oc_case_fee' => [ 'render element' => 'elements', 'file' => 'oc_case_fee.page.inc', 'template' => 'oc_case_fee', ], 'oc_case_fee_content_add_list' => [ 'render element' => 'content', 'variables' => ['content' => NULL], 'file' => 'oc_case_fee.page.inc', ], ]; } function opencase_cases_oc_case_fee_update(Drupal\opencase_cases\entity\OCCaseFee $case_fee): void { $case = $case_fee->getCase(); $case->addToTotalFee($case_fee->amount->value - $case_fee->original->amount->value); } function opencase_cases_oc_case_fee_insert(Drupal\opencase_cases\entity\OCCaseFee $case_fee): void { $case = $case_fee->getCase(); $case->addToTotalFee($case_fee->amount->value); } function opencase_cases_oc_case_fee_delete(Drupal\opencase_cases\entity\OCCaseFee $case_fee): void { $case = $case_fee->getCase(); $case->addToTotalFee(0 - $case_fee->amount->value); } 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'] = \Drupal\Core\Field\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_case_id') ->setDisplayOptions('view', [ 'type' => 'string', 'weight' => -3, ]) ->setRequired(TRUE); } return $fields; } /** * When creating an activity, it sets the case id from the URL. */ function opencase_cases_default_case_id() { return array(\Drupal::request()->query->get('case_id')); } /** * Implementation of hook_form_alter() * Changes what page is redirected to after deleting things */ function opencase_cases_form_alter(&$form, &$form_state, $form_id) { if (preg_match('/oc_actor_.*_delete_form/', $form_id) or (preg_match('/oc_case_.*_delete_form/', $form_id)) or (preg_match('/oc_organisation_.*_delete_form/', $form_id))) { $form['actions']['submit']['#submit'][] = '_opencase_cases_redirect_to_home'; $form['actions']['cancel']['#url'] = $form_state->getFormObject()->getEntity()->toUrl(); } if (preg_match('/oc_activity_.*_delete_form/', $form_id)) { $form['actions']['submit']['#submit'][] = '_opencase_cases_delete_activity_redirect'; $form['actions']['cancel']['#url'] = $form_state->getFormObject()->getEntity()->toUrl(); } } function _opencase_cases_redirect_to_home($form, &$form_state) { $form_state->setRedirect('