moved everything that references cases view into defaults

This commit is contained in:
Naomi 2020-11-17 11:09:17 +00:00
parent 0d927126a2
commit aff262a535
2 changed files with 31 additions and 62 deletions

View File

@ -61,3 +61,32 @@ function opencase_defaults_theme() {
]; ];
} }
/**
* Implements hook_block_access
*
* Forbids the opencase_contextual_menu block on pages where it has no content.
* (Without this, it was displaying an empty sidebar)
*/
function opencase_defaults_block_access(\Drupal\block\Entity\Block $block, $operation, \Drupal\Core\Session\AccountInterface $account) {
if ($operation == 'view' && $block->getPluginId() == 'opencase_contextual_menu') {
$route_name = \Drupal::routeMatch()->getRouteName();
$routes_where_it_should_be_shown = [
'entity.oc_actor.canonical',
'entity.oc_actor.edit_form',
'view.cases.page_1',
'entity.oc_case.canonical',
'entity.oc_case.edit_form',
'entity.oc_case.add_form',
'view.activities.page_1',
'entity.oc_activity.canonical',
'entity.oc_activity.edit_form',
'entity.oc_activity.add_form',
];
return AccessResult::forbiddenIf(!in_array($route_name, $routes_where_it_should_be_shown))->addCacheableDependency($block);
}
// No opinion.
return AccessResult::neutral();
}

View File

@ -33,35 +33,6 @@ function opencase_process_element($element) {
return $element; return $element;
} }
/**
* Implements hook_block_access
*
* Forbids the opencase_contextual_menu block on pages where it has no content.
* (Without this, it was displaying an empty sidebar)
*/
function opencase_block_access(\Drupal\block\Entity\Block $block, $operation, \Drupal\Core\Session\AccountInterface $account) {
if ($operation == 'view' && $block->getPluginId() == 'opencase_contextual_menu') {
$route_name = \Drupal::routeMatch()->getRouteName();
$routes_where_it_should_be_shown = [
'entity.oc_actor.canonical',
'entity.oc_actor.edit_form',
'view.cases.page_1',
'entity.oc_case.canonical',
'entity.oc_case.edit_form',
'entity.oc_case.add_form',
'view.activities.page_1',
'entity.oc_activity.canonical',
'entity.oc_activity.edit_form',
'entity.oc_activity.add_form',
];
return AccessResult::forbiddenIf(!in_array($route_name, $routes_where_it_should_be_shown))->addCacheableDependency($block);
}
// No opinion.
return AccessResult::neutral();
}
/** /**
* Implements hook_page_attachments * Implements hook_page_attachments
* *
@ -83,32 +54,6 @@ function opencase_link_alter(&$variables) {
} }
} }
/**
* Implements hook_preprocess_page_title
*
* Modify the page title to include more information
*/
function opencase_preprocess_page_title(&$variables) {
$route_name = \Drupal::routeMatch()->getRouteName();
switch ($route_name) {
case 'entity.oc_case.canonical':
$case = \Drupal::routeMatch()->getParameter('oc_case');
$variables['title'] = $case->getName() . ": Case Details and Files";
break;
case 'view.cases.page_1':
$actor_id = \Drupal::routeMatch()->getParameter('actor_id');
$actor = \Drupal::entityTypeManager()->getStorage('oc_actor')->load($actor_id);
$variables['title'] = $actor->getName() . ": Cases";
break;
case 'view.activities.page_1':
$case_id = \Drupal::routeMatch()->getParameter('case_id');
$case = \Drupal::entityTypeManager()->getStorage('oc_case')->load($case_id);
$variables['title'] = $case->getName() . ": Activities";
break;
}
}
/** /**
* Implements hook_help(). * Implements hook_help().
*/ */
@ -163,7 +108,6 @@ function opencase_uninstall() {
'block.block.opencasecontextualmenu', 'block.block.opencasecontextualmenu',
'block.block.opencase', 'block.block.opencase',
'system.menu.opencase', 'system.menu.opencase',
'views.view.cases',
'views.view.activities', 'views.view.activities',
'views.view.contact_details_changes' 'views.view.contact_details_changes'
]; ];
@ -191,7 +135,7 @@ function opencase_entity_field_access($operation, \Drupal\Core\Field\FieldDefini
/** /**
* Implementation of hook_form_alter() * Implementation of hook_form_alter()
* After deleting an actor or a case, redirect to the main page, which is a view of all cases. * Changes what page is redirected to after deleting things
*/ */
function opencase_form_alter(&$form, &$form_state, $form_id) { 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))) { if (preg_match('/oc_actor_.*_delete_form/', $form_id) or (preg_match('/oc_case_.*_delete_form/', $form_id))) {
@ -205,13 +149,9 @@ function opencase_form_alter(&$form, &$form_state, $form_id) {
} }
function _opencase_delete_case_redirect($form, &$form_state) { function _opencase_delete_case_redirect($form, &$form_state) {
$form_state->setRedirect('view.cases.page_2'); // redirect to view of all cases $form_state->setRedirect('<front>');
} }
function _opencase_delete_activity_redirect($form, &$form_state) { function _opencase_delete_activity_redirect($form, &$form_state) {
$case_id = $form_state->getFormObject()->getEntity()->oc_case->target_id; $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 $form_state->setRedirect('view.activities.page_1', ['case_id' => $case_id]); // redirect to the activity list
} }
function _opencase_cancel_delete_activity_redirect($form, &$form_state) {
$entity = $form_state->getFormObject()->getEntity();
$form_state->setRedirect('entity.oc_activity.canonical', ['oc_activity' => $entity->id()]); // redirect to the activity
}