Example #1
0
 /**
  * @param ServiceLocatorInterface $serviceLocator
  * @param RationaleEntity         $rationale
  */
 public function __construct(ServiceLocatorInterface $serviceLocator, RationaleEntity $rationale)
 {
     $projectService = $serviceLocator->get(ProjectService::class);
     $contactService = clone $serviceLocator->get('contact_contact_service');
     parent::__construct();
     $this->setAttribute('method', 'post');
     $this->setAttribute('class', 'form-horizontal');
     $this->add(['type' => 'Zend\\Form\\Element\\Textarea', 'name' => 'rationale', 'options' => ['label' => _("txt-rationale"), 'help-block' => _("txt-detailed-rationale-explanation")], 'attributes' => ['class' => 'form-control', 'rows' => 12]]);
     $contactsInProject = [];
     /*
      * A form element for a contact (project leader) is only needed when a projectService has already a project
      * So when we are editing a project. If not, simply replace it with the currently logged in user
      */
     if (!is_null($projectService->getProject())) {
         /*
          * @var Contact[]
          */
         $contactsInProject = $contactService->findContactsInProject($projectService);
     }
     $valueOptions = [];
     foreach ($contactsInProject as $contact) {
         /*
          * Filter the contacts based on the country
          */
         if (!is_null($contact->getContactOrganisation()) && $contact->getContactOrganisation()->getOrganisation()->getCountry()->getId() === $rationale->getCountry()->getId()) {
             $valueOptions[$contact->getId()] = $contact->getDisplayName();
         }
     }
     asort($valueOptions);
     $this->add(['type' => 'Zend\\Form\\Element\\Select', 'name' => 'contact', 'options' => ['value_options' => $valueOptions, 'label' => _("txt-nationale-coordinator")], 'attributes' => ['class' => 'form-control', 'required' => true]]);
     $this->add(['type' => 'Zend\\Form\\Element\\Submit', 'name' => 'submit', 'attributes' => ['class' => "btn btn-primary", 'value' => _("txt-update-rationale")]]);
     $this->add(['type' => 'Zend\\Form\\Element\\Submit', 'name' => 'cancel', 'attributes' => ['class' => "btn btn-warning", 'value' => _("txt-cancel")]]);
 }