Skip to content

Commit

Permalink
Added 'TicketsAcceptedPrefixId` option callback
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Coward committed Jun 14, 2020
1 parent b40139c commit 8d5a9da
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
41 changes: 41 additions & 0 deletions Option/TicketsAcceptedPrefixId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace VersoBit\ResourceTickets\Option;

use XF\Option\AbstractOption;

class TicketsAcceptedPrefixId extends AbstractOption
{
public static function renderOption(\XF\Entity\Option $option, array $htmlParams)
{
// TODO: only fetch prefixes available in selected ticket category (would require options save if category is changed at same time)
/** @var \NF\Tickets\Repository\TicketPrefix $prefixRepo */
$prefixRepo = \XF::repository('NF\Tickets:TicketPrefix');
$prefixes = $prefixRepo->findPrefixesForList()->fetch();
$prefixes = $prefixes->pluckNamed('title', 'prefix_id');

return self::getSelectRow($option, $htmlParams, $prefixes);
}

public static function verifyOption(&$value, \XF\Entity\Option $option)
{
if (!$value)
{
$value = null;

return true;
}

/** @var \NF\Tickets\Entity\TicketPrefix $category */
$prefix = \XF::finder('NF\Tickets:TicketPrefix')->whereId($value)->fetchOne();

if (!$prefix)
{
$option->error(\XF::phrase('vb_resourcetickets_ticket_prefix_not_found'), $option->option_id);

return false;
}

return true;
}
}
2 changes: 1 addition & 1 deletion _output/options/_metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"versobitResourceTicketsAcceptedPrefixId.json": {
"hash": "f8cb6327fcb384a949d403d6d9e907e4"
"hash": "c84552c3e2cecfb3a8ca9e1e03ecd16a"
},
"versobitResourceTicketsAwaitingApprovalPrefixId.json": {
"hash": "e709902941e864532cff9f19dfd427e0"
Expand Down
8 changes: 4 additions & 4 deletions _output/options/versobitResourceTicketsAcceptedPrefixId.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"edit_format": "textbox",
"edit_format_params": "",
"edit_format": "callback",
"edit_format_params": "VersoBit\\ResourceTickets\\Option\\TicketsAcceptedPrefixId::renderOption",
"data_type": "unsigned_integer",
"sub_options": [],
"validation_class": "",
"validation_method": "",
"validation_class": "VersoBit\\ResourceTickets\\Option\\TicketsAcceptedPrefixId",
"validation_method": "verifyOption",
"default_value": "0",
"relations": {
"versobitResourceTickets": 4
Expand Down

0 comments on commit 8d5a9da

Please sign in to comment.