| @@ -63,8 +63,14 @@ | ||
| 63 | 63 | if (isset($valueKeys[1])) { |
| 64 | 64 | $defaultValue = trim($valueKeys[1]); |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | + // Before the empty-data guard: with no agent (unassigned ticket, closed by | |
| 68 | + // a workflow) the signature is empty, not a literal {{agent.signature}}. | |
| 69 | + if ($dataKey == 'agent' && $valueKey == 'signature') { | |
| 70 | + return $this->getAgentSignature($data); | |
| 71 | + } | |
| 72 | + | |
| 67 | 73 | if(empty($data[$dataKey])) { |
| 68 | 74 | return $matches[0]; |
| 69 | 75 | } |
| 70 | 76 | |
| @@ -86,8 +92,35 @@ | ||
| 86 | 92 | return $this->getBusinessValue($valueKey, $defaultValue, $business); |
| 87 | 93 | } |
| 88 | 94 | |
| 89 | 95 | return apply_filters('fluentsupport/smartcode_fallback_callback_' . $dataKey, $matches[0], $valueKey, $defaultValue, $data); |
| 96 | + } | |
| 97 | + | |
| 98 | + /** Set while a signature renders: a signature naming itself, in any spelling, renders empty. */ | |
| 99 | + private static $renderingSignature = false; | |
| 100 | + | |
| 101 | + /** | |
| 102 | + * {{agent.signature}}: the agent's signature when enabled, otherwise empty. | |
| 103 | + * Its own smartcodes are filled from the same data. | |
| 104 | + */ | |
| 105 | + protected function getAgentSignature($data) | |
| 106 | + { | |
| 107 | + if (self::$renderingSignature || empty($data['agent'])) { | |
| 108 | + return ''; | |
| 109 | + } | |
| 110 | + | |
| 111 | + $signature = \FluentSupport\App\Services\Tickets\ResponseService::getAppendedSignature($data['agent']); | |
| 112 | + | |
| 113 | + if ($signature === '') { | |
| 114 | + return ''; | |
| 115 | + } | |
| 116 | + | |
| 117 | + self::$renderingSignature = true; | |
| 118 | + try { | |
| 119 | + return $this->parse($signature, $data); | |
| 120 | + } finally { | |
| 121 | + self::$renderingSignature = false; | |
| 122 | + } | |
| 90 | 123 | } |
| 91 | 124 | |
| 92 | 125 | protected function getTicketData($ticket, $valueKey, $defaultValue) |
| 93 | 126 | { |