Compare commits
15 Commits
9351768b25
...
revisioner
Author | SHA1 | Date | |
---|---|---|---|
457b4ad694 | |||
780f144b52 | |||
33aec90a78 | |||
f9654bcd78 | |||
4852de71c7 | |||
fdf00d5c95 | |||
a4aa8444e3 | |||
a228ea5554 | |||
c29a480401 | |||
56bc7b83dd | |||
9862e65ea9 | |||
2e071af1b7 | |||
12788e7965 | |||
a5132bbcfc | |||
f671580ed7 |
@ -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)
|
||||
|
@ -56,10 +56,10 @@ class OCCaseRevisionRevertForm extends ConfirmFormBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('entity.manager')->getStorage('oc_case'),
|
||||
$container->get('date.formatter')
|
||||
);
|
||||
return new static($container
|
||||
->get('entity_type.manager')
|
||||
->getStorage('oc_case'), $container
|
||||
->get('date.formatter'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -57,7 +57,7 @@ class OCActivityRevisionRevertForm extends ConfirmFormBase {
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('entity.manager')->getStorage('oc_activity'),
|
||||
$container->get('entity_type.manager')->getStorage('oc_activity'),
|
||||
$container->get('date.formatter')
|
||||
);
|
||||
}
|
||||
|
@ -56,10 +56,10 @@ class OCActorRevisionRevertForm extends ConfirmFormBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('entity.manager')->getStorage('oc_actor'),
|
||||
$container->get('date.formatter')
|
||||
);
|
||||
return new static($container
|
||||
->get('entity_type.manager')
|
||||
->getStorage('oc_actor'), $container
|
||||
->get('date.formatter'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,14 +41,14 @@ class OCOrganisationRevisionRevertForm extends ConfirmFormBase {
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
$instance = parent::create($container);
|
||||
$instance->oCOrganisationStorage = $container->get('entity_type.manager')->getStorage('oc_organisation');
|
||||
$instance->OCOrganisationStorage = $container->get('entity_type.manager')->getStorage('oc_organisation');
|
||||
$instance->dateFormatter = $container->get('date.formatter');
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'oc_organisation_revision_revert_confirm';
|
||||
}
|
||||
|
@ -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>
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -14,11 +14,11 @@ final class TimeBasedFieldUpdater {
|
||||
private string $bundle;
|
||||
|
||||
final public function __construct(
|
||||
EntityTypeManagerInterface $entityTypeManager,
|
||||
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;
|
||||
@ -31,16 +31,19 @@ final class TimeBasedFieldUpdater {
|
||||
$query = $this->entityTypeManager->getStorage($this->entity_type)->getQuery();
|
||||
$conditions[] = [$this->date_field, date($this->date_format, strtotime('-'.$time_elapsed)), "<"];
|
||||
$conditions[] = ['type', $this->bundle, '='];
|
||||
$this->utils->addConditionsToQuery($query, $conditions);
|
||||
|
||||
foreach ($conditions as $condition) {
|
||||
$query->condition($condition[0], $condition[1], $condition[2] ?? "=");
|
||||
}
|
||||
foreach($query->execute() as $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->$new_field = $new_value;
|
||||
$entity->$new_field = $new_value;
|
||||
}
|
||||
$entity->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,8 @@
|
||||
namespace Drupal\opencase;
|
||||
|
||||
use \Drupal;
|
||||
use Drupal\Core\Entity\EntityTypeManager;
|
||||
use Drupal\Core\Entity\Query\QueryInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use RuntimeException;
|
||||
|
||||
class Utils {
|
||||
|
||||
@ -19,15 +17,6 @@ class Utils {
|
||||
$this->entityTypeManager = $entityTypeManager;
|
||||
}
|
||||
|
||||
public function addConditionsToQuery(QueryInterface $query, array $conditions): void {
|
||||
foreach($conditions as $condition) {
|
||||
$field = $condition[0];
|
||||
$value = $condition[1];
|
||||
$operator = isset($condition[2]) ? $condition[2] : "=";
|
||||
$query->condition($field, $value, $operator);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility: find term by name and vid.
|
||||
*
|
||||
@ -40,7 +29,7 @@ class Utils {
|
||||
*/
|
||||
public function getTidByName(string $name, string $vid):int {
|
||||
if (empty($name) || empty($vid)) {
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
$properties = [
|
||||
'name' => $name,
|
||||
|
40
tests/src/Unit/OCActivityRevisionRevertFormTest.php
Normal file
40
tests/src/Unit/OCActivityRevisionRevertFormTest.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace Drupal\Tests\opencase\Unit;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\Form\FormState;
|
||||
use Drupal\opencase_entities\Form\OCActivityRevisionRevertForm;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
class OCActivityRevisionRevertFormTest extends UnitTestCase{
|
||||
public function setUp(): void {
|
||||
$container = new ContainerBuilder();
|
||||
$entityTypeManager = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityTypeManager')->disableOriginalConstructor()->getMock();
|
||||
$dateFormatter = $this->getMockBuilder('\\Drupal\\Core\\Datetime\\DateFormatterInterface')->disableOriginalConstructor()->getMock();
|
||||
$storage = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityStorageInterface')->disableOriginalConstructor()->getMock();
|
||||
$revision = $this->getMockBuilder('\\Drupal\\opencase_entities\\Entity\OCActivity')->disableOriginalConstructor()->getMock();
|
||||
$request = new Request([], [], [], [], [], [], [], json_encode([
|
||||
'foo' => 'bar'
|
||||
]));
|
||||
$requestStack = new RequestStack();
|
||||
$requestStack->push($request);
|
||||
$dateFormatter->method('format');
|
||||
$container->set('entity_type.manager', $entityTypeManager);
|
||||
$container->set('date.formatter', $dateFormatter);
|
||||
$entityTypeManager->method('getStorage')->willReturn($storage);
|
||||
$storage->method('loadRevision')->willReturn($revision);
|
||||
$container->set('string_translation', self::getStringTranslationStub());
|
||||
$container->set('request_stack', $requestStack);
|
||||
\Drupal::setContainer($container);
|
||||
$this->reverter = OCActivityRevisionRevertForm::create($container);
|
||||
}
|
||||
|
||||
public function testBuildForm():void {
|
||||
$form = [];
|
||||
$this->assertTrue(is_array($this->reverter->buildForm($form, new FormState())));
|
||||
}
|
||||
|
||||
}
|
40
tests/src/Unit/OCActorRevisionRevertFormTest.php
Normal file
40
tests/src/Unit/OCActorRevisionRevertFormTest.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace Drupal\Tests\opencase\Unit;
|
||||
|
||||
use Drupal\opencase_entities\Form\OCActorRevisionRevertForm;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\Core\Form\FormState;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
|
||||
class OCActorRevisionRevertFormTest extends UnitTestCase{
|
||||
public function setUp(): void {
|
||||
$container = new ContainerBuilder();
|
||||
$entityTypeManager = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityTypeManager')->disableOriginalConstructor()->getMock();
|
||||
$dateFormatter = $this->getMockBuilder('\\Drupal\\Core\\Datetime\\DateFormatterInterface')->disableOriginalConstructor()->getMock();
|
||||
$storage = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityStorageInterface')->disableOriginalConstructor()->getMock();
|
||||
$revision = $this->getMockBuilder('\\Drupal\\opencase_entities\\Entity\OCActor')->disableOriginalConstructor()->getMock();
|
||||
$request = new Request([], [], [], [], [], [], [], json_encode([
|
||||
'foo' => 'bar'
|
||||
]));
|
||||
$requestStack = new RequestStack();
|
||||
$requestStack->push($request);
|
||||
$dateFormatter->method('format');
|
||||
$container->set('entity_type.manager', $entityTypeManager);
|
||||
$container->set('date.formatter', $dateFormatter);
|
||||
$entityTypeManager->method('getStorage')->willReturn($storage);
|
||||
$storage->method('loadRevision')->willReturn($revision);
|
||||
$container->set('string_translation', self::getStringTranslationStub());
|
||||
$container->set('request_stack', $requestStack);
|
||||
\Drupal::setContainer($container);
|
||||
$this->reverter = OCActorRevisionRevertForm::create($container);
|
||||
}
|
||||
|
||||
public function testBuildForm():void {
|
||||
$form = [];
|
||||
$this->assertTrue(is_array($this->reverter->buildForm($form, new FormState())));
|
||||
}
|
||||
|
||||
}
|
40
tests/src/Unit/OCCaseRevisionRevertFormTest.php
Normal file
40
tests/src/Unit/OCCaseRevisionRevertFormTest.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace Drupal\Tests\opencase\Unit;
|
||||
|
||||
use Drupal\opencase_cases\Form\OCCaseRevisionRevertForm;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\Core\Form\FormState;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
|
||||
class OCCaseRevisionRevertFormTest extends UnitTestCase{
|
||||
public function setUp(): void {
|
||||
$container = new ContainerBuilder();
|
||||
$entityTypeManager = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityTypeManager')->disableOriginalConstructor()->getMock();
|
||||
$dateFormatter = $this->getMockBuilder('\\Drupal\\Core\\Datetime\\DateFormatterInterface')->disableOriginalConstructor()->getMock();
|
||||
$storage = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityStorageInterface')->disableOriginalConstructor()->getMock();
|
||||
$revision = $this->getMockBuilder('\\Drupal\\opencase_cases\\Entity\OCCase')->disableOriginalConstructor()->getMock();
|
||||
$request = new Request([], [], [], [], [], [], [], json_encode([
|
||||
'foo' => 'bar'
|
||||
]));
|
||||
$requestStack = new RequestStack();
|
||||
$requestStack->push($request);
|
||||
$dateFormatter->method('format');
|
||||
$container->set('entity_type.manager', $entityTypeManager);
|
||||
$container->set('date.formatter', $dateFormatter);
|
||||
$entityTypeManager->method('getStorage')->willReturn($storage);
|
||||
$storage->method('loadRevision')->willReturn($revision);
|
||||
$container->set('string_translation', self::getStringTranslationStub());
|
||||
$container->set('request_stack', $requestStack);
|
||||
\Drupal::setContainer($container);
|
||||
$this->reverter = OCCaseRevisionRevertForm::create($container);
|
||||
}
|
||||
|
||||
public function testBuildForm():void {
|
||||
$form = [];
|
||||
$this->assertTrue(is_array($this->reverter->buildForm($form, new FormState())));
|
||||
}
|
||||
|
||||
}
|
40
tests/src/Unit/OCOrganisationRevisionRevertFormTest.php
Normal file
40
tests/src/Unit/OCOrganisationRevisionRevertFormTest.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace Drupal\Tests\opencase\Unit;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\Core\Form\FormState;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\opencase_entities\Form\OCOrganisationRevisionRevertForm;
|
||||
|
||||
class OCOrganisationRevisionRevertFormTest extends UnitTestCase{
|
||||
public function setUp(): void {
|
||||
$container = new ContainerBuilder();
|
||||
$entityTypeManager = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityTypeManager')->disableOriginalConstructor()->getMock();
|
||||
$dateFormatter = $this->getMockBuilder('\\Drupal\\Core\\Datetime\\DateFormatterInterface')->disableOriginalConstructor()->getMock();
|
||||
$storage = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityStorageInterface')->disableOriginalConstructor()->getMock();
|
||||
$revision = $this->getMockBuilder('\\Drupal\\opencase_entities\\Entity\OCOrganisation')->disableOriginalConstructor()->getMock();
|
||||
$request = new Request([], [], [], [], [], [], [], json_encode([
|
||||
'foo' => 'bar'
|
||||
]));
|
||||
$requestStack = new RequestStack();
|
||||
$requestStack->push($request);
|
||||
$dateFormatter->method('format');
|
||||
$container->set('entity_type.manager', $entityTypeManager);
|
||||
$container->set('date.formatter', $dateFormatter);
|
||||
$entityTypeManager->method('getStorage')->willReturn($storage);
|
||||
$storage->method('loadRevision')->willReturn($revision);
|
||||
$container->set('string_translation', self::getStringTranslationStub());
|
||||
$container->set('request_stack', $requestStack);
|
||||
\Drupal::setContainer($container);
|
||||
$this->reverter = OCOrganisationRevisionRevertForm::create($container);
|
||||
}
|
||||
|
||||
public function testBuildForm():void {
|
||||
$form = [];
|
||||
$this->assertTrue(is_array($this->reverter->buildForm($form, new FormState())));
|
||||
}
|
||||
|
||||
}
|
@ -22,7 +22,7 @@ class TimeBasedFieldUpdaterTest extends UnitTestCase{
|
||||
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->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);
|
||||
}
|
||||
@ -30,16 +30,16 @@ class TimeBasedFieldUpdaterTest extends UnitTestCase{
|
||||
$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->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);
|
||||
$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->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);
|
||||
@ -48,13 +48,13 @@ class TimeBasedFieldUpdaterTest extends UnitTestCase{
|
||||
|
||||
function testBundleAndDateAndExtraConditionsAreAllAddedAsQueryConditions(): void {
|
||||
$this->query->method('execute')->willReturn([]);
|
||||
$expected_conditions= [
|
||||
['dummy_field', 'dummy_value', '<'],
|
||||
['dummy_field_2', 'dummy_value_2', '='],
|
||||
['dummy_date_field', date('Y-m-d', strtotime('- 3 months')), "<"],
|
||||
['type', 'dummy_bundle', '=']
|
||||
];
|
||||
$this->utils->expects($this->once())->method('addConditionsToQuery')->with($this->query, $expected_conditions);
|
||||
|
||||
$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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,24 +12,14 @@ class UtilsTest extends UnitTestCase{
|
||||
$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);
|
||||
$this->entityTypeManager->method('getStorage')->willReturn($this->storage);
|
||||
}
|
||||
|
||||
public function testGetTidByNameGetsTid():void {
|
||||
$this->entityTypeManager->method('getStorage')->willReturn($this->storage);
|
||||
$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);
|
||||
$this->assertEquals($this->utils->getTidByName('foo', 'bar'), 3);
|
||||
}
|
||||
public function testAddConditionToQueryAddsEqualsIfNoOperatorProvided():void {
|
||||
$this->query->expects($this->exactly(1))->method('condition')->with("1", "2", "=");
|
||||
$this->utils->addConditionsToQuery($this->query, [["1","2"]]);
|
||||
|
||||
}
|
||||
public function testAddConditionToQueryAddsTheRightAmountOfConditions():void {
|
||||
$this->query->expects($this->exactly(4))->method('condition');
|
||||
$this->utils->addConditionsToQuery($this->query, [["1","2","3"], ["lk", "n", "kk"], ['sfd', 'ds', 'fds'], ["1","2","3"]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user