isExternal()) { $variables['options']['attributes'] = ['target' => '_blank']; } } /** * Implements hook_help(). */ function opencase_help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { // Main module help for the opencase module. case 'help.page.opencase': $output = ''; $output .= '

' . t('About') . '

'; $output .= '

' . t('Simple Case Management') . '

'; return $output; default: } } /** * Implements hook_theme(). */ function opencase_theme() { return [ 'opencase' => [ 'render element' => 'children', ], ]; } /** * Implements hook_form_ID_alter */ function opencase_form_oc_case_type_add_form_alter(&$form, $form_state) { $widget = new EntityTypeRelationsWidget(); $widget->setup($form); } /** * Implements hook_form_ID_alter */ function opencase_form_oc_case_type_edit_form_alter(&$form, $form_state) { $widget = new EntityTypeRelationsWidget(); $widget->setup($form); $widget->populate($form); } /** * Implements hook_uninstall(). * Removes configs. */ function opencase_uninstall() { $configs = [ 'block.block.opencasecontextualmenu', 'block.block.opencase', 'system.menu.opencase', 'views.view.activities', 'views.view.contact_details_changes' ]; foreach($configs as $config) { Drupal::configFactory()->getEditable($config)->delete(); } } function opencase_views_pre_render($view) { if (empty($view->result) && empty($view->exposed_input)) { $view->exposed_widgets = NULL; } } function opencase_entity_field_access($operation, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, $account, $items = NULL) { if ($field_definition->getName() == 'field_linked_opencase_actor' && $operation == 'edit' && !$account->hasPermission('administer users')) { return AccessResult::forbidden(); } return AccessResult::neutral(); } /** * Implementation of hook_form_alter() * Changes what page is redirected to after deleting things */ function opencase_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))) { $form['actions']['submit']['#submit'][] = '_opencase_delete_case_redirect'; $form['actions']['cancel']['#url'] = $form_state->getFormObject()->getEntity()->toUrl(); } if (preg_match('/oc_activity_.*_delete_form/', $form_id)) { $form['actions']['submit']['#submit'][] = '_opencase_delete_activity_redirect'; $form['actions']['cancel']['#url'] = $form_state->getFormObject()->getEntity()->toUrl(); } } function _opencase_delete_case_redirect($form, &$form_state) { $form_state->setRedirect(''); } function _opencase_delete_activity_redirect($form, &$form_state) { $case_id = $form_state->getFormObject()->getEntity()->oc_case->target_id; $form_state->setRedirect('view.activities.page_1', ['case_id' => $case_id]); // redirect to the activity list }