From 3dd71bf2c04650708e045abba3d3a45e8de84143 Mon Sep 17 00:00:00 2001
From: naomi
Date: Mon, 8 Feb 2021 13:38:54 +0000
Subject: [PATCH] Added full_name field to actors, and made the administer
entities permission finer grained
---
css/opencase.css | 8 +++++
.../opencase_cases.links.menu.yml | 7 +++++
....user.user.field_linked_opencase_actor.yml | 2 +-
.../opencase_entities.permissions.yml | 16 ++++++++--
.../src/Entity/OCActivityType.php | 2 +-
.../opencase_entities/src/Entity/OCActor.php | 30 ++++++++++++++++---
.../src/Entity/OCActorType.php | 2 +-
.../src/Entity/OCBankAccount.php | 19 +-----------
.../src/Entity/OCCaseType.php | 2 +-
.../src/Plugin/Block/ContextualMenu.php | 5 ++--
opencase.links.menu.yml | 7 -----
11 files changed, 62 insertions(+), 38 deletions(-)
create mode 100644 modules/opencase_cases/opencase_cases.links.menu.yml
diff --git a/css/opencase.css b/css/opencase.css
index 18cea69..91e5af8 100644
--- a/css/opencase.css
+++ b/css/opencase.css
@@ -6,6 +6,14 @@ body {
font-size: 1em !important;
}
+div[data-drupal-selector=edit-user-bulk-form] {
+ display: none;
+}
+
+.layout-container {
+ max-width: 95% !important;
+}
+
/* Free the people from the tyranny of the useless search button */
#edit-submit-actor-search{
display: none;
diff --git a/modules/opencase_cases/opencase_cases.links.menu.yml b/modules/opencase_cases/opencase_cases.links.menu.yml
new file mode 100644
index 0000000..98d35e3
--- /dev/null
+++ b/modules/opencase_cases/opencase_cases.links.menu.yml
@@ -0,0 +1,7 @@
+opencase_cases.manage_case_types:
+ title: 'Manage case types'
+ description: 'Configure types of cases and their fields'
+ menu_name: opencase
+ parent: opencase.opencase_admin_menu
+ url: internal:/admin/opencase/oc_case_type
+ weight: 2
diff --git a/modules/opencase_entities/config/install/field.field.user.user.field_linked_opencase_actor.yml b/modules/opencase_entities/config/install/field.field.user.user.field_linked_opencase_actor.yml
index d67e47b..68dd9c4 100644
--- a/modules/opencase_entities/config/install/field.field.user.user.field_linked_opencase_actor.yml
+++ b/modules/opencase_entities/config/install/field.field.user.user.field_linked_opencase_actor.yml
@@ -10,7 +10,7 @@ field_name: field_linked_opencase_actor
entity_type: user
bundle: user
label: 'Person in OpenCase'
-description: 'If this user is also a person in OpenCase (e.g. a staff member or a volunteer), start typing the name here to link them. This will ensure they have access to the right cases.'
+description: 'If this user is also a person in OpenCase (e.g. a staff member or a volunteer), start typing the name here to link them. This will make their name appear against activities they are involved in.'
required: false
translatable: false
default_value: { }
diff --git a/modules/opencase_entities/opencase_entities.permissions.yml b/modules/opencase_entities/opencase_entities.permissions.yml
index b0c236c..5590a61 100644
--- a/modules/opencase_entities/opencase_entities.permissions.yml
+++ b/modules/opencase_entities/opencase_entities.permissions.yml
@@ -5,9 +5,14 @@ view edit delete all actor entities:
title: 'View/Edit/Delete all types of people'
description: ''
-administer opencase entity bundles:
- title: 'Administer OpenCase Actor/Case/Activity Types'
- description: 'Create, configure and delete types of actor (such as "Client" or "Legal Advisor"), types of case (such as "Housing" or "Asylum") and types of activity (such as "Case Note" or "Interview")'
+administer actor bundles:
+ title: 'Administer OpenCase Person Types'
+
+administer case bundles:
+ title: 'Administer OpenCase Case Types'
+
+administer activity bundles:
+ title: 'Administer OpenCase Activity Types'
administer actor entities:
title: 'Administer Actor entities'
@@ -45,6 +50,11 @@ revert all case revisions:
delete all case revisions:
title: 'Delete all revisions'
description: 'Role requires permission to view Case revisions and delete rights for case entities in question or administer case entities.'
+
+
+view published activity entities:
+ title: 'View published Activity entities'
+
add activity entities:
title: 'Create new Activity entities'
diff --git a/modules/opencase_entities/src/Entity/OCActivityType.php b/modules/opencase_entities/src/Entity/OCActivityType.php
index e8b4b62..2b62eca 100644
--- a/modules/opencase_entities/src/Entity/OCActivityType.php
+++ b/modules/opencase_entities/src/Entity/OCActivityType.php
@@ -24,7 +24,7 @@ use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
* },
* },
* config_prefix = "oc_activity_type",
- * admin_permission = "administer opencase entity bundles",
+ * admin_permission = "administer activity bundles",
* bundle_of = "oc_activity",
* entity_keys = {
* "id" = "id",
diff --git a/modules/opencase_entities/src/Entity/OCActor.php b/modules/opencase_entities/src/Entity/OCActor.php
index 961d522..2c7fd2e 100644
--- a/modules/opencase_entities/src/Entity/OCActor.php
+++ b/modules/opencase_entities/src/Entity/OCActor.php
@@ -114,10 +114,14 @@ class OCActor extends RevisionableContentEntityBase implements OCActorInterface
$translation->setOwnerId(0);
}
}
-
- $name = $this->get('first_name')->value . ' ';
- if ($this->get('middle_names')->value) $name .= $this->get('middle_names')->value . ' ';
- $name .= $this->get('last_name')->value . ' ';
+
+ if ($this->get('full_name')->value) {
+ $name = $this->get('full_name')->value . ' ';
+ } else {
+ $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->type->entity->label() . ')';
$this->setName($name);
@@ -238,6 +242,24 @@ class OCActor extends RevisionableContentEntityBase implements OCActorInterface
'weight' => -10,
]);
+ // When configuring a person type, you will need to choose whether to have full name or first and last name fields displayed.
+ $fields['full_name'] = BaseFieldDefinition::create('string')
+ ->setDescription(t('The person\'s name.'))
+ ->setLabel(t('Name'))
+ ->setRevisionable(TRUE)
+ ->setSettings([
+ 'max_length' => 20,
+ 'text_processing' => 0,
+ ])
+ ->setDisplayConfigurable("form", true)
+ ->setDisplayConfigurable("view", true)
+ ->setDefaultValue('')
+ ->setDisplayOptions('form', [
+ 'type' => 'string_textfield',
+ 'weight' => -50,
+ ])
+ ->setRequired(TRUE);
+
$fields['first_name'] = BaseFieldDefinition::create('string')
->setLabel(t('First Name'))
->setDescription(t("The person's first name."))
diff --git a/modules/opencase_entities/src/Entity/OCActorType.php b/modules/opencase_entities/src/Entity/OCActorType.php
index 299034e..0186825 100644
--- a/modules/opencase_entities/src/Entity/OCActorType.php
+++ b/modules/opencase_entities/src/Entity/OCActorType.php
@@ -24,7 +24,7 @@ use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
* },
* },
* config_prefix = "oc_actor_type",
- * admin_permission = "administer opencase entity bundles",
+ * admin_permission = "administer actor bundles",
* bundle_of = "oc_actor",
* entity_keys = {
* "id" = "id",
diff --git a/modules/opencase_entities/src/Entity/OCBankAccount.php b/modules/opencase_entities/src/Entity/OCBankAccount.php
index 452a6a8..a237525 100644
--- a/modules/opencase_entities/src/Entity/OCBankAccount.php
+++ b/modules/opencase_entities/src/Entity/OCBankAccount.php
@@ -144,24 +144,7 @@ class OCBankAccount extends ContentEntityBase implements OCBankAccountInterface
->setDescription(t('The user ID of author of the Bank Account entity.'))
->setRevisionable(TRUE)
->setSetting('target_type', 'user')
- ->setSetting('handler', 'default')
- ->setDisplayOptions('view', [
- 'label' => 'hidden',
- 'type' => 'author',
- 'weight' => 0,
- ])
- ->setDisplayOptions('form', [
- 'type' => 'entity_reference_autocomplete',
- 'weight' => 5,
- 'settings' => [
- 'match_operator' => 'CONTAINS',
- 'size' => '60',
- 'autocomplete_type' => 'tags',
- 'placeholder' => '',
- ],
- ])
- ->setDisplayConfigurable('form', TRUE)
- ->setDisplayConfigurable('view', TRUE);
+ ->setSetting('handler', 'default');
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
diff --git a/modules/opencase_entities/src/Entity/OCCaseType.php b/modules/opencase_entities/src/Entity/OCCaseType.php
index 1eedf4f..a65b5be 100644
--- a/modules/opencase_entities/src/Entity/OCCaseType.php
+++ b/modules/opencase_entities/src/Entity/OCCaseType.php
@@ -24,7 +24,7 @@ use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
* },
* },
* config_prefix = "oc_case_type",
- * admin_permission = "administer opencase entity bundles",
+ * admin_permission = "administer case bundles",
* bundle_of = "oc_case",
* entity_keys = {
* "id" = "id",
diff --git a/modules/opencase_no_cases/src/Plugin/Block/ContextualMenu.php b/modules/opencase_no_cases/src/Plugin/Block/ContextualMenu.php
index dffc8e1..8de07ca 100644
--- a/modules/opencase_no_cases/src/Plugin/Block/ContextualMenu.php
+++ b/modules/opencase_no_cases/src/Plugin/Block/ContextualMenu.php
@@ -49,15 +49,16 @@ class ContextualMenu extends BlockBase {
*/
private function generateLinksForAddingNewActivities($title, $query = []) {
$title = t($title);
- $markup = "$title:
";
+ $markup = "
$title: ";
$allActivityTypes = \Drupal::service('entity_type.bundle.info')->getBundleInfo('oc_activity');
foreach($allActivityTypes as $machine_name => $activityType) {
$label = $activityType['label'];
$url = \Drupal\Core\Url::fromRoute("entity.oc_activity.add_form", ['oc_activity_type' => $machine_name]);
$url->setOption('query', $query);
$link = \Drupal\Core\Link::fromTextAndUrl($label, $url)->toString();
- $markup .= "
$link
";
+ $markup .= " $link";
}
+ $markup .= "
";
return "$markup
";
}
}
diff --git a/opencase.links.menu.yml b/opencase.links.menu.yml
index cfadf11..dc45406 100644
--- a/opencase.links.menu.yml
+++ b/opencase.links.menu.yml
@@ -50,13 +50,6 @@ opencase.manage_person_types:
parent: opencase.opencase_admin_menu
url: internal:/admin/opencase/oc_actor_type
weight: 1
-opencase.manage_case_types:
- title: 'Manage case types'
- description: 'Configure types of cases and their fields'
- menu_name: opencase
- parent: opencase.opencase_admin_menu
- url: internal:/admin/opencase/oc_case_type
- weight: 2
opencase.manage_activity_types:
title: 'Manage activity types'
description: 'Configure types of activities and their fields'