You are here

function node_gallery_relationship_settings_form_submit in Node Gallery 6.3

Submit handler for relationship settings form

_state

Parameters

$form:

1 string reference to 'node_gallery_relationship_settings_form_submit'
node_gallery_relationship_settings_form in ./node_gallery.admin.inc
Returns a FAPI form array that renders the settings form when adding/editing a Gallery-to-Image relationship

File

./node_gallery.admin.inc, line 486

Code

function node_gallery_relationship_settings_form_submit($form, &$form_state) {
  $r = (object) $form['#relationship'];
  $r->imagefield_name = $form_state['values']['imagefield'];
  if ($r->imagefield_name == 'field_node_gallery_image') {

    // if the field is named 'field_node_gallery_image' check if it exists
    // or if we need to create it. We could hack around that check with a pre- or
    // suffix, but I rate this way cleaner (though more costly).
    $param = array(
      'type_name' => $r->image_type,
      'field_name' => $r->imagefield_name,
    );
    if (!node_gallery_cck_field_exists($param)) {

      // @todo: there's a little bit of DRY going on here and in node_gallery_install_cck_type() in .install.
      //  We should pull this into a common function at some point.
      // create the default imagefield read out of the default type
      $path = drupal_get_path('module', 'node_gallery') . "/cck_types";
      $cck_file = $path . '/node_gallery_image.cck';
      $param = array(
        'type_name' => $r->image_type,
      );
      $content = array();
      eval(file_get_contents($cck_file));
      $param = array_merge($param, array_pop($content['fields']));
      unset($content);
      content_field_instance_create($param);
      drupal_set_message(t('Node Gallery imagefield created.'));
    }
  }
  $settings = isset($r->settings) ? $r->settings : array();
  $valid_settings = array_keys(node_gallery_relationship_settings_defaults());
  foreach ((array) $form_state['values'] as $k => $v) {
    if (in_array($k, $valid_settings)) {
      $settings[$k] = $v;
    }
  }
  $r->settings = $settings;
  drupal_write_record('node_gallery_relationships', $r, 'rid');
  menu_cache_clear_all();
  drupal_set_message(t('Node Gallery relationship updated'));

  // Repopulate the cache
  node_gallery_get_relationship($r->gallery_type, TRUE);
  $form_state['redirect'] = 'admin/settings/node_gallery';
}