From 245992cadad86c71bb9c5a591343ff199a9064dc Mon Sep 17 00:00:00 2001 From: Camilo Rodriguez Date: Tue, 5 Dec 2017 18:17:06 +0000 Subject: [PATCH] CRM-21520: Refactor Form Quickform Building Code Now that we're only using one form, we don't need to have the FormBuilder class. Removed the class and sent the building code to the AddToCaseAsRole class. --- CRM/Case/Form/AddToCaseAsRole.php | 49 ++++++++++++++++++++- CRM/Case/FormBuilder.php | 44 ------------------ templates/CRM/Case/Form/AddToCaseAsRole.tpl | 2 +- 3 files changed, 48 insertions(+), 47 deletions(-) delete mode 100644 CRM/Case/FormBuilder.php diff --git a/CRM/Case/Form/AddToCaseAsRole.php b/CRM/Case/Form/AddToCaseAsRole.php index d8801ffd48..6f42c596e3 100644 --- a/CRM/Case/Form/AddToCaseAsRole.php +++ b/CRM/Case/Form/AddToCaseAsRole.php @@ -1,11 +1,56 @@ build(); + + $this->add('text', 'assign_to', ts('Assign to')); + $roleTypes = $this->getRoleTypes(); + + $this->add( + 'select', + 'role_type', + ts('Relationship Type'), + array('' => ts('- select type -')) + $roleTypes, + FALSE, + array('class' => 'crm-select2 twenty') + ); + + $this->addButtons(array( + array( + 'type' => 'submit', + 'name' => ts('Submit'), + 'isDefault' => TRUE, + ), + )); + } + + /** + * Returns list of configured role types for individuals. + * + * @return array + * List of role types + */ + private function getRoleTypes() { + $relType = CRM_Contact_BAO_Relationship::getRelationType('Individual'); + $roleTypes = array(); + + foreach ($relType as $k => $v) { + $roleTypes[substr($k, 0, strpos($k, '_'))] = $v; + } + + return $roleTypes; } + /** + * @inheritdoc + */ public function postProcess() { $values = $this->controller->exportValues(); diff --git a/CRM/Case/FormBuilder.php b/CRM/Case/FormBuilder.php deleted file mode 100644 index 511aa1a6b6..0000000000 --- a/CRM/Case/FormBuilder.php +++ /dev/null @@ -1,44 +0,0 @@ -form = $form; - } - - public function build() { - $this->form->add('text', 'assign_to', ts('Assign to')); - $roleTypes = $this->getRoleTypes(); - - $this->form->add( - 'select', - 'role_type', - ts('Relationship Type'), - array('' => ts('- select type -')) + $roleTypes, - FALSE, - array('class' => 'crm-select2 twenty') - ); - - $this->form->addButtons(array( - array( - 'type' => 'submit', - 'name' => ts('Submit'), - 'isDefault' => TRUE, - ), - )); - } - - /** - * @return array - */ - private function getRoleTypes() { - $relType = CRM_Contact_BAO_Relationship::getRelationType('Individual'); - $roleTypes = array(); - foreach ($relType as $k => $v) { - $roleTypes[substr($k, 0, strpos($k, '_'))] = $v; - } - return $roleTypes; - } - -} diff --git a/templates/CRM/Case/Form/AddToCaseAsRole.tpl b/templates/CRM/Case/Form/AddToCaseAsRole.tpl index 88e5d0a2dc..bef98d3604 100644 --- a/templates/CRM/Case/Form/AddToCaseAsRole.tpl +++ b/templates/CRM/Case/Form/AddToCaseAsRole.tpl @@ -10,7 +10,7 @@