FormExtendedTrait.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace ModulesGarden\Servers\ZimbraEmail\App\Traits;
  3. use ModulesGarden\Servers\ZimbraEmail\App\UI\Admin\Custom\Sections\RowSection;
  4. use ModulesGarden\Servers\ZimbraEmail\Core\UI\Widget\Forms\BaseForm;
  5. use ModulesGarden\Servers\ZimbraEmail\Core\UI\Widget\Forms\Sections\HalfPageSection;
  6. /**
  7. *
  8. * Created by PhpStorm.
  9. * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
  10. * Date: 08.11.19
  11. * Time: 14:20
  12. * Class FormExtendedTrait
  13. */
  14. trait FormExtendedTrait
  15. {
  16. protected $sectionCounter = 0;
  17. /**
  18. * auto generate double section helper
  19. *
  20. * @param array $fields
  21. * @return $this
  22. * @throws \Exception
  23. */
  24. protected function generateDoubleSection($fields = [])
  25. {
  26. if(!method_exists($this, 'addSection'))
  27. {
  28. throw new \Exception('This trait can not be used in class: '.self::class);
  29. }
  30. $sections = [];
  31. $fieldCounter = 0;
  32. foreach($fields as $field)
  33. {
  34. $halfPageSection = new HalfPageSection('generated_'.$this->sectionCounter.'_'.$fieldCounter);
  35. $halfPageSection->addField($field);
  36. $sections[] = $halfPageSection;
  37. $fieldCounter++;
  38. }
  39. $rawSection = new RowSection('generated_row_section_'.$this->sectionCounter);
  40. foreach($sections as $section)
  41. {
  42. $rawSection->addSection($section);
  43. }
  44. $this->addSection($rawSection);
  45. $this->sectionCounter++;
  46. return $this;
  47. }
  48. }