You are here

function eck__extra_field_widget_form_submit in Entity Construction Kit (ECK) 7.3

Submit callback.

To change the widget for a property field from a bundle's field management form.

File

./eck.bundle.inc, line 779

Code

function eck__extra_field_widget_form_submit($form, &$form_state) {

  // Load entity_type and bundle in case they have changed since the form was
  // first built.
  $entity_type = entity_type_load($form['#entity_type']->name);
  $bundle = bundle_load($entity_type->name, $form['#bundle']->name);

  // Update the widget settings if it has changed.
  if ($form['#default_widget'] != $form_state['values']['widget_type']) {

    // Grab the config settings for this bundle so we can alter them.
    $config = !empty($bundle->config) ? $bundle->config : array();
    if (isset($config['extra_fields'][$form['#property_name']]['form'])) {
      $widget_info = eck_property_info_widget_types($form_state['values']['widget_type']);

      // Changing the widget so make sure to start with the default widget
      // settings.
      $widget = array(
        'type' => $form_state['values']['widget_type'],
        'settings' => $widget_info['default settings'],
      );
      $config['extra_fields'][$form['#property_name']]['form']['widget'] = $widget;
      $bundle->config = $config;

      // Save the bundle.
      $bundle
        ->save();
      Bundle::loadAll(NULL, TRUE);
    }
    else {

      // The extra field form setting was not found in the config so it must no
      // longer be managed. Don't do anything except notify the user.
      drupal_set_message(t('Could not change the property widget. The property %name on the %bundle bundle is no selected for management.', array(
        '%name' => $form['#property_name'],
        '%bundle' => $bundle->label,
      )), 'error');
    }
  }
  $form_state['redirect'] = 'admin/structure/entity-type/' . $entity_type->name . '/' . $bundle->name . '/fields';
}