当前位置: 首页>>代码示例>>PHP>>正文


PHP CRM_Core_PseudoConstant::getOptionEditUrl方法代码示例

本文整理汇总了PHP中CRM_Core_PseudoConstant::getOptionEditUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_PseudoConstant::getOptionEditUrl方法的具体用法?PHP CRM_Core_PseudoConstant::getOptionEditUrl怎么用?PHP CRM_Core_PseudoConstant::getOptionEditUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CRM_Core_PseudoConstant的用法示例。


在下文中一共展示了CRM_Core_PseudoConstant::getOptionEditUrl方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addField

 /**
  * Adds a field based on metadata.
  *
  * @param $name
  *   Field name to go on the form.
  * @param array $props
  *   Mix of html attributes and special properties, namely.
  *   - entity (api entity name, can usually be inferred automatically from the form class)
  *   - name (field name - only needed if different from name used on the form)
  *   - option_url - path to edit this option list - usually retrieved automatically - set to NULL to disable link
  *   - placeholder - set to NULL to disable
  *   - multiple - bool
  *   - context - @see CRM_Core_DAO::buildOptionsContext
  * @param bool $required
  * @throws \CiviCRM_API3_Exception
  * @throws \Exception
  * @return HTML_QuickForm_Element
  */
 public function addField($name, $props = array(), $required = FALSE)
 {
     // Resolve context.
     if (empty($props['context'])) {
         $props['context'] = $this->getDefaultContext();
     }
     $context = $props['context'];
     // Resolve entity.
     if (empty($props['entity'])) {
         $props['entity'] = $this->getDefaultEntity();
     }
     // Resolve field.
     if (empty($props['name'])) {
         $props['name'] = strrpos($name, '[') ? rtrim(substr($name, 1 + strrpos($name, '[')), ']') : $name;
     }
     // Resolve action.
     if (empty($props['action'])) {
         $props['action'] = $this->getApiAction();
     }
     // Handle custom fields
     if (strpos($name, 'custom_') === 0 && is_numeric($name[7])) {
         $fieldId = (int) substr($name, 7);
         return CRM_Core_BAO_CustomField::addQuickFormElement($this, $name, $fieldId, $required, $context == 'search', CRM_Utils_Array::value('label', $props));
     }
     // Core field - get metadata.
     $fieldSpec = civicrm_api3($props['entity'], 'getfield', $props);
     $fieldSpec = $fieldSpec['values'];
     $label = CRM_Utils_Array::value('label', $props, isset($fieldSpec['title']) ? $fieldSpec['title'] : NULL);
     $widget = isset($props['type']) ? $props['type'] : $fieldSpec['html']['type'];
     if ($widget == 'TextArea' && $context == 'search') {
         $widget = 'Text';
     }
     $isSelect = in_array($widget, array('Select', 'CheckBoxGroup', 'RadioGroup', 'Radio'));
     if ($isSelect) {
         // Fetch options from the api unless passed explicitly.
         if (isset($props['options'])) {
             $options = $props['options'];
         } else {
             $options = isset($fieldSpec['options']) ? $fieldSpec['options'] : NULL;
         }
         if ($context == 'search') {
             $widget = 'Select';
             $props['multiple'] = CRM_Utils_Array::value('multiple', $props, TRUE);
         }
         // Add data for popup link.
         if ((!empty($props['option_url']) || !array_key_exists('option_url', $props)) && ($context != 'search' && $widget == 'Select' && CRM_Core_Permission::check('administer CiviCRM'))) {
             $props['data-option-edit-path'] = !empty($props['option_url']) ? $props['option_url'] : CRM_Core_PseudoConstant::getOptionEditUrl($fieldSpec);
             $props['data-api-entity'] = $props['entity'];
             $props['data-api-field'] = $props['name'];
         }
     }
     $props += CRM_Utils_Array::value('html', $fieldSpec, array());
     CRM_Utils_Array::remove($props, 'entity', 'name', 'context', 'label', 'action', 'type', 'option_url', 'options');
     // TODO: refactor switch statement, to separate methods.
     switch ($widget) {
         case 'Text':
         case 'Url':
         case 'Number':
         case 'Email':
             //TODO: Autodetect ranges
             $props['size'] = isset($props['size']) ? $props['size'] : 60;
             return $this->add(strtolower($widget), $name, $label, $props, $required);
         case 'hidden':
             return $this->add('hidden', $name, NULL, $props, $required);
         case 'TextArea':
             //Set default columns and rows for textarea.
             $props['rows'] = isset($props['rows']) ? $props['rows'] : 4;
             $props['cols'] = isset($props['cols']) ? $props['cols'] : 60;
             return $this->add('textarea', $name, $label, $props, $required);
         case 'Select Date':
             //TODO: add range support
             //TODO: Add date formats
             //TODO: Add javascript template for dates.
             return $this->addDate($name, $label, $required, $props);
         case 'Radio':
             $separator = isset($props['separator']) ? $props['separator'] : NULL;
             unset($props['separator']);
             if (!isset($props['allowClear'])) {
                 $props['allowClear'] = !$required;
             }
             return $this->addRadio($name, $label, $options, $props, $separator, $required);
         case 'ChainSelect':
//.........这里部分代码省略.........
开发者ID:saurabhbatra96,项目名称:civicrm-core,代码行数:101,代码来源:Form.php

示例2: addField

 /**
  * Adds a field based on metadata.
  *
  * @param $name
  *   Field name to go on the form.
  * @param array $props
  *   Mix of html attributes and special properties, namely.
  *   - entity (api entity name, can usually be inferred automatically from the form class)
  *   - name (field name - only needed if different from name used on the form)
  *   - option_url - path to edit this option list - usually retrieved automatically - set to NULL to disable link
  *   - placeholder - set to NULL to disable
  *   - multiple - bool
  *   - context - @see CRM_Core_DAO::buildOptionsContext
  * @param bool $required
  * @throws \CiviCRM_API3_Exception
  * @throws \Exception
  * @return HTML_QuickForm_Element
  */
 public function addField($name, $props = array(), $required = FALSE)
 {
     // TODO: Handle custom field
     if (strpos($name, 'custom_') === 0 && is_numeric($name[7])) {
         throw new Exception("Custom fields are not supported by the addField method. ");
     }
     // Resolve context.
     if (!isset($props['context'])) {
         $props['context'] = $this->getDefaultContext();
     }
     // Resolve entity.
     if (!isset($props['entity'])) {
         $props['entity'] = $this->getDefaultEntity();
     }
     // Resolve field.
     if (!isset($props['name'])) {
         $props['name'] = strrpos($name, '[') ? rtrim(substr($name, 1 + strrpos($name, '[')), ']') : $name;
     }
     // Resolve action.
     if (!isset($props['action'])) {
         $props['action'] = $this->getApiAction();
     }
     // Get field metadata.
     $fieldSpec = civicrm_api3($props['entity'], 'getfield', $props);
     $fieldSpec = $fieldSpec['values'];
     $label = CRM_Utils_Array::value('label', $props, isset($fieldSpec['title']) ? $fieldSpec['title'] : NULL);
     $widget = isset($props['type']) ? $props['type'] : $fieldSpec['html']['type'];
     if ($widget == 'TextArea' && $props['context'] == 'search') {
         $widget = 'Text';
     }
     $isSelect = in_array($widget, array('Select', 'Multi-Select', 'Select State/Province', 'Multi-Select State/Province', 'Select Country', 'Multi-Select Country', 'AdvMulti-Select', 'CheckBoxGroup', 'RadioGroup', 'Radio'));
     if ($isSelect) {
         // Fetch options from the api unless passed explicitly.
         if (isset($props['options'])) {
             $options = $props['options'];
             // Else this get passed to the form->add method.
             unset($props['options']);
         } else {
             $options = isset($fieldSpec['options']) ? $fieldSpec['options'] : NULL;
         }
         //@TODO AdvMulti-Select is deprecated, drop support.
         if ($props['context'] == 'search' || $widget !== 'AdvMulti-Select' && strpos($widget, 'Select') !== FALSE) {
             $widget = 'Select';
         }
         // Set default options-url value.
         if (!isset($props['options-url'])) {
             $props['options-url'] = TRUE;
         }
         // Add data for popup link.
         if (isset($props['options-url']) && $props['options-url'] && ($props['context'] != 'search' && $widget == 'Select' && CRM_Core_Permission::check('administer CiviCRM'))) {
             $props['data-option-edit-path'] = array_key_exists('option_url', $props) ? $props['option_url'] : ($props['data-option-edit-path'] = CRM_Core_PseudoConstant::getOptionEditUrl($fieldSpec));
             $props['data-api-entity'] = $props['entity'];
             $props['data-api-field'] = $props['name'];
             if (isset($props['options-url'])) {
                 unset($props['options-url']);
             }
         }
     }
     //Use select2 library for following widgets.
     $isSelect2 = in_array($widget, array('Select', 'Multi-Select', 'Select State/Province', 'Multi-Select State/Province', 'Select Country', 'Multi-Select Country'));
     if ($isSelect2) {
         $props['class'] = (isset($props['class']) ? $props['class'] . ' ' : '') . "crm-select2";
         if ($props['context'] == 'search' || strpos($widget, 'Multi') !== FALSE) {
             $props['class'] .= ' huge';
             $props['multiple'] = 'multiple';
         }
         // The placeholder is only used for select-elements.
         if (!array_key_exists('placeholder', $props)) {
             $props['placeholder'] = $required ? ts('- select -') : $props['context'] == 'search' ? ts('- any -') : ts('- none -');
         }
     }
     $props += CRM_Utils_Array::value('html', $fieldSpec, array());
     CRM_Utils_Array::remove($props, 'entity', 'name', 'context', 'label', 'action', 'type');
     // TODO: refactor switch statement, to separate methods.
     switch ($widget) {
         case 'Text':
         case 'Link':
             //TODO: Autodetect ranges
             $props['size'] = isset($props['size']) ? $props['size'] : 60;
             return $this->add('text', $name, $label, $props, $required);
         case 'hidden':
             return $this->add('hidden', $name, NULL, $props, $required);
//.........这里部分代码省略.........
开发者ID:hoegrammer,项目名称:civicrm-core,代码行数:101,代码来源:Form.php

示例3: addSelect

 /**
  * Adds a select based on field metadata.
  * TODO: This could be even more generic and widget type (select in this case) could also be read from metadata
  * Perhaps a method like $form->bind($name) which would look up all metadata for named field
  * @param $name
  *   Field name to go on the form.
  * @param array $props
  *   Mix of html attributes and special properties, namely.
  *   - entity (api entity name, can usually be inferred automatically from the form class)
  *   - field (field name - only needed if different from name used on the form)
  *   - option_url - path to edit this option list - usually retrieved automatically - set to NULL to disable link
  *   - placeholder - set to NULL to disable
  *   - multiple - bool
  *   - context - @see CRM_Core_DAO::buildOptionsContext
  * @param bool $required
  * @throws CRM_Core_Exception
  * @return HTML_QuickForm_Element
  */
 public function addSelect($name, $props = array(), $required = FALSE)
 {
     if (!isset($props['entity'])) {
         $props['entity'] = CRM_Utils_Api::getEntityName($this);
     }
     if (!isset($props['field'])) {
         $props['field'] = strrpos($name, '[') ? rtrim(substr($name, 1 + strrpos($name, '[')), ']') : $name;
     }
     // Fetch options from the api unless passed explicitly
     if (isset($props['options'])) {
         $options = $props['options'];
     } else {
         $info = civicrm_api3($props['entity'], 'getoptions', $props);
         $options = $info['values'];
     }
     if (!array_key_exists('placeholder', $props)) {
         $props['placeholder'] = $required ? ts('- select -') : CRM_Utils_Array::value('context', $props) == 'search' ? ts('- any -') : ts('- none -');
     }
     // Handle custom field
     if (strpos($name, 'custom_') === 0 && is_numeric($name[7])) {
         list(, $id) = explode('_', $name);
         $label = isset($props['label']) ? $props['label'] : CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', 'label', $id);
         $gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', 'option_group_id', $id);
         if (CRM_Utils_Array::value('context', $props) != 'search') {
             $props['data-option-edit-path'] = array_key_exists('option_url', $props) ? $props['option_url'] : 'civicrm/admin/options/' . CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $gid);
         }
     } else {
         $info = civicrm_api3($props['entity'], 'getfields');
         foreach ($info['values'] as $uniqueName => $fieldSpec) {
             if ($uniqueName === $props['field'] || CRM_Utils_Array::value('name', $fieldSpec) === $props['field'] || in_array($props['field'], CRM_Utils_Array::value('api.aliases', $fieldSpec, array()))) {
                 break;
             }
         }
         $label = isset($props['label']) ? $props['label'] : $fieldSpec['title'];
         if (CRM_Utils_Array::value('context', $props) != 'search') {
             $props['data-option-edit-path'] = array_key_exists('option_url', $props) ? $props['option_url'] : ($props['data-option-edit-path'] = CRM_Core_PseudoConstant::getOptionEditUrl($fieldSpec));
         }
     }
     $props['class'] = (isset($props['class']) ? $props['class'] . ' ' : '') . "crm-select2";
     $props['data-api-entity'] = $props['entity'];
     $props['data-api-field'] = $props['field'];
     CRM_Utils_Array::remove($props, 'label', 'entity', 'field', 'option_url', 'options', 'context');
     return $this->add('select', $name, $label, $options, $required, $props);
 }
开发者ID:JSProffitt,项目名称:civicrm-website-org,代码行数:62,代码来源:Form.php


注:本文中的CRM_Core_PseudoConstant::getOptionEditUrl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。