From 2170855fc09755f49c7457055ca369b41d1d214b Mon Sep 17 00:00:00 2001
From: s j <sj@1729.be>
Date: Wed, 13 Jul 2022 15:19:59 +0000
Subject: [PATCH] imp: add max shares option to transfer shares form

---
 src/Form/TransferShareForm.php | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/Form/TransferShareForm.php b/src/Form/TransferShareForm.php
index 3c792894..9120aa32 100644
--- a/src/Form/TransferShareForm.php
+++ b/src/Form/TransferShareForm.php
@@ -55,7 +55,14 @@ class TransferShareForm extends FormBase {
       ],
       '#weight' => '20',
     ];
-
+    $form['max'] = [
+      '#type' => 'number',
+      '#min' => 0,
+      '#title' => $this->t('Max number of shares from selection to transfer.'),
+      '#description' => $this->t('If you need to transfer a large number of shares, select all applicable shares using shift+click, and fill out this field with the desired number.'),
+      '#weight' => '21',        
+    ];
+                    
     $form['recipient'] = [
       '#type' => 'entity_autocomplete',
       '#title' => $this->t('Recipient'),
@@ -88,6 +95,12 @@ class TransferShareForm extends FormBase {
     ]);
     $group->save();
 
+    if ($max = $form_state->getValue('max') and $max > 0) {
+        $ssad = $form_state->getValue('shareholder_shares_at_date');
+        $ssad['shares'] = array_slice($ssad['shares'], 0, $max);
+        $form_state->setValue('shareholder_shares_at_date', $ssad);
+    }
+    
     $selected_shares = $form_state->getValue('shareholder_shares_at_date')['shares'];
 
     $t1 = ShareTransaction::create([
-- 
GitLab