From d3e0de4d5c43521a768e5de1d281b37ea8413220 Mon Sep 17 00:00:00 2001 From: Benn Oshrin Date: Wed, 7 Feb 2024 07:25:36 -0500 Subject: [PATCH] Add comment truncation to ProvisioningHistoryRecord (NOJIRA) --- .../Table/ProvisioningHistoryRecordsTable.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/src/Model/Table/ProvisioningHistoryRecordsTable.php b/app/src/Model/Table/ProvisioningHistoryRecordsTable.php index e9e0cdc81..321e7e984 100644 --- a/app/src/Model/Table/ProvisioningHistoryRecordsTable.php +++ b/app/src/Model/Table/ProvisioningHistoryRecordsTable.php @@ -100,6 +100,25 @@ public function initialize(array $config): void { ]); } + /** + * Perform actions while marshaling data, before validation. + * + * @since COmanage Registry v5.0.0 + * @param EventInterface $event Event + * @param ArrayObject $data Object data, in array format + * @param ArrayObject $options Entity save options + */ + + public function beforeMarshal(EventInterface $event, \ArrayObject $data, \ArrayObject $options) + { + if(!empty($data['comment'])) { + // Truncate the comment to fit the column width + $column = $this->getSchema()->getColumn('comment'); + + $data['comment'] = substr($data['comment'], 0, $column['length']); + } + } + /** * Table specific logic to generate a display field. *