You are here

function hijri_settings_form_submit in Hijri 7

Same name and namespace in other branches
  1. 8 _hijri.module \hijri_settings_form_submit()

Form submit handler.

1 string reference to 'hijri_settings_form_submit'
hijri_settings_form in ./hijri.module
Form builder.

File

./hijri.module, line 236
This module convert to Hijri date in nodes,comments and a block.

Code

function hijri_settings_form_submit($form, &$form_state) {

  // Check if our field is not already created.
  if (!field_info_field('field_hijri_correction')) {

    // Create the field base.
    $field = array(
      'field_name' => 'field_hijri_correction',
      'type' => 'number_integer',
    );
    field_create_field($field);
  }
  foreach ($form_state['values']['hijri_types'] as $key => $type) {

    // Create the instance.
    $instance = array(
      'field_name' => 'field_hijri_correction',
      'entity_type' => 'node',
      'bundle' => $key,
      'label' => t('Hijri Date Correction'),
      'description' => t('This field will save the Correction and different between months'),
      'required' => FALSE,
    );
    if ((string) $type == (string) $key) {
      $prior_instance = field_read_instance($instance['entity_type'], $instance['field_name'], $instance['bundle']);
      if (empty($prior_instance)) {
        field_create_instance($instance);
      }
    }
    else {
      $prior_instance = field_read_instance($instance['entity_type'], $instance['field_name'], $instance['bundle']);
      if (!empty($prior_instance)) {
        field_delete_instance($instance, FALSE);
      }
    }
  }
}