Compare commits
28 Commits
42f4b124d0
...
multiplefu
Author | SHA1 | Date | |
---|---|---|---|
fdf00d5c95 | |||
a4aa8444e3 | |||
a228ea5554 | |||
9862e65ea9 | |||
2e071af1b7 | |||
12788e7965 | |||
a5132bbcfc | |||
f671580ed7 | |||
9351768b25 | |||
1c61f2f0a4 | |||
13fb920e69 | |||
cfec9be05c | |||
d483b3f47e | |||
f6792e5053 | |||
804694c0cc | |||
f1965ff3c1 | |||
b000e9414b | |||
107d0d6a8c | |||
6e91a54dc4 | |||
82a44d3448 | |||
21c84e21d2 | |||
19e0718fb8 | |||
e5358503f4 | |||
f532286802 | |||
b0f3376c82 | |||
559ff4d83b | |||
e5b01eac53 | |||
c65295be62 |
@ -0,0 +1,65 @@
|
||||
uuid: ac6da2f0-4de2-4e8d-baf6-f7229b42616f
|
||||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- opencase_entities.oc_organisation_type.partner_organisation
|
||||
module:
|
||||
- file
|
||||
id: oc_organisation.partner_organisation.default
|
||||
targetEntityType: oc_organisation
|
||||
bundle: partner_organisation
|
||||
mode: default
|
||||
content:
|
||||
contact_name:
|
||||
type: string_textfield
|
||||
weight: 3
|
||||
region: content
|
||||
settings:
|
||||
size: 60
|
||||
placeholder: ''
|
||||
third_party_settings: { }
|
||||
email:
|
||||
type: string_textfield
|
||||
weight: 4
|
||||
region: content
|
||||
settings:
|
||||
size: 60
|
||||
placeholder: ''
|
||||
third_party_settings: { }
|
||||
name:
|
||||
type: string_textfield
|
||||
weight: 0
|
||||
region: content
|
||||
settings:
|
||||
size: 60
|
||||
placeholder: ''
|
||||
third_party_settings: { }
|
||||
notes:
|
||||
type: string_textarea
|
||||
weight: 2
|
||||
region: content
|
||||
settings:
|
||||
rows: 5
|
||||
placeholder: ''
|
||||
third_party_settings: { }
|
||||
website:
|
||||
type: string_textfield
|
||||
weight: 1
|
||||
region: content
|
||||
settings:
|
||||
size: 60
|
||||
placeholder: ''
|
||||
third_party_settings: { }
|
||||
hidden:
|
||||
billing_contact_name: true
|
||||
billing_email: true
|
||||
billing_phone: true
|
||||
billing_post_code: true
|
||||
billing_postal_address: true
|
||||
contact_role: true
|
||||
phone: true
|
||||
post_code: true
|
||||
postal_address: true
|
||||
revision_log: true
|
||||
status: true
|
@ -0,0 +1,57 @@
|
||||
uuid: 96b9f3c8-1433-4915-9656-4547eb1bc899
|
||||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- opencase_entities.oc_organisation_type.partner_organisation
|
||||
module:
|
||||
- file
|
||||
id: oc_organisation.partner_organisation.default
|
||||
targetEntityType: oc_organisation
|
||||
bundle: partner_organisation
|
||||
mode: default
|
||||
content:
|
||||
contact_name:
|
||||
type: string
|
||||
label: above
|
||||
settings:
|
||||
link_to_entity: false
|
||||
third_party_settings: { }
|
||||
weight: 2
|
||||
region: content
|
||||
email:
|
||||
type: string
|
||||
label: above
|
||||
settings:
|
||||
link_to_entity: false
|
||||
third_party_settings: { }
|
||||
weight: 3
|
||||
region: content
|
||||
notes:
|
||||
type: basic_string
|
||||
label: above
|
||||
settings: { }
|
||||
third_party_settings: { }
|
||||
weight: 1
|
||||
region: content
|
||||
website:
|
||||
type: string
|
||||
label: above
|
||||
settings:
|
||||
link_to_entity: false
|
||||
third_party_settings: { }
|
||||
weight: 0
|
||||
region: content
|
||||
hidden:
|
||||
billing_contact_name: true
|
||||
billing_email: true
|
||||
billing_phone: true
|
||||
billing_post_code: true
|
||||
billing_postal_address: true
|
||||
contact_role: true
|
||||
name: true
|
||||
phone: true
|
||||
post_code: true
|
||||
postal_address: true
|
||||
search_api_excerpt: true
|
||||
status: true
|
@ -81,6 +81,7 @@ module:
|
||||
views_aggregator: 0
|
||||
views_aggregator_more_functions: 0
|
||||
views_autosubmit: 0
|
||||
views_contextual_filters_or: 0
|
||||
views_data_export: 0
|
||||
views_summarize: 0
|
||||
views_ui: 0
|
||||
|
@ -3,4 +3,4 @@ langcode: en
|
||||
status: true
|
||||
dependencies: { }
|
||||
id: partner_organisation
|
||||
label: 'Partner Organisation'
|
||||
label: 'Partner organisation'
|
||||
|
@ -29,6 +29,7 @@ permissions:
|
||||
- 'add client entities'
|
||||
- 'add equal opps entities'
|
||||
- 'add event entities'
|
||||
- 'add organisation entities'
|
||||
- 'add staff_member entities'
|
||||
- 'add volunteer entities'
|
||||
- 'edit activity entities'
|
||||
|
@ -155,6 +155,71 @@ display:
|
||||
multi_type: separator
|
||||
separator: ', '
|
||||
field_api_classes: false
|
||||
oc_target:
|
||||
id: oc_target
|
||||
table: oc_activity_field_data
|
||||
field: oc_target
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
entity_type: oc_activity
|
||||
entity_field: oc_target
|
||||
plugin_id: field
|
||||
label: Target
|
||||
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
|
||||
oc_provider:
|
||||
id: oc_provider
|
||||
table: oc_activity_field_data
|
||||
@ -426,6 +491,44 @@ display:
|
||||
validate_options: { }
|
||||
break_phrase: false
|
||||
not: false
|
||||
oc_provider:
|
||||
id: oc_provider
|
||||
table: oc_activity_field_data
|
||||
field: oc_provider
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
entity_type: oc_activity
|
||||
entity_field: oc_provider
|
||||
plugin_id: numeric
|
||||
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
|
||||
override: false
|
||||
items_per_page: 25
|
||||
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
|
||||
filters: { }
|
||||
style:
|
||||
type: table
|
||||
@ -434,11 +537,51 @@ display:
|
||||
row_class: ''
|
||||
default_row_class: true
|
||||
columns:
|
||||
type: type
|
||||
activity_date_time: activity_date_time
|
||||
oc_target: oc_target
|
||||
oc_provider: oc_provider
|
||||
name: name
|
||||
description: description
|
||||
default: '-1'
|
||||
info:
|
||||
type:
|
||||
sortable: true
|
||||
default_sort_order: asc
|
||||
align: ''
|
||||
separator: ''
|
||||
empty_column: false
|
||||
responsive: ''
|
||||
activity_date_time:
|
||||
sortable: true
|
||||
default_sort_order: desc
|
||||
align: ''
|
||||
separator: ''
|
||||
empty_column: false
|
||||
responsive: ''
|
||||
oc_target:
|
||||
sortable: true
|
||||
default_sort_order: asc
|
||||
align: ''
|
||||
separator: ''
|
||||
empty_column: false
|
||||
responsive: ''
|
||||
oc_provider:
|
||||
sortable: true
|
||||
default_sort_order: asc
|
||||
align: ''
|
||||
separator: ''
|
||||
empty_column: false
|
||||
responsive: ''
|
||||
name:
|
||||
sortable: false
|
||||
sortable: true
|
||||
default_sort_order: asc
|
||||
align: ''
|
||||
separator: ''
|
||||
empty_column: false
|
||||
responsive: ''
|
||||
description:
|
||||
sortable: true
|
||||
default_sort_order: asc
|
||||
align: ''
|
||||
separator: ''
|
||||
@ -465,6 +608,7 @@ display:
|
||||
distinct: false
|
||||
replica: false
|
||||
query_tags: { }
|
||||
contextual_filters_or: true
|
||||
relationships: { }
|
||||
header: { }
|
||||
footer: { }
|
||||
|
@ -191,7 +191,22 @@ display:
|
||||
type: tag
|
||||
options: { }
|
||||
empty: { }
|
||||
sorts: { }
|
||||
sorts:
|
||||
name:
|
||||
id: name
|
||||
table: oc_actor_field_data
|
||||
field: name
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
entity_type: oc_actor
|
||||
entity_field: name
|
||||
plugin_id: standard
|
||||
order: ASC
|
||||
expose:
|
||||
label: ''
|
||||
field_identifier: ''
|
||||
exposed: false
|
||||
arguments:
|
||||
type:
|
||||
id: type
|
||||
|
@ -8,6 +8,7 @@
|
||||
*/
|
||||
|
||||
use Drupal\Core\Render\Element;
|
||||
use Drupal\opencase;
|
||||
|
||||
/**
|
||||
* Prepares variables for Case templates.
|
||||
@ -20,18 +21,6 @@ use Drupal\Core\Render\Element;
|
||||
* - attributes: HTML attributes for the containing element.
|
||||
*/
|
||||
function template_preprocess_oc_case(array &$variables) {
|
||||
// Separate the fields into two sections to be displayed in two columns.
|
||||
// Remove the name (title) field as this is displayed anyway.
|
||||
$variables['id'] = $variables['elements']['#oc_case']->get('id')[0]->get('value')->getValue();
|
||||
$variables['base_fields'] = array();
|
||||
$variables['other_fields'] = array();
|
||||
foreach (Element::children($variables['elements']) as $key) {
|
||||
$variables['content'][$key] = $variables['elements'][$key];
|
||||
if (in_array($key, ['created', 'changed', 'files', 'actors_involved', 'status', 'user_id'])) {
|
||||
$variables['base_fields'][$key] = $variables['elements'][$key];
|
||||
} else {
|
||||
$variables['other_fields'][$key] = $variables['elements'][$key];
|
||||
unset($variables['other_fields']['name']);
|
||||
}
|
||||
}
|
||||
_template_preprocess_entity($variables);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,17 @@
|
||||
<?php
|
||||
use \Drupal\Core\Field\BaseFieldDefinition;
|
||||
|
||||
function opencase_cases_update_90005() {
|
||||
$field_storage_definition = BaseFieldDefinition::create('integer')
|
||||
->setLabel(t('Number of Cases'))
|
||||
->setRevisionable(TRUE)
|
||||
->setDisplayConfigurable('view', true);
|
||||
|
||||
\Drupal::entityDefinitionUpdateManager()
|
||||
->installFieldStorageDefinition('total_cases', 'oc_actor', 'opencase_cases', $field_storage_definition);
|
||||
}
|
||||
|
||||
|
||||
function opencase_cases_update_90004() {
|
||||
$field_storage_definition = BaseFieldDefinition::create('string_long')
|
||||
->setRevisionable(TRUE)
|
||||
|
@ -68,19 +68,6 @@ function opencase_cases_theme() {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Drupal\opencase_cases\entity\OCActivity[]
|
||||
*/
|
||||
function opencase_cases_get_activities(Drupal\opencase_cases\entity\OCCase $case): array {
|
||||
$query = \Drupal::entityQuery('oc_activity')
|
||||
->condition('oc_case.target_id', $case->id());
|
||||
$activity_ids = $query->execute();
|
||||
$activities = [];
|
||||
foreach($activity_ids as $id) {
|
||||
$activities[] = Drupal\opencase_entities\Entity\OCActivity::load($id);
|
||||
}
|
||||
return $activities;
|
||||
}
|
||||
|
||||
function opencase_cases_oc_case_fee_update(Drupal\opencase_cases\entity\OCCaseFee $case_fee): void {
|
||||
$case = $case_fee->getCase();
|
||||
@ -119,13 +106,6 @@ function opencase_cases_entity_base_field_info($entity_type) {
|
||||
return $fields;
|
||||
}
|
||||
|
||||
// When deleting a case, delete the activities associated with it
|
||||
function opencase_cases_oc_case_delete(Drupal\opencase_cases\Entity\OCCase $case): void {
|
||||
$activities = opencase_cases_get_activities($case);
|
||||
foreach ($activities as $activity) {
|
||||
$activity->delete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -91,6 +91,24 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface
|
||||
];
|
||||
}
|
||||
|
||||
public function deleteCaseProvisions(): void {
|
||||
$this->deleteChildren('oc_case_provision');
|
||||
}
|
||||
public function deleteActivities(): void {
|
||||
$this->deleteChildren('oc_activity');
|
||||
}
|
||||
|
||||
|
||||
public function deleteChildren($child_entity_type):void {
|
||||
$query = \Drupal::entityQuery($child_entity_type)
|
||||
->condition('oc_case.target_id', $this->id());
|
||||
$ids = $query->execute();
|
||||
foreach($ids as $id) {
|
||||
\Drupal::entityTypeManager()
|
||||
->getStorage($child_entity_type)
|
||||
->load($id)->delete();
|
||||
}
|
||||
}
|
||||
|
||||
public static function defaultTarget()
|
||||
{
|
||||
|
@ -16,7 +16,10 @@
|
||||
*/
|
||||
#}
|
||||
<div{{ attributes.addClass('oc_case') }}>
|
||||
{% if content %}
|
||||
{{- content -}}
|
||||
{% if normal_fields %}
|
||||
<div id='static_data'>{{- normal_fields -}}</div>
|
||||
{% endif %}
|
||||
{% if extra_fields %}
|
||||
<div id='dynamic_data'>{{- extra_fields -}}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\opencase_defaults\Functional;
|
||||
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Simple test to ensure that main page loads with module enabled.
|
||||
*
|
||||
* @group opencase_defaults
|
||||
*/
|
||||
class LoadTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['opencase_defaults'];
|
||||
|
||||
/**
|
||||
* A user with permission to administer site configuration.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->user = $this->drupalCreateUser(['administer site configuration']);
|
||||
$this->drupalLogin($this->user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the home page loads with a 200 response.
|
||||
*/
|
||||
public function testLoad() {
|
||||
$this->drupalGet(Url::fromRoute('<front>'));
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
}
|
||||
|
||||
}
|
@ -20,17 +20,5 @@ use Drupal\Core\Render\Element;
|
||||
* - attributes: HTML attributes for the containing element.
|
||||
*/
|
||||
function template_preprocess_oc_actor(array &$variables) {
|
||||
// Make the id available to the template and also separate the fields
|
||||
// into two sections to be displayed in two columns.
|
||||
$variables['id'] = $variables['elements']['#oc_actor']->get('id')[0]->get('value')->getValue();
|
||||
$variables['contact_details'] = array();
|
||||
$variables['fields_other_than_contact_details'] = array();
|
||||
foreach (Element::children($variables['elements']) as $key) {
|
||||
$variables['content'][$key] = $variables['elements'][$key];
|
||||
if (in_array($key, ['email', 'phone', 'phone2', 'postal_address', 'post_code'])) {
|
||||
$variables['contact_details'][$key] = $variables['elements'][$key];
|
||||
} else {
|
||||
$variables['fields_other_than_contact_details'][$key] = $variables['elements'][$key];
|
||||
}
|
||||
}
|
||||
_template_preprocess_entity($variables);
|
||||
}
|
||||
|
@ -20,11 +20,5 @@ use Drupal\Core\Render\Element;
|
||||
* - attributes: HTML attributes for the containing element.
|
||||
*/
|
||||
function template_preprocess_oc_organisation(array &$variables) {
|
||||
// Fetch OCOrganisation Entity Object.
|
||||
$oc_organisation = $variables['elements']['#oc_organisation'];
|
||||
|
||||
// Helpful $content variable for templates.
|
||||
foreach (Element::children($variables['elements']) as $key) {
|
||||
$variables['content'][$key] = $variables['elements'][$key];
|
||||
}
|
||||
_template_preprocess_entity($variables);
|
||||
}
|
||||
|
@ -247,7 +247,12 @@ class OCActivity extends RevisionableContentEntityBase implements OCActivityInte
|
||||
->setLabel(t('Provider'))
|
||||
->setRevisionable(TRUE)
|
||||
->setSetting('target_type', 'oc_actor')
|
||||
->setSetting('handler', 'default')
|
||||
->setSetting('handler', 'views')
|
||||
->setSetting('handler_settings', [
|
||||
'view' => [
|
||||
'view_name' => 'case_providers',
|
||||
'display_name' => 'entity_reference_1'
|
||||
]])
|
||||
->setDefaultValueCallback('\Drupal\opencase_entities\Entity\OCActivity::loggedInActorId')
|
||||
->setDisplayConfigurable('form', true)
|
||||
->setDisplayConfigurable('view', true);
|
||||
|
@ -208,15 +208,17 @@ class OCActor extends RevisionableContentEntityBase implements OCActorInterface
|
||||
}
|
||||
|
||||
|
||||
public function getCountOfCaseProvisions(array $conditions = []): int {
|
||||
public function getCountOfCaseProvisions(array $conditionsToApplyToCaseProvisionQuery = []): int {
|
||||
$query = \Drupal::entityQuery('oc_case_provision');
|
||||
$query->condition('oc_provider', $this->id());
|
||||
// foreach($conditions as $condition) {
|
||||
// $query->condition($condition);
|
||||
// }
|
||||
return count($query->execute());
|
||||
}
|
||||
|
||||
public function calculateTotalCases(): void {
|
||||
$this->set('total_cases', $this->getCountOfCaseProvisions());
|
||||
$this->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -16,7 +16,10 @@
|
||||
*/
|
||||
#}
|
||||
<div{{ attributes.addClass('oc_actor') }}>
|
||||
{% if content %}
|
||||
{{- content -}}
|
||||
{% if normal_fields %}
|
||||
<div id='static_data'>{{- normal_fields -}}</div>
|
||||
{% endif %}
|
||||
{% if extra_fields %}
|
||||
<div id='dynamic_data'>{{- extra_fields -}}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
@ -16,7 +16,10 @@
|
||||
*/
|
||||
#}
|
||||
<div{{ attributes.addClass('oc_organisation') }}>
|
||||
{% if content %}
|
||||
{{- content -}}
|
||||
{% if normal_fields %}
|
||||
<div id='static_data'>{{- normal_fields -}}</div>
|
||||
{% endif %}
|
||||
{% if extra_fields %}
|
||||
<div id='dynamic_data'>{{- extra_fields -}}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\opencase_entities\Functional;
|
||||
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Simple test to ensure that main page loads with module enabled.
|
||||
*
|
||||
* @group opencase_entities
|
||||
*/
|
||||
class LoadTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['opencase_entities'];
|
||||
|
||||
/**
|
||||
* A user with permission to administer site configuration.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->user = $this->drupalCreateUser(['administer site configuration']);
|
||||
$this->drupalLogin($this->user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the home page loads with a 200 response.
|
||||
*/
|
||||
public function testLoad() {
|
||||
$this->drupalGet(Url::fromRoute('<front>'));
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
}
|
||||
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
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: { }
|
@ -1,318 +0,0 @@
|
||||
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: { }
|
@ -1,8 +0,0 @@
|
||||
name: 'OpenCase No Cases'
|
||||
type: module
|
||||
description: 'Enable EITHER this OR "OpenCase Cases". This one links activities directly to people, which is simpler and therefore what some orgs prefer.'
|
||||
core: 8.x
|
||||
package: 'OpenCase'
|
||||
dependencies:
|
||||
- opencase_entities
|
||||
- route_condition
|
@ -1,105 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains opencase_no_cases.module.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
|
||||
/**
|
||||
* Implements hook_help().
|
||||
*/
|
||||
function opencase_no_cases_help($route_name, RouteMatchInterface $route_match) {
|
||||
switch ($route_name) {
|
||||
// Main module help for the opencase_no_cases module.
|
||||
case 'help.page.opencase_no_cases':
|
||||
$output = '';
|
||||
$output .= '<h3>' . t('About') . '</h3>';
|
||||
$output .= '<p>' . t('Enable EITHER this OR "OpenCase Cases". This one links activities directly to people, which is simpler and therefore what some orgs prefer.') . '</p>';
|
||||
return $output;
|
||||
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
function opencase_no_cases_entity_base_field_info($entity_type) {
|
||||
if ($entity_type->id() === 'oc_activity') {
|
||||
$fields = array();
|
||||
$fields['actors_involved'] = BaseFieldDefinition::create('entity_reference')
|
||||
->setLabel(t('Participants'))
|
||||
->setDescription(t('People involved in this activity. To add one, start typing their name.'))
|
||||
->setSetting('target_type', 'oc_actor')
|
||||
->setSetting('handler', 'default')
|
||||
->setTranslatable(TRUE)
|
||||
->setCardinality(-1)
|
||||
->setDisplayOptions('form', [
|
||||
'label' => 'above',
|
||||
'type' => 'hidden',
|
||||
'weight' => -100,
|
||||
'settings' => [
|
||||
'match_operator' => 'CONTAINS',
|
||||
'size' => '60',
|
||||
'autocomplete_type' => 'tags',
|
||||
'placeholder' => '',
|
||||
],
|
||||
])
|
||||
->setDisplayOptions('view', [
|
||||
'label' => 'above',
|
||||
'weight' => -100,
|
||||
])
|
||||
->setDefaultValueCallback('opencase_no_cases_actors_involved_callback')
|
||||
->setRequired(TRUE);
|
||||
}
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* When creating an activity, it sets the first involved party to the actor
|
||||
* id from the URL, and the second to the author's linked actor
|
||||
* (if it exists and is different)
|
||||
*/
|
||||
function opencase_no_cases_actors_involved_callback() {
|
||||
$author_linked_actor_id = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id())->get('field_linked_opencase_actor')->target_id;
|
||||
$currently_viewed_actor_id = \Drupal::request()->query->get('actor_id');
|
||||
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('<front>');
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
@ -39,7 +39,7 @@ opencase.add_events_links:
|
||||
menu_name: opencase
|
||||
parent: opencase.opencase_add_new_things_menu
|
||||
opencase.add_equal_opps:
|
||||
title: 'Equal Opportunies record'
|
||||
title: 'Equal Opps record'
|
||||
menu_name: opencase
|
||||
url: internal:/opencase/oc_equal_opps/add
|
||||
parent: opencase.opencase_add_new_things_menu
|
||||
|
@ -4,8 +4,11 @@
|
||||
* Contains opencase.module.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\Render\Element;
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\opencase_cases\Entity\OCCase;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\opencase_cases\Entity\OCCaseProvision;
|
||||
|
||||
/**
|
||||
* Implements hook_element_info_alter().
|
||||
@ -14,6 +17,18 @@ function opencase_element_info_alter(array &$types) {
|
||||
$types['datetime']['#process'][] = 'opencase_process_element';
|
||||
}
|
||||
|
||||
function _template_preprocess_entity(&$variables) {
|
||||
foreach (Element::children($variables['elements']) as $key) {
|
||||
if (is_extra_field($variables['elements'][$key])) {
|
||||
$variables['extra_fields'][$key] = $variables['elements'][$key];
|
||||
} else {
|
||||
$variables['normal_fields'][$key] = $variables['elements'][$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
function is_extra_field($element){
|
||||
return array_key_exists('#field', $element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Element process callback for datetime fields. Removes the seconds part.
|
||||
@ -31,6 +46,21 @@ function opencase_process_element($element) {
|
||||
$element['time']['#attributes']['step'] = 60;
|
||||
return $element;
|
||||
}
|
||||
function opencase_oc_case_provision_insert(OCCaseProvision $case_provision): void {
|
||||
$case_provision->oc_provider->entity->calculateTotalCases();
|
||||
}
|
||||
function opencase_oc_case_provision_delete(OCCaseProvision $case_provision): void {
|
||||
$case_provision->oc_provider->entity->calculateTotalCases();
|
||||
}
|
||||
function opencase_oc_case_provision_update(OCCaseProvision $case_provision): void {
|
||||
$case_provision->oc_provider->entity->calculateTotalCases();
|
||||
$case_provision->original->oc_provider->entity->calculateTotalCases();
|
||||
}
|
||||
|
||||
function opencase_oc_case_delete(OCCase $case): void {
|
||||
$case->deleteCaseProvisions();
|
||||
$case->deleteActivities();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_page_attachments
|
||||
@ -127,6 +157,19 @@ function opencase_entity_field_access($operation, \Drupal\Core\Field\FieldDefini
|
||||
return AccessResult::neutral();
|
||||
}
|
||||
|
||||
/*
|
||||
Implementation of hook_relevant_activity_type_ids which is a custom hook invoked in the AddActivity block.
|
||||
*/
|
||||
function opencase_relevant_activity_type_ids($actorTypeID) {
|
||||
switch ($actorTypeID) {
|
||||
case 'volunteer':
|
||||
return ['email', 'phone_call', 'supervision'];
|
||||
case 'client':
|
||||
return ['email', 'lete', 'phone_call', 'case_note', 'destitution_funds_provided', 'research', 'application'];
|
||||
case 'staff_member':
|
||||
return ['application', 'interview'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_form_alter()
|
||||
|
@ -4,9 +4,8 @@ namespace Drupal\opencase;
|
||||
use Drupal\user\Entity\User;
|
||||
|
||||
class EmailAlerter {
|
||||
public function send_email_to_users_with_role(array $params, string $key, string $role): void {
|
||||
public function send_email_to_users_with_role(array $params, string $key, string $role, string $module): void {
|
||||
$mailManager = \Drupal::service('plugin.manager.mail');
|
||||
$module = 'goodnightout_opencase';
|
||||
$to = implode(',', $this->get_email_addresses_of_users_with_role($role));
|
||||
$send = true;
|
||||
$result = $mailManager->mail($module, $key, $to, NULL, $params, NULL, $send);
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace Drupal\opencase\Plugin\Block;
|
||||
|
||||
@ -19,9 +19,11 @@ class AddActivity extends BlockBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function build():array {
|
||||
$target_id = \Drupal::routeMatch()->getParameter('oc_actor')->id();
|
||||
$activity_types = \Drupal::service('entity_type.bundle.info')->getBundleInfo('oc_activity');
|
||||
$actor = \Drupal::routeMatch()->getParameter('oc_actor');
|
||||
$target_id = $actor->id();
|
||||
$actorType = $actor->bundle();
|
||||
$markup = "<ul>";
|
||||
$activity_types = $this->getActivityTypesToDisplay($actorType);
|
||||
foreach($activity_types as $id => $info) {
|
||||
$label = $info['label'];
|
||||
$markup .= "<li><a href='/opencase/oc_activity/add/$id?target_id=$target_id&destination=/opencase/oc_actor/$target_id'>$label</a></li>";
|
||||
@ -34,4 +36,17 @@ class AddActivity extends BlockBase {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private function getActivityTypesToDisplay(string $actorType): array {
|
||||
// Client modules will provide a list of what activity types (bundles) are relevant for each actor type.
|
||||
// Check if they are implemented, and if so display them.
|
||||
$implemented_activity_types = \Drupal::service('entity_type.bundle.info')->getBundleInfo('oc_activity');
|
||||
$relevant_activity_type_ids = \Drupal::moduleHandler()->invokeAll('relevant_activity_type_ids', [$actorType]);
|
||||
$activity_types_to_display = [];
|
||||
foreach ($relevant_activity_type_ids as $type_id) {
|
||||
if (array_key_exists($type_id, $implemented_activity_types)) {
|
||||
$activity_types_to_display[$type_id] = $implemented_activity_types[$type_id];
|
||||
}
|
||||
}
|
||||
return $activity_types_to_display;
|
||||
}
|
||||
}
|
||||
|
@ -1,37 +1,49 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace Drupal\opencase;
|
||||
use Drupal;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\opencase\Utils;
|
||||
|
||||
final class TimeBasedFieldUpdater {
|
||||
private string $date_field;
|
||||
private string $entity_type;
|
||||
private array $conditions;
|
||||
private string $date_format;
|
||||
|
||||
final public function __construct($entity_type, $date_field, $conditions = [], $date_format = 'Y-m-d')
|
||||
private EntityTypeManagerInterface $entityTypeManager;
|
||||
private string $date_field;
|
||||
private Utils $utils;
|
||||
private string $entity_type;
|
||||
private string $date_format;
|
||||
private string $bundle;
|
||||
|
||||
final public function __construct(
|
||||
EntityTypeManagerInterface $entityTypeManager,
|
||||
Utils $utils,
|
||||
string $entity_type, string $bundle, string $date_field, string $date_format = 'Y-m-d'
|
||||
)
|
||||
{
|
||||
$this->entityTypeManager = $entityTypeManager;
|
||||
$this->utils = $utils;
|
||||
$this->date_field = $date_field;
|
||||
$this->conditions = $conditions;
|
||||
$this->date_format = $date_format;
|
||||
$this->entity_type = $entity_type;
|
||||
$this->bundle = $bundle;
|
||||
}
|
||||
|
||||
final public function update($time_elapsed, $old_values, $new_values): void {
|
||||
$query = Drupal::entityQuery($this->entity_type);
|
||||
foreach($this->conditions as $cond_field=>$cond_value) {
|
||||
$query->condition($cond_field, $cond_value);
|
||||
final public function update(array $conditions, string $time_elapsed, array $new_values): void {
|
||||
$query = $this->entityTypeManager->getStorage($this->entity_type)->getQuery();
|
||||
$conditions[] = [$this->date_field, date($this->date_format, strtotime('-'.$time_elapsed)), "<"];
|
||||
$conditions[] = ['type', $this->bundle, '='];
|
||||
|
||||
foreach ($conditions as $condition) {
|
||||
$query->condition($condition[0], $condition[1], $condition[2] ?? "=");
|
||||
}
|
||||
foreach($old_values as $old_field=>$old_value) {
|
||||
$query->condition($old_field, $old_value);
|
||||
}
|
||||
$query->condition($this->date_field, date($this->date_format, strtotime('-'.$time_elapsed)), "<");
|
||||
foreach($query->execute() as $id) {
|
||||
$entity = Drupal::entityTypeManager()->getStorage($this->entity_type)->load($id);
|
||||
$this->updateEntity($id, $new_values);
|
||||
}
|
||||
}
|
||||
private function updateEntity(int $entity_id, array $new_values): void {
|
||||
$entity = $this->entityTypeManager->getStorage($this->entity_type)->load($entity_id);
|
||||
foreach($new_values as $new_field=>$new_value) {
|
||||
$entity->set($new_field, $new_value);
|
||||
$entity->$new_field = $new_value;
|
||||
}
|
||||
$entity->save();
|
||||
}
|
||||
}
|
||||
}
|
42
src/Utils.php
Normal file
42
src/Utils.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php declare(strict_types =1);
|
||||
|
||||
namespace Drupal\opencase;
|
||||
|
||||
use \Drupal;
|
||||
use Drupal\Core\Entity\Query\QueryInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
|
||||
class Utils {
|
||||
|
||||
public function __construct(
|
||||
EntityTypeManagerInterface $entityTypeManager = null
|
||||
) {
|
||||
if ($entityTypeManager == null) {
|
||||
$entityTypeManager = Drupal::entityTypeManager();
|
||||
}
|
||||
$this->entityTypeManager = $entityTypeManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility: find term by name and vid.
|
||||
*
|
||||
* @param string $name
|
||||
* Term name.
|
||||
* @param string $vid
|
||||
* Term vid.
|
||||
* @return int
|
||||
* Term id, or 0 if none.
|
||||
*/
|
||||
public function getTidByName(string $name, string $vid):int {
|
||||
if (empty($name) || empty($vid)) {
|
||||
return 0;
|
||||
}
|
||||
$properties = [
|
||||
'name' => $name,
|
||||
'vid' => $vid,
|
||||
];
|
||||
$terms = $this->entityTypeManager->getStorage('taxonomy_term')->loadByProperties($properties);
|
||||
$term = reset($terms);
|
||||
return (int)(!empty($term) ? $term->id() : 0);
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\opencase\Functional;
|
||||
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Simple test to ensure that main page loads with module enabled.
|
||||
*
|
||||
* @group opencase
|
||||
*/
|
||||
class LoadTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['opencase'];
|
||||
|
||||
/**
|
||||
* A user with permission to administer site configuration.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->user = $this->drupalCreateUser(['administer site configuration']);
|
||||
$this->drupalLogin($this->user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the home page loads with a 200 response.
|
||||
*/
|
||||
public function testLoad() {
|
||||
$this->drupalGet(Url::fromRoute('<front>'));
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
}
|
||||
|
||||
}
|
60
tests/src/Unit/TimeBasedFieldUpdaterTest.php
Normal file
60
tests/src/Unit/TimeBasedFieldUpdaterTest.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace Drupal\Tests\opencase\Unit;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\opencase\TimeBasedFieldUpdater;
|
||||
|
||||
class TimeBasedFieldUpdaterTest extends UnitTestCase{
|
||||
|
||||
function setUp():void {
|
||||
/** @var \Drupal\opencase\Utils&\PHPUnit\Framework\MockObject\MockObject $utils */
|
||||
$this->utils = $this->getMockBuilder('\\Drupal\\opencase\\Utils')->disableOriginalConstructor()->getMock();
|
||||
/** @var \Drupal\core\Entity\EntityTypeManagerInterface&\PHPUnit\Framework\MockObject\MockObject $entityTypeManager */
|
||||
$this->entityTypeManager = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityTypeManager')->disableOriginalConstructor()->getMock();
|
||||
$this->storage = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityStorageInterface')->getMock();
|
||||
$this->query = $this->getMockBuilder('\\Drupal\\Core\\Entity\\Query\\QueryInterface')->getMock();
|
||||
$this->entityTypeManager->method('getStorage')->willReturn($this->storage);
|
||||
$this->storage->method('getQuery')->willReturn($this->query);
|
||||
$this->updater = new TimeBasedFieldUpdater($this->entityTypeManager, $this->utils, 'dummy_entity_type', 'dummy_bundle', 'dummy_date_field');
|
||||
|
||||
}
|
||||
function testFieldIsUpdatedOnEntityReturnedByQuery():void {
|
||||
$this->query->method('execute')->willReturn([1]);
|
||||
$this->entity = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityBase')->disableOriginalConstructor()->getMock();
|
||||
$this->storage->expects($this->once())->method('load')->with(1)->willReturn($this->entity);
|
||||
$this->updater->update([], '3 months', ['dummy_field' => 4]);
|
||||
$this->assertEquals($this->entity->dummy_field, 4);
|
||||
}
|
||||
function testFieldIsUpdatedOnAllEntitiesReturnedByQuery():void {
|
||||
$this->query->method('execute')->willReturn([1, 2]);
|
||||
$this->entity = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityBase')->disableOriginalConstructor()->getMock();
|
||||
$this->entity2 = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityBase')->disableOriginalConstructor()->getMock();
|
||||
$this->storage->method('load')->willReturnMap([[1, $this->entity], [2, $this-> entity2]]);
|
||||
$this->updater->update([], '3 months', ['dummy_field' => 4]);
|
||||
$this->assertEquals($this->entity->dummy_field, 4);
|
||||
$this->assertEquals($this->entity2->dummy_field, 4);
|
||||
}
|
||||
|
||||
function testMultipleFieldsAreUpdated(): void {
|
||||
$this->query->method('execute')->willReturn([1]);
|
||||
$this->entity = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityBase')->disableOriginalConstructor()->getMock();
|
||||
$this->storage->expects($this->once())->method('load')->with(1)->willReturn($this->entity);
|
||||
$this->updater->update([], '3 months', ['dummy_field' => 4, 'dummy_field_2' => 5]);
|
||||
$this->assertEquals($this->entity->dummy_field, 4);
|
||||
$this->assertEquals($this->entity->dummy_field_2, 5);
|
||||
|
||||
}
|
||||
|
||||
function testBundleAndDateAndExtraConditionsAreAllAddedAsQueryConditions(): void {
|
||||
$this->query->method('execute')->willReturn([]);
|
||||
|
||||
$this->query->expects($this->exactly(4))->method('condition')->withConsecutive(
|
||||
['dummy_field', 'dummy_value', '<'],
|
||||
['dummy_field_2', 'dummy_value_2', '='],
|
||||
['dummy_date_field', date('Y-m-d', strtotime('- 3 months')), "<"],
|
||||
['type', 'dummy_bundle', '=']);
|
||||
|
||||
$this->updater->update([['dummy_field', 'dummy_value', '<'], ['dummy_field_2', 'dummy_value_2', '='] ], '3 months', ['dummy_field' => 4]);
|
||||
}
|
||||
}
|
25
tests/src/Unit/UtilsTest.php
Normal file
25
tests/src/Unit/UtilsTest.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace Drupal\Tests\opencase\Unit;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\opencase\Utils;
|
||||
|
||||
class UtilsTest extends UnitTestCase{
|
||||
public function setUp(): void {
|
||||
/** @var \Drupal\core\Entity\EntityTypeManager&\PHPUnit\Framework\MockObject\MockObject $entityTypeManager */
|
||||
$this->entityTypeManager = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityTypeManager')->disableOriginalConstructor()->getMock();
|
||||
$this->utils = new Utils($this->entityTypeManager);
|
||||
$this->storage = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityStorageInterface')->getMock();
|
||||
$this->query = $this->getMockBuilder('\\Drupal\\Core\\Entity\\Query\\QueryInterface')->getMock();
|
||||
$this->entityTypeManager->method('getStorage')->willReturn($this->storage);
|
||||
}
|
||||
|
||||
public function testGetTidByNameGetsTid():void {
|
||||
$term_entity = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityBase')->disableOriginalConstructor()->getMock();
|
||||
$term_entity->expects($this->once())->method('id')->willReturn('3');
|
||||
$this->storage->expects($this->once())->method('loadByProperties')->with(['name' => 'foo', 'vid' => 'bar'])
|
||||
->willReturn([$term_entity]);
|
||||
$this->assertEquals($this->utils->getTidByName('foo', 'bar'), 3);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user