You are here

function location_cck_field_settings in Location 6.3

Same name and namespace in other branches
  1. 5.3 contrib/location_cck/location_cck.module \location_cck_field_settings()
  2. 7.5 contrib/location_cck/location_cck.module \location_cck_field_settings()
  3. 7.3 contrib/location_cck/location_cck.module \location_cck_field_settings()
  4. 7.4 contrib/location_cck/location_cck.module \location_cck_field_settings()

Implementation of hook_field_settings().

File

contrib/location_cck/location_cck.module, line 52
Defines location field type.

Code

function location_cck_field_settings($op, $field) {
  switch ($op) {
    case 'form':
      $form = array();
      $settings = isset($field['location_settings']) ? $field['location_settings'] : FALSE;
      $form['location_settings'] = location_settings($settings);

      // Multiple is handled by CCK.
      unset($form['location_settings']['multiple']);

      // CCK handles weight, and collapsibility is not changeable.
      unset($form['location_settings']['form']['weight']);
      unset($form['location_settings']['form']['collapsible']);
      unset($form['location_settings']['form']['collapsed']);
      unset($form['location_settings']['display']['weight']);

      // We want to see the settings, so uncollapse them.
      $form['location_settings']['#collapsible'] = FALSE;
      $form['location_settings']['form']['#collapsed'] = FALSE;
      $form['location_settings']['display']['#collapsed'] = FALSE;

      // Add some GMap settings, if GMap is enabled.
      if (module_exists('gmap')) {
        $form['gmap_macro'] = array(
          '#type' => 'textarea',
          '#title' => t('GMap Macro'),
          '#rows' => 2,
          '#maxlength' => 500,
          '#description' => t('A macro to be used as a base map for this field.  This map will be recentered on the location, so the center is not that important.'),
          '#default_value' => !empty($field['gmap_macro']) ? $field['gmap_macro'] : '[gmap ]',
        );
        $options = gmap_get_marker_titles();
        $form['gmap_marker'] = array(
          '#type' => 'select',
          '#title' => t('GMap marker'),
          '#options' => $options,
          '#default_value' => !empty($field['gmap_marker']) ? $field['gmap_marker'] : 'drupal',
        );
      }
      else {

        // Preserve existing data, apply defaults even if gmap is disabled.
        $form['gmap_macro'] = array(
          '#type' => 'value',
          '#value' => !empty($field['gmap_macro']) ? $field['gmap_macro'] : '[gmap ]',
        );
        $form['gmap_marker'] = array(
          '#type' => 'value',
          '#value' => !empty($field['gmap_marker']) ? $field['gmap_marker'] : 'drupal',
        );
      }
      return $form;
    case 'save':
      return array(
        'location_settings',
        'gmap_macro',
        'gmap_marker',
      );
    case 'database columns':
      return array(
        'lid' => array(
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => FALSE,
        ),
      );
    case 'views data':

      // We want to for the most part use the CCK stuff, but we also want to
      // patch in a relationship so location's views support can target
      // cck fields directly.
      $table = content_views_tablename($field);
      $db_info = content_database_info($field);
      $field_alias = $db_info['columns']['lid']['column'];
      $data = content_views_field_views_data($field);
      $data[$table][$field_alias]['relationship'] = array(
        'base' => 'location',
        'field' => $field_alias,
        'handler' => 'views_handler_relationship',
        'label' => t('Location'),
      );
      return $data;
  }
}