Beispiel #1
0
 /**
  * Reset values for all options those are full.
  *
  * @param array $optionFullIds
  * @param CRM_Core_Form $form
  */
 public static function resetElementValue($optionFullIds = array(), &$form)
 {
     if (!is_array($optionFullIds) || empty($optionFullIds) || !$form->isSubmitted()) {
         return;
     }
     foreach ($optionFullIds as $fldId => $optIds) {
         $name = "price_{$fldId}";
         if (!$form->elementExists($name)) {
             continue;
         }
         $element = $form->getElement($name);
         $eleType = $element->getType();
         $resetSubmitted = FALSE;
         switch ($eleType) {
             case 'text':
                 if ($element->getValue() && $element->isFrozen()) {
                     $label = "{$element->getLabel()}<tt>(x)</tt>";
                     $element->setLabel($label);
                     $element->setPersistantFreeze();
                     $resetSubmitted = TRUE;
                 }
                 break;
             case 'group':
                 if (is_array($element->_elements)) {
                     foreach ($element->_elements as $child) {
                         $childType = $child->getType();
                         $methodName = 'getName';
                         if ($childType) {
                             $methodName = 'getValue';
                         }
                         if (in_array($child->{$methodName}(), $optIds) && $child->isFrozen()) {
                             $resetSubmitted = TRUE;
                             $child->setPersistantFreeze();
                         }
                     }
                 }
                 break;
             case 'select':
                 $value = $element->getValue();
                 if (in_array($value[0], $optIds)) {
                     foreach ($element->_options as $option) {
                         if ($option['attr']['value'] === "crm_disabled_opt-{$value[0]}") {
                             $placeholder = html_entity_decode($option['text'], ENT_QUOTES, "UTF-8");
                             $element->updateAttributes(array('placeholder' => $placeholder));
                             break;
                         }
                     }
                     $resetSubmitted = TRUE;
                 }
                 break;
         }
         //finally unset values from submitted.
         if ($resetSubmitted) {
             self::resetSubmittedValue($name, $optIds, $form);
         }
     }
 }
Beispiel #2
0
/**
 * @param string $formName
 * @param CRM_Core_Form $form
 */
function hremerg_civicrm_buildForm($formName, &$form)
{
    if ($formName == 'CRM_Contact_Form_Relationship' && empty($form->_caseId)) {
        if ($form->elementExists('relationship_type_id') && $form->_contactType == 'Individual') {
            $relationshipType = civicrm_api3('relationship_type', 'get', array('name_a_b' => 'Emergency Contact'));
            $select = $form->getElement('relationship_type_id');
            $select->freeze();
            $select->setLabel('');
            $form->getElement('related_contact_id')->setLabel('');
            if ($form->getAction() & CRM_Core_Action::ADD && !empty($relationshipType['id'])) {
                $form->setDefaults(array('relationship_type_id' => $relationshipType['id'] . '_a_b'));
            }
        }
    }
}