From 2bc1abc7a74670c0ee164b3a37776e430cad9029 Mon Sep 17 00:00:00 2001 From: naomi Date: Fri, 5 Feb 2021 13:43:11 +0000 Subject: [PATCH] Deleting activity in "No Cases" mode should redirect to first linked person, and other changes --- modules/opencase_cases/opencase_cases.module | 23 ++ .../opencase_entities.module | 15 + .../src/Entity/OCActivity.php | 4 + .../opencase_entities/src/Entity/OCActor.php | 11 +- ....block.views_block__activities_block_1.yml | 30 ++ .../config/install/views.view.activities.yml | 318 ++++++++++++++++++ .../opencase_no_cases.module | 37 ++ opencase.info.yml | 1 + opencase.module | 22 -- 9 files changed, 437 insertions(+), 24 deletions(-) create mode 100644 modules/opencase_no_cases/config/install/block.block.views_block__activities_block_1.yml create mode 100644 modules/opencase_no_cases/config/install/views.view.activities.yml diff --git a/modules/opencase_cases/opencase_cases.module b/modules/opencase_cases/opencase_cases.module index 84c7bdf..79cf4b3 100644 --- a/modules/opencase_cases/opencase_cases.module +++ b/modules/opencase_cases/opencase_cases.module @@ -62,3 +62,26 @@ function opencase_cases_entity_base_field_info($entity_type) { public static function opencase_cases_default_activity_case_value() { 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(''); +} +function _opencase_cases_delete_activity_redirect($form, &$form_state) { + $case_id = $form_state->getFormObject()->getEntity()->oc_case->target_id; + $form_state->setRedirect('entity.oc_case.canonical', ['oc_case' => $case_id]); +} diff --git a/modules/opencase_entities/opencase_entities.module b/modules/opencase_entities/opencase_entities.module index bf62ec1..de31340 100644 --- a/modules/opencase_entities/opencase_entities.module +++ b/modules/opencase_entities/opencase_entities.module @@ -191,3 +191,18 @@ function opencase_entities_theme_suggestions_oc_event(array $variables) { $suggestions[] = 'oc_event__' . $entity->id() . '__' . $sanitized_view_mode; return $suggestions; } + +/* Presave hook on actor entities to manage user creation. + - If a linked user already exists with that email, it does nothing. + - If a user exists with that email but it has no linked actor, it links it. + - If a user exists with that email which already has a linked actor, it fails validation. + - If a linked user exists with a different email, it updates the email. +*/ +function opencase_entities_oc_actor_presave(Drupal\Core\Entity\EntityInterface $entity) { + if ($entity->get('user_login')->value) { + + error_log($entity->get('first_name')->value); + error_log($entity->get('last_name')->value); + error_log($entity->get('email')->value); + } +} diff --git a/modules/opencase_entities/src/Entity/OCActivity.php b/modules/opencase_entities/src/Entity/OCActivity.php index 4ea9a9b..460acf7 100644 --- a/modules/opencase_entities/src/Entity/OCActivity.php +++ b/modules/opencase_entities/src/Entity/OCActivity.php @@ -263,6 +263,8 @@ class OCActivity extends RevisionableContentEntityBase implements OCActivityInte 'text_processing' => 0, ]) ->setDefaultValue('') + ->setDisplayConfigurable('form', true) + ->setDisplayConfigurable('view', true) ->setDisplayOptions('view', [ 'label' => 'hidden', 'type' => 'string', @@ -299,6 +301,8 @@ class OCActivity extends RevisionableContentEntityBase implements OCActivityInte ->setSettings([ 'suffix' => 'minutes', ]) + ->SetDisplayConfigurable("form", true) + ->SetDisplayConfigurable("view", true) ->setDefaultValue('') ->setDisplayOptions('view', [ 'label' => 'above', diff --git a/modules/opencase_entities/src/Entity/OCActor.php b/modules/opencase_entities/src/Entity/OCActor.php index 4ee5789..2ad63a3 100644 --- a/modules/opencase_entities/src/Entity/OCActor.php +++ b/modules/opencase_entities/src/Entity/OCActor.php @@ -118,7 +118,7 @@ class OCActor extends RevisionableContentEntityBase implements OCActorInterface $name = $this->get('first_name')->value . ' '; if ($this->get('middle_names')->value) $name .= $this->get('middle_names')->value . ' '; $name .= $this->get('last_name')->value . ' '; - $name .= '(' . $this->bundle() . ')'; + $name .= '(' . $this->type->entity->label() . ')'; $this->setName($name); @@ -284,7 +284,6 @@ class OCActor extends RevisionableContentEntityBase implements OCActorInterface ->setRequired(TRUE); // Contact details. - // so it is not exposed to user configuration. $fields['email'] = BaseFieldDefinition::create('string') ->setLabel(t('Email Address')) ->setRevisionable(TRUE) @@ -293,6 +292,7 @@ class OCActor extends RevisionableContentEntityBase implements OCActorInterface 'max_length' => 30, 'text_processing' => 0, )) + ->setDisplayConfigurable('form', true) ->setDisplayOptions('view', array( 'label' => 'above', 'type' => 'string', @@ -387,6 +387,13 @@ class OCActor extends RevisionableContentEntityBase implements OCActorInterface ->setRevisionable(TRUE) ->setTranslatable(TRUE); + $fields['user_login'] = BaseFieldDefinition::create('boolean') + ->setLabel(t('Login Access')) + ->setDescription(t('Whether this person should be able to log into the system.')) + ->setDisplayConfigurable('form', true) + ->setDisplayConfigurable('display', true) + ->setDefaultValue(FALSE); + return $fields; } diff --git a/modules/opencase_no_cases/config/install/block.block.views_block__activities_block_1.yml b/modules/opencase_no_cases/config/install/block.block.views_block__activities_block_1.yml new file mode 100644 index 0000000..ff021e4 --- /dev/null +++ b/modules/opencase_no_cases/config/install/block.block.views_block__activities_block_1.yml @@ -0,0 +1,30 @@ +langcode: en +status: true +dependencies: + config: + - views.view.activities + module: + - route_condition + - views + theme: + - bartik +id: views_block__activities_block_1 +theme: bartik +region: content +weight: 0 +provider: null +plugin: 'views_block:activities-block_1' +settings: + id: 'views_block:activities-block_1' + label: '' + provider: views + label_display: visible + views_label: '' + items_per_page: none + context_mapping: { } +visibility: + route: + id: route + routes: entity.oc_actor.canonical + negate: false + context_mapping: { } diff --git a/modules/opencase_no_cases/config/install/views.view.activities.yml b/modules/opencase_no_cases/config/install/views.view.activities.yml new file mode 100644 index 0000000..c82f478 --- /dev/null +++ b/modules/opencase_no_cases/config/install/views.view.activities.yml @@ -0,0 +1,318 @@ +langcode: en +status: true +dependencies: + module: + - datetime + - opencase_entities +id: activities +label: Activities +module: views +description: '' +tag: '' +base_table: oc_activity_field_data +base_field: id +display: + default: + display_plugin: default + id: default + display_title: Master + position: 0 + display_options: + access: + type: none + options: { } + cache: + type: tag + options: { } + query: + type: views_query + options: + disable_sql_rewrite: false + distinct: false + replica: false + query_comment: '' + query_tags: { } + exposed_form: + type: basic + options: + submit_button: Apply + reset_button: false + reset_button_label: Reset + exposed_sorts_label: 'Sort by' + expose_sort_order: true + sort_asc_label: Asc + sort_desc_label: Desc + pager: + type: none + options: + items_per_page: null + offset: 0 + style: + type: table + row: + type: fields + fields: + name: + id: name + table: oc_activity_field_data + field: name + relationship: none + group_type: group + admin_label: '' + label: Subject + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: value + type: string + settings: + link_to_entity: true + group_column: value + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + entity_type: null + entity_field: name + plugin_id: field + activity_date_time: + id: activity_date_time + table: oc_activity_field_data + field: activity_date_time + relationship: none + group_type: group + admin_label: '' + label: 'Date and time' + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: value + type: datetime_default + settings: + timezone_override: '' + format_type: medium + group_column: value + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + entity_type: oc_activity + entity_field: activity_date_time + plugin_id: field + actors_involved_target_id: + id: actors_involved_target_id + table: oc_activity__actors_involved + field: actors_involved_target_id + relationship: none + group_type: group + admin_label: '' + label: Participants + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: target_id + type: entity_reference_label + settings: + link: true + group_column: target_id + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + entity_type: oc_activity + entity_field: actors_involved + plugin_id: field + filters: { } + sorts: { } + title: Activities + header: { } + footer: { } + empty: { } + relationships: { } + arguments: + actors_involved_target_id: + id: actors_involved_target_id + table: oc_activity__actors_involved + field: actors_involved_target_id + relationship: none + group_type: group + admin_label: '' + default_action: default + exception: + value: all + title_enable: false + title: All + title_enable: false + title: '' + default_argument_type: raw + default_argument_options: + index: 2 + use_alias: false + default_argument_skip_url: false + summary_options: + base_path: '' + count: true + items_per_page: 25 + override: false + summary: + sort_order: asc + number_of_records: 0 + format: default_summary + specify_validation: false + validate: + type: none + fail: 'not found' + validate_options: { } + break_phrase: false + not: false + entity_type: oc_activity + entity_field: actors_involved + plugin_id: numeric + display_extenders: { } + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - url + tags: { } + block_1: + display_plugin: block + id: block_1 + display_title: Block + position: 1 + display_options: + display_extenders: { } + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - url + tags: { } diff --git a/modules/opencase_no_cases/opencase_no_cases.module b/modules/opencase_no_cases/opencase_no_cases.module index f170459..beb0c33 100644 --- a/modules/opencase_no_cases/opencase_no_cases.module +++ b/modules/opencase_no_cases/opencase_no_cases.module @@ -65,3 +65,40 @@ function opencase_no_cases_actors_involved_callback() { return array_unique([$currently_viewed_actor_id, $author_linked_actor_id]); } +/** + * Implementation of hook_form_alter() + * When deleting an activity go back to the page of the first listed involved party (as this is likely to be the "target" of the activity). + */ +function opencase_form_alter(&$form, &$form_state, $form_id) { + if (preg_match('/oc_actor_.*_delete_form/', $form_id) or (preg_match('/oc_organisation_.*_delete_form/', $form_id))) { + $form['actions']['submit']['#submit'][] = '_opencase_no_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_no_cases_delete_activity_redirect'; + $form['actions']['cancel']['#url'] = $form_state->getFormObject()->getEntity()->toUrl(); + } +} + +function _opencase_no_cases_redirect_to_home($form, &$form_state) { + $form_state->setRedirect(''); +} +function _opencase_no_cases_delete_activity_redirect($form, &$form_state) { + $actor_id = $form_state->getFormObject()->getEntity()->actors_involved[0]->target_id; + $form_state->setRedirect('entity.oc_actor.canonical', ['oc_actor' => $actor_id]); +} +/** + * Implements hook_uninstall(). + */ +function opencase_no_cases_uninstall() { + $dir = new DirectoryIterator(dirname(__FILE__) . "/config/install"); + $configs = []; + foreach ($dir as $fileinfo) { + if (!$fileinfo->isDot()) { + $configs[] = str_replace('.yml', '', $fileinfo->getFilename()); + } + } + foreach($configs as $config) { + Drupal::configFactory()->getEditable($config)->delete(); + } +} diff --git a/opencase.info.yml b/opencase.info.yml index 677ac64..02902c5 100644 --- a/opencase.info.yml +++ b/opencase.info.yml @@ -7,5 +7,6 @@ package: 'OpenCase' dependencies: - opencase_entities - superfish + - admin_toolbar libraries: - opencase/opencase-lib diff --git a/opencase.module b/opencase.module index 7ae451b..6d46be2 100644 --- a/opencase.module +++ b/opencase.module @@ -112,25 +112,3 @@ function opencase_entity_field_access($operation, \Drupal\Core\Field\FieldDefini } -/** - * 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)) or (preg_match('/oc_organisation_.*_delete_form/', $form_id))) { - $form['actions']['submit']['#submit'][] = '_opencase_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_delete_activity_redirect'; - $form['actions']['cancel']['#url'] = $form_state->getFormObject()->getEntity()->toUrl(); - } -} - -function _opencase_redirect_to_home($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('entity.oc_case.canonical', ['oc_case' => $case_id]); -}