type, array()); if (isset($settings['multiple']['max']) && $settings['multiple']['max'] > 0) { $locations = isset($node->locations) ? $node->locations : array(); $form['locations'] = location_form($settings, $locations); $form['locations']['#group'] = 'additional_settings'; unset($form['locations']['collapsible']); unset($form['locations']['collapsed']); } } } /** * Implementation of hook_node_delete_revision(). */ function location_node_node_delete_revision($node) { $locations = array(); location_save_locations($locations, array('vid' => $node->vid)); } /** * Implementation of hook_node_delete(). */ function location_node_node_delete($node) { $locations = array(); location_save_locations($locations, array('nid' => $node->nid)); } /** * Implementation of hook_node_load(). */ function location_node_node_load($nodes, $types) { // @@@ Resurrect the behavior from way back (1.x/2.x) that disabled existing // locations when the content type wasn't enabled for locations? // @@@TODO 7.x -- multiload version! foreach (array_keys($nodes) as $nid) { $nodes[$nid]->locations = location_load_locations($nodes[$nid]->vid); // @@@TODO 7.x -- Either reimplement or cut $node->location. } } /** * Implementation of hook_node_insert(). */ function location_node_node_insert($node) { if (!empty($node->locations)) { location_save_locations($node->locations, array('nid' => $node->nid, 'vid' => $node->vid)); } } /** * Implementation of hook_node_update(). */ function location_node_node_update($node) { return location_node_node_insert($node); } /** * Implementation of hook_node_view(). */ function location_node_node_view($node, $view_mode, $langcode) { // @@@TODO 7.x Switch to a pure "fields" approach? if (empty($node->locations)) { return; } // @@@TODO 7.x -- TEST THIS! if ($view_mode == 'rss') { $settings = variable_get('location_settings_node_' . $node->type, array()); $mode = isset($settings['rss']['mode']) ? $settings['rss']['mode'] : 'simple'; if ($mode == 'none') { return; } if (is_array($node->locations) && !empty($node->locations)) { require_once(drupal_get_path('module', 'location') . '/location.georss.inc'); $node->rss_namespaces += location_rss_namespaces($mode); foreach ($node->locations as $location) { if (($item = location_rss_item($location, $mode))) { $node->rss_elements[] = $item; } } } } else { // @@@TODO 7.x -- location_display_location is idiotic. KILL IT. if (variable_get('location_display_location', 1)) { $settings = variable_get('location_settings_node_' . $node->type, array()); if (isset($settings['display']['teaser']) && isset($settings['display']['full'])) { if (isset($settings['display'][$view_mode]) && $settings['display'][$view_mode]) { $node->content['locations'] = location_display($settings, $node->locations); } } } } } /** * Implementation of hook_locationapi(). */ function location_node_locationapi(&$obj, $op, $a3 = NULL, $a4 = NULL, $a5 = NULL) { switch ($op) { case 'instance_links': foreach ($obj as $k => $v) { if ($v['nid'] != 0) { $node = node_load($v['nid']); $obj[$k]['href'] = 'node/' . $v['nid']; $obj[$k]['title'] = $node->title; $obj[$k]['type'] = t('Node location'); } } } } /** * Alter the node_type_form form. */ function location_node_form_node_type_form_alter(&$form, &$form_state) { $type = $form['#node_type']->type; // Hook the form handlers so we can correctly extract our information; // the node type form doesn't handle nested values correctly. array_unshift($form['#validate'], 'location_node_settings_validate'); //array_unshift($form['#submit'], 'node_type_form_submit'); array_unshift($form['#submit'], '_location_node_type_save_submit'); $settings = variable_get('location_settings_node_' . $type, array()); $form['location_settings'] = location_settings($settings); $form['location_settings']['#group'] = 'additional_settings'; // Tack on customizations for node settings. $form['location_settings']['display']['teaser'] = array( '#type' => 'checkbox', '#title' => t('Display location in teaser view'), '#default_value' => isset($settings['display']['teaser']) ? $settings['display']['teaser'] : TRUE, '#weight' => -2, ); $form['location_settings']['display']['full'] = array( '#type' => 'checkbox', '#title' => t('Display location in full view'), '#default_value' => isset($settings['display']['full']) ? $settings['display']['full'] : TRUE, '#weight' => -1, ); $form['location_settings']['rss'] = array( '#type' => 'fieldset', '#title' => t('RSS Settings'), '#description' => t('Here, you can change how locative data affects RSS feeds on nodes.'), '#tree' => TRUE, '#weight' => 5, ); $form['location_settings']['rss']['mode'] = array( '#type' => 'select', '#title' => t('RSS mode'), '#description' => t('Select how to use locations in RSS feeds for this content type.'), '#options' => array( 'none' => t('None (Do not put locational data in RSS feeds)'), 'w3c' => t('W3C Geo (deprecated)'), 'w3c_bugcompat' => t('Location 1.x-2.x compatible (buggy W3C)'), 'simple' => t('GeoRSS-Simple'), 'gml' => t('GeoRSS GML'), ), '#default_value' => isset($settings['rss']['mode']) ? $settings['rss']['mode'] : 'simple', ); // Make the weights inaccessible if CCK is being used. if (module_exists('content')) { $form['location_settings']['form']['weight']['#type'] = 'value'; $form['location_settings']['form']['weight']['#value'] = $form['location_settings']['form']['weight']['#default_value']; $form['location_settings']['display']['weight']['#type'] = 'value'; $form['location_settings']['display']['weight']['#value'] = $form['location_settings']['display']['weight']['#default_value']; } // @@@ THIS IS NOT GOOD. --Bdragon // clear the views cache in case anything was changed if (function_exists('views_invalidate_cache')) { views_invalidate_cache(); } } /** * Validation function for node settings form. * Logically, the default number of locations per node cannot * be bigger than the max locations. * * @ingroup $form */ function location_node_settings_validate($form, &$form_state) { if (!empty($form_state['values']['location_settings']['multiple']['max']) && empty($form_state['values']['location_settings']['multiple']['add'])) { form_error($form['location_settings']['multiple']['add'], t("You must have at least one empty location form enabled if you are going to allow locations to be submitted for nodes of this content type. If you don't intend to allow locations to be submitted for nodes of this content type, set the maximum number of locations allowed for this content type to 0.")); } elseif ($form_state['values']['location_settings']['multiple']['max'] > 0) { if ($form_state['values']['location_settings']['multiple']['add'] > $form_state['values']['location_settings']['multiple']['max']) { form_error($form['location_settings']['multiple']['add'], t("You can't show more empty location forms than the maximum number of locations allowed for this content type.")); } } } /** * Custom submit function to save location settings properly. */ function _location_node_type_save_submit($form, &$form_state) { variable_set('location_settings_node_' . $form_state['values']['type'], $form_state['values']['location_settings']); // @@@ Backwards compatibility variables. // There are a few places in contrib where these variables are checked. variable_set('location_maxnum_' . $form_state['values']['type'], $form_state['values']['location_settings']['multiple']['max']); variable_set('location_defaultnum_' . $form_state['values']['type'], $form_state['values']['location_settings']['multiple']['add']); // Prevent the "normal" submit handler from stomping our variable. unset($form_state['values']['location_settings']); } /** * Alter the content_field_overview_form form. */ function location_node_form_content_field_overview_form_alter(&$form, &$form_state) { $form['#submit'][] = 'location_node_content_extra_save'; } /** * Implementation of hook_content_extra_fields(). * * For being able to edit location weight in node forms and node view. */ function location_node_content_extra_fields($type_name) { $settings = variable_get('location_settings_node_' . $type_name, array()); if (isset($settings['multiple']) && $settings['multiple']['max'] > 0) { $weight = isset($settings['form']['weight']) ? $settings['form']['weight'] : 0; $extra['locations'] = array( 'label' => t('Locations'), 'description' => t('Node Locations module form.'), 'weight' => $weight, ); return $extra; } } /** * Saving the fields management's weight for location node data in forms and node view * * @param $form * @param $form_state */ function location_node_content_extra_save($form, &$form_state) { $type = $form['#type_name']; // We need to stay in sync with CCK's idea of the weight. $settings = variable_get('location_settings_node_' . $type, array()); if (isset($form_state['values']['locations'])) { $settings['form']['weight'] = $form_state['values']['locations']['weight']; $settings['display']['weight'] = $form_state['values']['locations']['weight']; } variable_set('location_settings_node_' . $type, $settings); }