You are here

function merci_restrictions_field_widget_form_alter in MERCI (Manage Equipment Reservations, Checkout and Inventory) 7.3

File

merci_restrictions/merci_restrictions.module, line 17

Code

function merci_restrictions_field_widget_form_alter(&$element, &$form_state, $context) {

  // Add a css class to widget form elements for all fields of type mytype.
  if ($context['field']['field_name'] == MERCI_OVERRIDE_RESTRICTIONS) {
    $line_item = $element['target_id']['#entity'];
    if (property_exists($line_item, MERCI_OVERRIDE_RESTRICTIONS) and !empty($line_item->{MERCI_OVERRIDE_RESTRICTIONS}['und'])) {
      return;
    }

    // Be sure not to overwrite existing attributes.
    $element['#attributes']['class'][] = 'myclass';
    $element['override_password'] = array(
      '#type' => 'password',
      '#title' => t('Password'),
    );
    $element['#type'] = 'fieldset';
    $element['#title'] = 'Override restrictions';
    $element['#element_validate'][] = 'merci_restrictions_override_validate';
  }
}