This type of form was traditionally embedded in a page, with values like _id and _action
`set()` by the page controller.
This allows Admin forms to be placed at their own url without any refactoring.
}
/**
- * Basic setup.
+ * Note: This type of form was traditionally embedded in a page, with values like _id and _action
+ * being `set()` by the page controller.
+ * Nowadays the preferred approach is to place these forms at their own url, so this function
+ * handles both scenarios. It will retrieve id either from a value stored by the page controller
+ * if embedded, or from the url if standalone.
*/
public function preProcess() {
Civi::resources()->addStyleFile('civicrm', 'css/admin.css');
Civi::resources()->addScriptFile('civicrm', 'js/jquery/jquery.crmIconPicker.js');
- $this->_id = $this->get('id');
+ // Lookup id from URL or stored value in controller
+ $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
+
$this->_BAOName = $this->get('BAOName');
+ // If BAOName not explicitly set, look it up from the api entity name
+ if (!$this->_BAOName) {
+ $this->_BAOName = CRM_Core_DAO_AllCoreTables::getBAOClassName(CRM_Core_DAO_AllCoreTables::getFullName($this->getDefaultEntity()));
+ }
$this->_values = [];
if (isset($this->_id)) {
$params = ['id' => $this->_id];
*/
class CRM_Admin_Form_ContactType extends CRM_Admin_Form {
- public function preProcess(): void {
- CRM_Utils_Request::retrieve('action', 'String', $this);
- CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0);
- $this->set('BAOName', 'CRM_Contact_BAO_ContactType');
- parent::preProcess();
+ /**
+ * Explicitly declare the entity api name.
+ */
+ public function getDefaultEntity() {
+ return 'ContactType';
}
/**
*/
public $submitOnce = TRUE;
- public function preProcess(): void {
- CRM_Utils_Request::retrieve('action', 'String', $this);
- CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0);
- $this->set('BAOName', 'CRM_Core_BAO_LocationType');
- parent::preProcess();
+ /**
+ * Explicitly declare the entity api name.
+ */
+ public function getDefaultEntity() {
+ return 'LocationType';
}
/**
* @throws \CRM_Core_Exception
*/
public function preProcess() {
- CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0);
- $this->set('BAOName', 'CRM_Financial_BAO_PaymentProcessor');
-
parent::preProcess();
$this->setPaymentProcessorTypeID();
use CRM_Core_Form_EntityFormTrait;
+ protected $_BAOName = 'CRM_Contact_BAO_RelationshipType';
+
/**
* Fields for the entity to be assigned to the template.
*
*/
protected $entityFields = [];
- public function preProcess(): void {
- CRM_Utils_Request::retrieve('action', 'String', $this);
- CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0);
- $this->set('BAOName', 'CRM_Contact_BAO_RelationshipType');
- parent::preProcess();
- }
-
/**
* Set entity fields to be assigned to the form.
*/
return 'Tag';
}
- public function preProcess() {
- CRM_Utils_Request::retrieve('id', 'Integer', $this, FALSE);
- $this->set('BAOName', 'CRM_Core_BAO_Tag');
- parent::preProcess();
- }
-
/**
* Build the form object.
*/