You are here

function hashtags_configuration_form_content_type_settings_submit in Hashtags 7.2

1 string reference to 'hashtags_configuration_form_content_type_settings_submit'
hashtags_configuration_form in ./hashtags.module
Hashtags configuration form

File

./hashtags.module, line 318

Code

function hashtags_configuration_form_content_type_settings_submit($form, &$form_state) {
  if ($form_state['clicked_button']['#value'] == t('Save configuration')) {
    $field_name = variable_get('hashtags_terms_field', '');
    foreach ($form_state['values']['hashtags_content_types'] as $content_type => $checked) {
      $instance = field_info_instance('node', $field_name, $content_type);
      if ($content_type === $checked) {
        if (!is_array($instance)) {
          $instance = array(
            'field_name' => $field_name,
            'entity_type' => 'node',
            'label' => 'Hashtags',
            'bundle' => $content_type,
            'widget' => array(
              'type' => 'taxonomy_autocomplete',
              'weight' => -4,
            ),
            'display' => array(
              'default' => array(
                'type' => 'taxonomy_term_reference_link',
                'weight' => 10,
              ),
              'teaser' => array(
                'type' => 'taxonomy_term_reference_link',
                'weight' => 10,
              ),
            ),
          );
          field_create_instance($instance);
        }
      }
      else {
        if (is_array($instance)) {
          field_delete_instance($instance, FALSE);
        }
      }
    }

    //cache_clear_all();
    drupal_set_message(t('Content types changes have been saved.'));
  }
}