Skip to content

Commit

Permalink
SIT-1211 Transportation Wallet (#2955)
Browse files Browse the repository at this point in the history
* SIT-1211 initial demo version of Transportation Wallet form

* SIT-1211 12/02 changes, added null check to address verifier widget

* SIT-1211 split out hop card recipient names into firstname/lastname

* SIT-1211 commit work in progress so I can switch branches. Started making requested changes to form.

* SIT-1211 massive set of revisions requested by customer, includes funds calculator

* SIT-1211 major form refactoring, changed custom composites to regular elements

* SIT-1211 fixed logic issues, finished reqeusted updates and improvements, ready for next demo

* SIT-1211 incremental update so I can switch branches

* SIT-1211 incremental commit so I can merge changes from master

* SIT-1211 incremental commit so I can switch to a workstation with working debugger

* SIT-1211 updated zendesk handler to support Problem-Incident relationship, configure form to use updated handler, fix Xdebug config

* SIT-1211 updated address verifier js to support widgets on wizard pages, more form updates including better data being pushed into tickets

* SIT-1211 lots of form updates, fixed all the calculator fields, updated household ticket handlers

* SIT-1211 fixed up handlers, added organizaiton name field support, added more test handlers, committing changes before another major round of updates in case they need to be reversed.

* SIT-1211 final tweaks before QA testing

* SIT-1211 removed debugging code.

* SIT-1211 remove unneeded references

* SIT-1211 final updates to form: fixed (I think) the form reset bug, updated ticket subject for options 1 and 2, set hop card amount for option 2.

* SIT-1211 hide computed amount for options 1/2

* SIT-1211 fixed value for personalized honored citizen hop card

* SIT-1211 added ReceviedAt value for outdoor dining in their Zendesk handler

* SIT-1211 added date of birth elements for all househould members

* SIT-1211 refactored to use much less computed twig content

* SIT-1211 refactored calculator to use custom javascript instead of relying on computed twig (fixes the 'start over' bug), misc form updates, made the first page accessible.

* SIT-1211 add 1sec delay to ajax to hopefully prevent the 'start over' bug

* SIT-1211 final form tweaks to hopefully prevent reset bug

* SIT-1211 clean up unused lines

---------

Co-authored-by: Oden <hello@odensc.com>
  • Loading branch information
jookyg and odensc authored Jan 31, 2025
1 parent a419d5c commit 39a5d79
Show file tree
Hide file tree
Showing 5 changed files with 1,950 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
attach: function (context) {
$(once('address-verifier', '.portland-address-verifier--wrapper', context)).each(function () {
const $element = $(this);
const elementId = $element.attr('id');
const elementId = $element.attr('id').replace(/--[^-]+--wrapper$/, '--wrapper');

const apiKey = drupalSettings.portlandmaps_api_key;

// Always initialize the model, view, and controller regardless of visibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected function formatHtmlItemValue(array $element, WebformSubmissionInterfac
$lines = [];
$address = "";

if ($value['location_verification_status'] == 'Verified') {
if ($value['location_verification_status'] == 'Verified' && array_key_exists('address_label', $value)) {
$address = $value['address_label'];
$address = str_replace("\r\n", "<br>", $address);
} else {
Expand Down Expand Up @@ -118,7 +118,9 @@ protected function formatTextItemValue(array $element, WebformSubmissionInterfac
public function prepare(array &$element, WebformSubmissionInterface $webform_submission = NULL) {
parent::prepare($element, $webform_submission);

$machine_name = "edit-" . $element['#webform_key'] . "--wrapper";
$key = isset($element['#webform_key']) ? $element['#webform_key'] : "";

$machine_name = "edit-" . $key . "--wrapper";
$machine_name = str_replace("_", "-", $machine_name);

$addressType = array_key_exists('#address_type', $element) && strtolower($element['#address_type']) == "any";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,15 @@
*/

namespace Drupal\portland_zendesk\Plugin\WebformHandler;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\webform\Plugin\WebformHandlerBase;
use Drupal\webform\WebformSubmissionConditionsValidatorInterface;
use Drupal\webform\WebformSubmissionInterface;
use Drupal\portland_zendesk\Client\ZendeskClient;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\webform\WebformTokenManagerInterface;
use Drupal\Core\Serialization\Yaml;
use Drupal\file\Entity\File;
use Drupal\portland_zendesk\Utils\Utility;
use Drupal\webform\Entity\Webform;
use Drupal\webform\WebformSubmissionForm;


/**
* Form submission to Zendesk handler.
Expand Down Expand Up @@ -105,9 +98,11 @@ public function defaultConfiguration()
'group_id' => '',
'assignee_id' => '',
'type' => 'question',
'is_child_incident' => '',
'collaborators' => '',
'custom_fields' => '',
'ticket_id_field' => '',
'parent_ticket_id_field' => '',
'ticket_fork_field' => '',
'ticket_form_id' => '',
];
Expand Down Expand Up @@ -309,6 +304,13 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
'#required' => false
];

$form['is_child_incident'] = [
'#type' => 'checkbox',
'#title' => $this->t('This ticket is the child of a Problem ticket.'),
'#description' => $this->t('Uses the value in the Zendesk Parent Ticket ID field to identify the parent Problem.'),
'#default_value' => $this->configuration['is_child_incident'] ?? 0
];

// space separated tags
$form['tags'] = [
'#type' => 'textfield',
Expand Down Expand Up @@ -454,6 +456,15 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
'#required' => false
];

$form['parent_ticket_id_field'] = [
'#type' => 'webform_select_other',
'#title' => $this->t('Zendesk Parent Ticket ID Field'),
'#description' => $this->t('The name of the hidden field which will store the parent ticket ID in a Problem-Incident relationship. This field automatically gets filled with the created Ticket ID unless is_child_incident is true.'),
'#default_value' => $this->configuration['parent_ticket_id_field'],
'#options' => $options['hidden'],
'#required' => false
];

$form['ticket_fork_field'] = [
'#type' => 'textfield',
'#title' => $this->t('Zendesk Ticket Fork Field'),
Expand All @@ -462,6 +473,25 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
'#required' => false
];

$form['subject']['#weight'] = -10; // Place first
$form['comment']['#weight'] = -10;
$form['requester_name']['#weight'] = -10;
$form['requester_email']['#weight'] = -10;
$form['collaborators']['#weight'] = -7; // CCs
$form['tags']['#weight'] = -5;
$form['ticket_id_field']['#weight'] = -4;
$form['parent_ticket_id_field']['#weight'] = -4;
$form['type']['#weight'] = -3; // Ticket Type
$form['incident_child_problem']['#weight'] = -2; // Checkbox
$form['priority']['#weight'] = -1;
$form['status']['#weight'] = 0;
$form['recipient']['#weight'] = 1;
$form['group_id']['#weight'] = 2;
$form['assignee_id']['#weight'] = 3;
$form['ticket_form_id']['#weight'] = 4;
$form['ticket_fork_field']['#weight'] = 5;
$form['custom_fields']['#weight'] = 6;

// TODO: remove once zendesk PHP library is updated for PHP 8.2
error_reporting($error_level);

Expand Down Expand Up @@ -549,6 +579,8 @@ public function sendToZendesk(array &$form, FormStateInterface &$form_state) {

$new_ticket_id = 0;
$zendesk_ticket_id_field_name = $this->configuration['ticket_id_field'];
$zendesk_parent_ticket_id_field_name = $this->configuration['parent_ticket_id_field'];
$is_child = $this->configuration['is_child_incident'];

// tickets will be forked on the field identified in the config value 'ticket_fork_field'
$fork_field_name = $this->configuration['ticket_fork_field'];
Expand All @@ -559,11 +591,20 @@ public function sendToZendesk(array &$form, FormStateInterface &$form_state) {

// check for a report_ticket_id value in the form state; if a handler previously submitted
// a ticket, the ID should be available to subsequent handlers.
$prev_ticket_id = $form_state->getValue('report_ticket_id');
$prev_ticket_id = $form_state->getValue($zendesk_ticket_id_field_name);
if ($prev_ticket_id) {
$webform_submission->setElementData('report_ticket_id', $prev_ticket_id);
$webform_submission->setElementData($zendesk_ticket_id_field_name, $prev_ticket_id);
}

// check for a parent_ticket_id value in the form state; if a handler previously submitted
// a ticket, the ID should be available to subsequent handlers.
$parent_ticket_id = $form_state->getValue($zendesk_parent_ticket_id_field_name);
if ($parent_ticket_id) {
$webform_submission->setElementData($zendesk_parent_ticket_id_field_name, $parent_ticket_id);
}

// the 2nd time through, $prev_ticket_id and $parent_ticket_id are both set

if ($fork_field_name) {
// if the handler has a fork field configured, grab the values array from that field so we can
// spin through it and stuff a single value into the webform_submission for each ticket being created.
Expand Down Expand Up @@ -593,21 +634,37 @@ public function sendToZendesk(array &$form, FormStateInterface &$form_state) {
$data = $webform_submission->getData();
}

// if name field is set and present, add ticket ID to hidden Zendesk Ticket ID field
if ($zendesk_ticket_id_field_name && array_key_exists( $zendesk_ticket_id_field_name, $data ) && $new_ticket_id){
// if field is set and present, add ticket ID to hidden Zendesk Ticket ID field
// NOTE: Only do this if $prev_ticket_id isn't already set
if (!$prev_ticket_id && $zendesk_ticket_id_field_name && array_key_exists( $zendesk_ticket_id_field_name, $data ) && $new_ticket_id){
$data[$zendesk_ticket_id_field_name] = $new_ticket_id;
$form_state->setValue($zendesk_ticket_id_field_name, $new_ticket_id);
$form['values'][$zendesk_ticket_id_field_name] = $new_ticket_id;
}

// if this is a Problem ticket and parent ticket ID field is present, add new ticket ID there too
if (!$parent_ticket_id && $zendesk_parent_ticket_id_field_name && array_key_exists( $zendesk_parent_ticket_id_field_name, $data ) && $new_ticket_id && !$is_child){
$data[$zendesk_parent_ticket_id_field_name] = $new_ticket_id;
$form_state->setValue($zendesk_parent_ticket_id_field_name, $new_ticket_id);
$form['values'][$zendesk_parent_ticket_id_field_name] = $new_ticket_id;
}

return $new_ticket_id; // if a null is returned, an error/try-again message will be displayed to the user
}

public function submitTicket(WebformSubmissionInterface $webform_submission, $configuration) {
$zendesk_parent_ticket_id_field_name = $this->configuration['parent_ticket_id_field'];
$is_child = $this->configuration['is_child_incident'];

$submission_fields = $webform_submission->toArray(TRUE);
$new_ticket_id = 0;
$request = [];

if ($is_child && array_key_exists('parent_ticket_id', $submission_fields['data'])) {
$parent_ticket_id = $submission_fields['data'][$zendesk_parent_ticket_id_field_name];
$request['problem_id'] = $parent_ticket_id;
}

// Allow for either values coming from other fields or static/tokens
foreach ($this->defaultConfigurationNames() as $field) {
$request[$field] = $configuration[$field];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ handlers:
tags: 'drupal webform [webform_submission:values:computed_permit_type]'
priority: normal
status: new
recipient: ''
recipient: outdoordining@portlandoregon.gov
group_id: '26629264449943'
assignee_id: ''
type: question
Expand All @@ -390,6 +390,8 @@ handlers:
ticket_id_field: report_ticket_id
ticket_fork_field: ''
ticket_form_id: '26628296208535'
is_child_incident: 0
parent_ticket_id_field: ''
zendesk_update_request:
id: zendesk_update_ticket
handler_id: zendesk_update_request
Expand Down
Loading

0 comments on commit 39a5d79

Please # to comment.