From b6a956180e63fc7b3ff56e3c88a23a9274b93596 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Sat, 14 Feb 2026 13:03:36 -0500 Subject: [PATCH] Revert "fix: Make example hook only load if not yet loaded. Users should follow this example" This reverts commit 3f751349995422efc7045e9acdd82e4c266de3af. --- config/hooks.php.dist | 192 +++++++++++++++++++++--------------------- 1 file changed, 94 insertions(+), 98 deletions(-) diff --git a/config/hooks.php.dist b/config/hooks.php.dist index 52f0cccc..5b7f911c 100644 --- a/config/hooks.php.dist +++ b/config/hooks.php.dist @@ -1,5 +1,4 @@ $common_fields, - // 'Attributes' => $attributes); - // - // // Example #2: Move the 'queue' field at the top of the regular - // // fields list. - // $new_fields = array(); - // foreach ($fields as $field) { - // if ($field == 'queue') { - // array_unshift($new_fields, $field); - // } else { - // array_push($new_fields, $field); - // } - // } - // return $new_fields; - // } +class Whups_Hooks +{ + /** + * Customize the order and grouping of ticket fields. + * + * @param string $type A ticket type. + * @param array $fields A list of field names. + * + * @return array A one-dimensional array with field names, or a + * two-dimensional array with header labels as keys and + * field names as values. + */ +// public function group_fields($type, $fields) +// { +// // Example #1: Split all fields into two groups, one for custom +// // attribute fields and one for the regular fields. +// $common_fields = $attributes = array(); +// foreach ($fields as $field) { +// if (substr($field, 0, 10) == 'attribute_') { +// $attributes[] = $field; +// } else { +// $common_fields[] = $field; +// } +// } +// return array('Common Fields' => $common_fields, +// 'Attributes' => $attributes); +// +// // Example #2: Move the 'queue' field at the top of the regular +// // fields list. +// $new_fields = array(); +// foreach ($fields as $field) { +// if ($field == 'queue') { +// array_unshift($new_fields, $field); +// } else { +// array_push($new_fields, $field); +// } +// } +// return $new_fields; +// } - /** - * Intercept ticket creation. - * - * @param array $info A hash with ticket information. - * @param string $requester The user creating the ticket. - * - * @return array The modified information. - */ - // public function ticket_create($info, $requester) - // { - // // Example #2: Simple spam check. - // if (isset($info['comment']) && - // stripos($info['comment'], 'some spam text') !== false) { - // throw new Whups_Exception('Spammer!'); - // } - // - // return $info; - // } + /** + * Intercept ticket creation. + * + * @param array $info A hash with ticket information. + * @param string $requester The user creating the ticket. + * + * @return array The modified information. + */ +// public function ticket_create($info, $requester) +// { +// // Example #2: Simple spam check. +// if (isset($info['comment']) && +// stripos($info['comment'], 'some spam text') !== false) { +// throw new Whups_Exception('Spammer!'); +// } +// +// return $info; +// } - /** - * Intercept ticket changes. - * - * @param Whups_Ticket $ticket A ticket object. - * @param array $changes A list of change hashes. - * - * @return array The modified changes. - */ - // public function ticket_update($ticket, $changes) - // { - // // Example #1: If a comment has been added to a closed ticket, - // // re-open the ticket and set the state to "assigned". - // // You might want to use numeric ids for the 'to' item in - // // a real life hook. - // /* We only want to change the ticket state if it is closed, a comment - // * has been added, and the state hasn't been changed already. */ - // if (!empty($changes['comment']) && - // empty($changes['state']) && - // $ticket->get('state_category') == 'resolved') { - // /* Pick the first state from the state category 'assigned'. */ - // $states = $GLOBALS['whups_driver']->getStates($ticket->get('type'), - // 'assigned'); - // /* These three item have to exist in a change set. */ - // $changes['state'] = array( - // 'to' => key($states), - // 'from' => $ticket->get('state'), - // 'from_name' => $ticket->get('state_name')); - // } - // - // // Example #2: Simple spam check. - // if (isset($changes['comment']['to']) && - // stripos($changes['comment']['to'], 'some spam text') !== false) { - // throw new Whups_Exception('Spammer!'); - // } - // - // return $changes; - // } - } + /** + * Intercept ticket changes. + * + * @param Whups_Ticket $ticket A ticket object. + * @param array $changes A list of change hashes. + * + * @return array The modified changes. + */ +// public function ticket_update($ticket, $changes) +// { +// // Example #1: If a comment has been added to a closed ticket, +// // re-open the ticket and set the state to "assigned". +// // You might want to use numeric ids for the 'to' item in +// // a real life hook. +// /* We only want to change the ticket state if it is closed, a comment +// * has been added, and the state hasn't been changed already. */ +// if (!empty($changes['comment']) && +// empty($changes['state']) && +// $ticket->get('state_category') == 'resolved') { +// /* Pick the first state from the state category 'assigned'. */ +// $states = $GLOBALS['whups_driver']->getStates($ticket->get('type'), +// 'assigned'); +// /* These three item have to exist in a change set. */ +// $changes['state'] = array( +// 'to' => key($states), +// 'from' => $ticket->get('state'), +// 'from_name' => $ticket->get('state_name')); +// } +// +// // Example #2: Simple spam check. +// if (isset($changes['comment']['to']) && +// stripos($changes['comment']['to'], 'some spam text') !== false) { +// throw new Whups_Exception('Spammer!'); +// } +// +// return $changes; +// } }