protected $_values = array();
protected $unsavedWarn = TRUE;
+
+ /**
+ * Explicitly declare the entity api name.
+ */
+ public function getDefaultEntity() {
+ return 'Activity';
+ }
/**
* The _fields var can be used by sub class to set/unset/edit the
*
*/
class CRM_Admin_Form_ParticipantStatusType extends CRM_Admin_Form {
+
+ /**
+ * Explicitly declare the entity api name.
+ */
+ public function getDefaultEntity() {
+ return 'ParticipantStatusType';
+ }
+
public function buildQuickForm() {
parent::buildQuickForm();
*/
class CRM_Admin_Form_Tag extends CRM_Admin_Form {
protected $_isTagSet;
+
+ /**
+ * Explicitly declare the entity api name.
+ */
+ public function getDefaultEntity() {
+ return 'Tag';
+ }
/**
* Build the form object.
* @var int
*/
protected $_campaignId;
+
+ /**
+ * Explicitly declare the entity api name.
+ */
+ public function getDefaultEntity() {
+ return 'Campaign';
+ }
public function preProcess() {
if (!CRM_Campaign_BAO_Campaign::accessCampaign()) {
* @var string
*/
protected $_context;
+
+ /**
+ * Explicitly declare the entity api name.
+ */
+ public function getDefaultEntity() {
+ return 'Survey';
+ }
public function preProcess() {
parent::preProcess();
* during the write phase
*/
public $_preEditValues;
+
+ /**
+ * Explicitly declare the entity api name.
+ */
+ public function getDefaultEntity() {
+ return 'Contact';
+ }
/**
* Build all the data structures needed to build the form.
protected $_customSearchClass = NULL;
protected $_openedPanes = array();
+
+ /**
+ * Explicitly declare the entity api name.
+ */
+ public function getDefaultEntity() {
+ return 'Contact';
+ }
/**
* Define the set of valid contexts that the search form operates on.
protected $_priceSetID = NULL;
protected $_values;
+
+ /**
+ * Explicitly declare the entity api name.
+ */
+ public function getDefaultEntity() {
+ return 'Contribution';
+ }
/**
* Set variables up before form is built.
$this->addDate($name . $to, ts('To:'), $required, array('formatType' => $dateFormat));
}
}
+
+ /**
+ * Classes extending CRM_Core_Form should implement this method.
+ * @throws Exception
+ */
+ public function getDefaultEntity() {
+ throw new Exception("Cannot determine default entity. The form class should implement getDefaultEntity().");
+ }
/**
* Adds a select based on field metadata.
*/
public function addSelect($name, $props = array(), $required = FALSE) {
if (!isset($props['entity'])) {
- if (isset($this->entityName)) {
- $props['entity'] = $this->entityName;
- }
- else {
- $props['entity'] = CRM_Utils_Api::getEntityName($this);
- }
+ $props['entity'] = $this->getDefaultEntity();
}
if (!isset($props['field'])) {
$props['field'] = strrpos($name, '[') ? rtrim(substr($name, 1 + strrpos($name, '[')), ']') : $name;
* Check if repeating event.
*/
public $_isRepeatingEvent;
-
+
/**
* Explicitly declare the entity api name.
*/
- public $entityName = 'Event';
+ public function getDefaultEntity() {
+ return 'Event';
+ }
/**
* Set variables up before form is built.
* @var null
*/
public $_onlinePendingContributionId = NULL;
+
+ /**
+ * Explicitly declare the entity api name.
+ */
+ public function getDefaultEntity() {
+ return 'Participant';
+ }
/**
* Set variables up before form is built.
*
*/
class CRM_Event_Form_SearchEvent extends CRM_Core_Form {
+
+ /**
+ * Explicitly declare the entity api name.
+ */
+ public function getDefaultEntity() {
+ return 'Event';
+ }
/**
* @return array
protected $_contactID;
protected $_context;
+
+ /**
+ * Explicitly declare the entity api name.
+ */
+ public function getDefaultEntity() {
+ return 'Grant';
+ }
/**
* Set variables up before form is built.
* @var string
*/
protected $_BAOName;
+
+ /**
+ * Explicitly declare the entity api name.
+ */
+ public function getDefaultEntity() {
+ return 'MembershipType';
+ }
public function preProcess() {
$this->_id = $this->get('id');
protected $_currentUserID = NULL;
protected $_session = NULL;
+
+ /**
+ * Explicitly declare the entity api name.
+ */
+ public function getDefaultEntity() {
+ return 'Profile';
+ }
/**
* Pre processing work done here.
+++ /dev/null
-<?php
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.6 |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014 |
- +--------------------------------------------------------------------+
- | This file is a part of CiviCRM. |
- | |
- | CiviCRM is free software; you can copy, modify, and distribute it |
- | under the terms of the GNU Affero General Public License |
- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
- | |
- | CiviCRM is distributed in the hope that it will be useful, but |
- | WITHOUT ANY WARRANTY; without even the implied warranty of |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
- | See the GNU Affero General Public License for more details. |
- | |
- | You should have received a copy of the GNU Affero General Public |
- | License and the CiviCRM Licensing Exception along |
- | with this program; if not, contact CiviCRM LLC |
- | at info[AT]civicrm[DOT]org. If you have questions about the |
- | GNU Affero General Public License or the licensing of CiviCRM, |
- | see the CiviCRM license FAQ at http://civicrm.org/licensing |
- +--------------------------------------------------------------------+
- */
-
-/**
- * Class CRM_Utils_Api
- */
-class CRM_Utils_Api {
- /**
- * Attempts to retrieve the API entity name from any calling class.
- * FIXME: This is a bit hackish but the naming convention for forms is not very strict
- *
- * @param string|object $classNameOrObject
- *
- * @return string
- * @throws CRM_Core_Exception
- */
- public static function getEntityName($classNameOrObject) {
- require_once 'api/api.php';
- $className = is_string($classNameOrObject) ? $classNameOrObject : get_class($classNameOrObject);
-
- // First try the obvious replacements
- $daoName = str_replace(array('_BAO_', '_Form_', '_Page_'), '_DAO_', $className);
- $entityName = CRM_Core_DAO_AllCoreTables::getBriefName($daoName);
-
- // If that didn't work, try a different pattern
- if (!$entityName) {
- list(, $parent, , $child) = explode('_', $className);
- $daoName = "CRM_{$parent}_DAO_$child";
- $entityName = CRM_Core_DAO_AllCoreTables::getBriefName($daoName);
- }
-
- // If that didn't work, try a different pattern
- if (!$entityName) {
- $daoName = "CRM_{$parent}_DAO_$parent";
- $entityName = CRM_Core_DAO_AllCoreTables::getBriefName($daoName);
- }
-
- // If that didn't work, try a different pattern
- if (!$entityName) {
- $daoName = "CRM_Core_DAO_$child";
- $entityName = CRM_Core_DAO_AllCoreTables::getBriefName($daoName);
- }
-
- // If that didn't work, try using just the trailing name
- if (!$entityName) {
- $entityName = CRM_Core_DAO_AllCoreTables::getFullName($child) ? $child : NULL;
- }
-
- // If that didn't work, try using just the leading name
- if (!$entityName) {
- $entityName = CRM_Core_DAO_AllCoreTables::getFullName($parent) ? $parent : NULL;
- }
-
- if (!$entityName) {
- throw new CRM_Core_Exception('Could not find api name for supplied class');
- }
- return $entityName;
- }
-
-}