Made "opencase_cases" and "opencase_no_cases" modules and gave the latter a version of the contextual menu
This commit is contained in:
parent
208240badc
commit
6d281625b7
7
modules/opencase_cases/opencase_cases.info.yml
Normal file
7
modules/opencase_cases/opencase_cases.info.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
name: 'Opencase Cases'
|
||||||
|
type: module
|
||||||
|
description: 'Provides case entities and a required field on activities linking them to a case.'
|
||||||
|
core: 8.x
|
||||||
|
package: 'OpenCase'
|
||||||
|
dependencies:
|
||||||
|
- opencase_entities
|
64
modules/opencase_cases/opencase_cases.module
Normal file
64
modules/opencase_cases/opencase_cases.module
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Contains opencase_cases.module.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Drupal\Core\Routing\RouteMatchInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_help().
|
||||||
|
*/
|
||||||
|
function opencase_cases_help($route_name, RouteMatchInterface $route_match) {
|
||||||
|
switch ($route_name) {
|
||||||
|
// Main module help for the opencase_cases module.
|
||||||
|
case 'help.page.opencase_cases':
|
||||||
|
$output = '';
|
||||||
|
$output .= '<h3>' . t('About') . '</h3>';
|
||||||
|
$output .= '<p>' . t('Provides case entities and a required field on activities linking them to a case.') . '</p>';
|
||||||
|
return $output;
|
||||||
|
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_theme().
|
||||||
|
*/
|
||||||
|
function opencase_cases_theme() {
|
||||||
|
return [
|
||||||
|
'opencase_cases' => [
|
||||||
|
'render element' => 'children',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
function opencase_cases_entity_base_field_info($entity_type) {
|
||||||
|
$fields = array();
|
||||||
|
|
||||||
|
// Add Case field to Activity
|
||||||
|
if ($entity_type->id() === 'oc_activity') {
|
||||||
|
$fields['oc_case'] = BaseFieldDefinition::create('entity_reference')
|
||||||
|
->setLabel(t('Case'))
|
||||||
|
->setDescription(t('The case this activity belongs to.'))
|
||||||
|
->setSetting('target_type', 'oc_case')
|
||||||
|
->setSetting('handler', 'default')
|
||||||
|
->setTranslatable(TRUE)
|
||||||
|
->setCardinality(1)
|
||||||
|
->setDefaultValueCallback('opencase_cases_default_activity_case_value')
|
||||||
|
->setDisplayOptions('view', [
|
||||||
|
'type' => 'string',
|
||||||
|
'weight' => -3,
|
||||||
|
])
|
||||||
|
->setRequired(TRUE);
|
||||||
|
}
|
||||||
|
return $fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When creating an activity, it sets the case id from the URL.
|
||||||
|
*/
|
||||||
|
public static function opencase_cases_default_activity_case_value() {
|
||||||
|
return array(\Drupal::request()->query->get('case_id'));
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
<!-- Add you custom twig html here -->
|
@ -7,4 +7,5 @@ dependencies:
|
|||||||
- contact
|
- contact
|
||||||
- field
|
- field
|
||||||
- opencase_entities
|
- opencase_entities
|
||||||
|
- opencase_cases
|
||||||
- options
|
- options
|
||||||
|
@ -107,7 +107,7 @@ function opencase_defaults_entity_base_field_info($entity_type) {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a Client field to cases
|
// Add Involved Parties field to cases
|
||||||
if ($entity_type->id() === 'oc_case') {
|
if ($entity_type->id() === 'oc_case') {
|
||||||
$fields['actors_involved'] = BaseFieldDefinition::create('entity_reference')
|
$fields['actors_involved'] = BaseFieldDefinition::create('entity_reference')
|
||||||
->setLabel(t('Involved Parties'))
|
->setLabel(t('Involved Parties'))
|
||||||
|
@ -80,7 +80,7 @@ class OCActivity extends RevisionableContentEntityBase implements OCActivityInte
|
|||||||
* When creating an activity, it sets the case id from the URL.
|
* When creating an activity, it sets the case id from the URL.
|
||||||
*/
|
*/
|
||||||
public static function defaultVal() {
|
public static function defaultVal() {
|
||||||
return array(\Drupal::request()->query->get('case_id'));
|
return array(\Drupal::request()->query->get('actor_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function currentDateTime() {
|
public static function currentDateTime() {
|
||||||
@ -274,20 +274,6 @@ class OCActivity extends RevisionableContentEntityBase implements OCActivityInte
|
|||||||
])
|
])
|
||||||
->setRequired(TRUE);
|
->setRequired(TRUE);
|
||||||
|
|
||||||
$fields['oc_case'] = BaseFieldDefinition::create('entity_reference')
|
|
||||||
->setLabel(t('Case'))
|
|
||||||
->setDescription(t('The case this activity belongs to.'))
|
|
||||||
->setSetting('target_type', 'oc_case')
|
|
||||||
->setSetting('handler', 'default')
|
|
||||||
->setTranslatable(TRUE)
|
|
||||||
->setCardinality(1)
|
|
||||||
->setDefaultValueCallback('Drupal\opencase_entities\Entity\OCActivity::defaultVal')
|
|
||||||
->setDisplayOptions('view', [
|
|
||||||
'type' => 'string',
|
|
||||||
'weight' => -3,
|
|
||||||
])
|
|
||||||
->setRequired(TRUE);
|
|
||||||
|
|
||||||
$fields['description'] = BaseFieldDefinition::create('string_long')
|
$fields['description'] = BaseFieldDefinition::create('string_long')
|
||||||
->setLabel(t('Description'))
|
->setLabel(t('Description'))
|
||||||
->setRevisionable(TRUE)
|
->setRevisionable(TRUE)
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
langcode: en
|
||||||
|
status: true
|
||||||
|
dependencies:
|
||||||
|
module:
|
||||||
|
- opencase_no_cases
|
||||||
|
theme:
|
||||||
|
- bartik
|
||||||
|
id: opencasecontextualmenu
|
||||||
|
theme: bartik
|
||||||
|
region: sidebar_second
|
||||||
|
weight: -6
|
||||||
|
provider: null
|
||||||
|
plugin: opencase_no_cases_contextual_menu
|
||||||
|
settings:
|
||||||
|
id: opencase_no_cases_contextual_menu
|
||||||
|
label: 'OpenCase Contextual Menu'
|
||||||
|
provider: opencase_no_cases
|
||||||
|
label_display: '0'
|
||||||
|
visibility: { }
|
8
modules/opencase_no_cases/opencase_no_cases.info.yml
Normal file
8
modules/opencase_no_cases/opencase_no_cases.info.yml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
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
|
67
modules/opencase_no_cases/opencase_no_cases.module
Normal file
67
modules/opencase_no_cases/opencase_no_cases.module
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
<?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' => 'entity_reference_autocomplete',
|
||||||
|
'weight' => -2,
|
||||||
|
'settings' => [
|
||||||
|
'match_operator' => 'CONTAINS',
|
||||||
|
'size' => '60',
|
||||||
|
'autocomplete_type' => 'tags',
|
||||||
|
'placeholder' => '',
|
||||||
|
],
|
||||||
|
])
|
||||||
|
->setDisplayOptions('view', [
|
||||||
|
'label' => 'above',
|
||||||
|
])
|
||||||
|
->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]);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\opencase_no_cases\Plugin\Block;
|
||||||
|
|
||||||
|
use Drupal\Core\Block\BlockBase;
|
||||||
|
use Drupal\Core\Link;
|
||||||
|
use Drupal\Core\Url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a 'ContextualMenu' block.
|
||||||
|
*
|
||||||
|
* Displays links for adding activities against a person.
|
||||||
|
*
|
||||||
|
* @Block(
|
||||||
|
* id = "opencase_no_cases_contextual_menu",
|
||||||
|
* admin_label = @Translation("OpenCase Contextual Menu"),
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
class ContextualMenu extends BlockBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function build() {
|
||||||
|
$route_name = \Drupal::routeMatch()->getRouteName();
|
||||||
|
if ($route_name == 'entity.oc_actor.canonical') {
|
||||||
|
$markup = $this->actorPage();
|
||||||
|
$build = [];
|
||||||
|
$build['contextual_menu'] = [
|
||||||
|
'#markup' => "<div id='opencase_contextual_menu'>$markup</div",
|
||||||
|
'#cache' => ['max-age' => 0]
|
||||||
|
];
|
||||||
|
return $build;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contextual menu for Actor page
|
||||||
|
* - Links to add activities of various types
|
||||||
|
*/
|
||||||
|
private function actorPage() {
|
||||||
|
$actor_id = \Drupal::routeMatch()->getParameter('oc_actor')->id();
|
||||||
|
$current_path = \Drupal::service('path.current')->getPath();
|
||||||
|
return $this->generateLinksForAddingNewActivities("Add activity", ['actor_id' => $actor_id, 'destination' => $current_path]);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* returns html markup.
|
||||||
|
*/
|
||||||
|
private function generateLinksForAddingNewActivities($title, $query = []) {
|
||||||
|
$title = t($title);
|
||||||
|
$markup = "<h1>$title: </h1>";
|
||||||
|
$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 .= "<p>$link</p>";
|
||||||
|
}
|
||||||
|
return "<div class='openactor_add_links'>$markup</div>";
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user