This task issue is for my work on the location_cck module. The patch(es) will probably grow and change depending on reviews and if anything gets committed. But I plan to document all the changes in the patch in the comments for each change.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dragonwize’s picture

FileSize
990 bytes

CCK calls a load op for each field so it may load its data but since that could result in may queries ran the first load is cached for re-use. Working on location_cck_field()'s load op first eluded me because of that. Only on clear cache would the load op actually be called. Just modifying the $item or $node vars was not enough because the data would only be loaded on first run but not on refresh.

For field data to be cached it has to be returned in a certain format.

return array($field['field_name'] => $items);

Now with this patch, the $node->field_LOCATION_FIELDNAME will be populated with all the location data not just the lid.

bdragon’s picture

oh, so THAT's the trick? Nice!

bdragon’s picture

OK, confirmed, that's how to get cck to keep the locations cached. Awesome!

http://drupal.org/cvs?commit=175710
http://drupal.org/cvs?commit=175714

dragonwize’s picture

We can also use the same array to load a copy of the date into $node->locations and $node->location if we want. Like so:

return array($field['field_name'] => $items, 'locations' => $items, 'location' => $items[0]);

Some conditional would be involved also in case $items is empty but that is the basic idea. That would help provide some backwards compatibility for the location_cck module but I am not sure it needs or should be done. Any thoughts?

bdragon’s picture

And a followup patch: Since the location is being cached, no need to load it before theming.

http://drupal.org/cvs?commit=175718
http://drupal.org/cvs?commit=175720

Thoughts I had while coding:
I noticed location_cck_field_formatter() doesn't seem to get called.
Also, I am also loading the locations for token stuff. I wonder if it's possible to also skip loading it in this case too.

Regarding loading locations and location, that would be nice to have, node locations will have to be copied to a new field (and that considered the new "official" source internally to location) before that's feasible though, otherwise the cck locations would leak into the node locations.

dragonwize’s picture

@#4
hmm... on second thought that might be more trouble some than it appears. It would work fine for only 1 location_cck field. If the content type had more than one location field it would get really messy. Not sure how that would be best handled but even if we keyed the arrays with field names it would lose the backwards compat which destroys the whole reason for it any way.

dragonwize’s picture

Here is the patch I promised a month ago. Back into working on this. This patch puts the location fields into $node->locations like we discussed on IRC.

Next I will be working on the cleaning up more and better views integration.

YesCT’s picture

tagging. nice to see this!

dragonwize’s picture

Title: Working on location_cck » location_cck back compat and views support
Status: Active » Needs work

ok, this patch has some fixed views support rolled in as well with the previously uncommitted backward compat support with location_node.

This patch currently supports views relationships which allows pulling each piece of the fields (address, city, country, etc) into your view for display. The ability to filter with that relationship does not yet work though and I haven't tested using arguments yet.

I am continuing to work on the views support. Also I've started to try and get a more organized movement around geo in drupal so drop by #drupal-geo and help hash anything out.

YesCT’s picture

#drupal-geo sounds like a good place to work on a sprint to try and work "real time" on some location issues.

#452806: sprint? can bdragon make it?

dragonwize’s picture

Status: Needs work » Needs review

With my testing so far, this patch is working well with the latest HEAD. All views elements are working including filters, exposed filters, and relationships.

dragonwize’s picture

Forgot the patch :)

KarenS’s picture

The 'arguments' and 'views' sections need to be removed altogether. That is the way things worked in D5, those operations are not invoked in D6 and should be removed. I haven't done anything with the rest of the patch, just wanted to note that much.

SocialNicheGuru’s picture

There are a billion threads on cck location and proximity filter. would this patch help that issue also?

q0rban’s picture

Status: Needs review » Needs work

Tried the patch out in #12 and views still don't seem to work. Created a view with a 'Location: Nodes' relationship, and selected 'Content: Address' as the field... nothing displays.

Looking at the query, the join still says: "LEFT JOIN location_instance location_instance ON node.vid = location_instance.vid", which is what landed me at the solution here: #517914: Location CCK Address Fields don't display

Is there a thread somewhere describing why genid is used for location_cck, as referenced here? Is this due to fields in D7 not being node-specific?

dragonwize’s picture

Status: Needs work » Needs review
FileSize
4.39 KB
4.94 KB

@q0rban: It works perfectly for me. Ensure that you are setting the "Relationship:" drop-down field in your location field. (see attached screenshot). Your query should look similar to the below.

SELECT node.nid AS nid,
   location_node_data_field_location_test.lid AS location_node_data_field_location_test_lid
 FROM node node 
 LEFT JOIN content_field_location_test node_data_field_location_test ON node.vid = node_data_field_location_test.vid
 INNER JOIN location location_node_data_field_location_test ON node_data_field_location_test.field_location_test_lid = location_node_data_field_location_test.lid

location_cck works very much like node reference field. CCK stores the lid and that is then related to the correct data by CCK when loading the field.

Patch is rerolled with latest HEAD and Karen's improvement from #13.

q0rban’s picture

Ah, so I shouldn't be using a Location:nodes relationship, but instead just a Location relationship? I'll try that out. Thanks!

SocialNicheGuru’s picture

Has anyone tried this patch which connects the location cck with the node. It allows me to use location without relationship for views

http://drupal.org/node/343943

The posiive is that I can have multiple node types called and their locations without relationships being used. admittedly i have not gotten proximity to work yet.

q0rban’s picture

@dragonwize, I still cannot get this working. Could it be that your patch for location_cck is not up to date with this patch for location.views.inc? I see three relationship options for location. "Location: Users", "Location: Node", & "Location: Node Revisions", whereas your screenshot shows only "Location".

q0rban’s picture

@dragonwize: Ok, so one clarifying question: Your view where it's working is a node based view, not a location based one, right?

q0rban’s picture

Honestly, I don't see how this can be done with genid. Node based tables need to have joins based on the nid. A snippet from your patch:

<?php
      $data["location_$table_alias"]['table']['join']['node'] = array(
        'table' => 'location',
        'field' => 'lid',
        'left_table' => $table_alias,
        'left_field' => $field['field_name'] .'_lid',
      );
?>

Which if I'm understanding correctly is essentially saying join the 'location' table to the 'node' table via $table_alias on lid = $field['field_name'] .'_lid'. Which sounds good, except that location.views.inc already joins to the node table via location_instance on nid/vid.

Also, this means that you can't actually just use the views field that CCK is providing. I have a feeling a custom relationship handler is going to be needed if nid/vid cannot be used for CCK fields in location_instance. The handler would need to parse out the genid from the location_instance table and join location to node that way.

dragonwize’s picture

@q0rban:

Yes, my patch is only for location_cck on node type views. That is what is taken care of by the cck views calls. Location type views are handled by location.views.inc and were taken care of by another patch of location.views.inc by brandon that I believe has already landed on head. The patch you are referring to is, to my knowledge, attempting to make improvements there.

All your assumptions there are assuming that both peices are working together but they actually are playing separate parts. My patch is only on the location_cck module and use CCk's views support api.

This patch works perfectly for me with location head for back compat with location node and node type views.

q0rban’s picture

@dragonwize,

Thanks for continuing the dialog, its very helpful. I think I'm going to end up switching to location_node instead of using location_cck. I just can't get this working.

Location type views are handled by location.views.inc and were taken care of by another patch of location.views.inc... All your assumptions there are assuming that both peices are working together but they actually are playing separate parts. My patch is only on the location_cck module and use CCk's views support api.

Yeah, I understand that location.views.inc is primarily for location views. My point is, look at this code from location.views.inc:

<?php
  $data['location']['table']['join'] = array(
    // Location links to node through location_instance via lid.
    'node' => array(
      'left_table' => 'location_instance',
      'left_field' => 'lid',
      'field' => 'lid',
    ),
?>

And then compare with your code below in location_cck:

<?php
      $data["location_$table_alias"]['table']['join']['node'] = array(
        'table' => 'location',
        'field' => 'lid',
        'left_table' => $table_alias,
        'left_field' => $field['field_name'] .'_lid',
      );
?>

They are both functionally doing the same thing (joining location to the node table). The former one is joining location to node via location_instance, whereas the latter is joining to node via the cck table that contains the location_cck field. In your case it appears that for some reason views is using the location_cck join over location.views.inc's join. In my case, the opposite appears to be true. Either that or my other guess is that it won't use the cck table to join because the cck table is already joined to node for the other cck fields.

Anyways, thanks for your help, I hope you're not feeling like I don't appreciate the time you've put into this!

dragonwize’s picture

Again you are assuming that both code is running at the same time, they don't, or at least shouldn't. When you are building a location type view you use join relations to nodes, that relation is set in location.views.inc and is ran when a node relation in a location type view is setup. When you build a node type view and you relation to a location cck field, that relation is set in location_cck via the cck api.

I do not know what modifications you have made from head but it sounds like you have made a few. Try the patch with a clean version of head with this patch.

I do not want to drive you away, if there are issues with this patch I want to find and fix them, but to do that we need to be able to synchronize what we are doing to find out where the issue is, as there are just too many variables in play right now. Any information about your setup and your view, even a copy of a view export may be helpful.

rucx’s picture

i've noticed a bug with your patch in 2 installs of mine, please try and see if you get the same result:
- just change default location in location - main settings to any other country of your choice (or in cck same thing)
- now go to add node ... did the default country change or is it still the same? in both my installs the default country configuration wont change anything since i applied this patch.

rucx’s picture

funny, my default country of choice is set right in edit node if i create a node with empty location, but at add/create node the default country wont change to my configuration choice.

rucx’s picture

lol, solved the problem by deleting cck location field and creating a new one. seems like you cant change default country once the cck field has been created.

dragonwize’s picture

@rucx:

What you are experiencing is a usability issue outside with location_cck outside of this patch. I've talked with Brandon about this a couple times but we have not come up with a good solution yet.

The issue is that there are 3 different places that are labeled for default country but each one actually has a specific place it sets the default. The default country under the admin/settings/location area is to set the default country when creating new content types for location_node. The CCK default values fieldset only sets the default country for the first field of a cck field. The default country in the location fieldset of the cck field actually sets the default country for the fields after the first of a multi value field.

We are working on that issue but currently it is part technical and usable issues that we are trying to match up to work well.

roball’s picture

Thank you for the patch #16. Works perfectly for me! Should be committed.

roball’s picture

The patch from #16 was against HEAD version 1.16 of "location_cck.module". Meanwhile, we are at v. 1.23, and it does not seem that the view improvements from this thread have been implemented. So, do we still have to apply the patch - and will it work - or must the patch be updated?

dragonwize’s picture

Patch re-rolled with latest HEAD.

roball’s picture

Thank you - patch #31 works perfectly for location fields in views with Location v6.x-3.x-dev (2009-Jul-31). I am using it at https://www.iseki-food.net/drupal/upcoming_ifa_events_all.

bomarmonk’s picture

After applying this patch I get the following error: "warning: include_once(./sites/all/modules/location/contrib/location_cck/location_cck.module) [function.include-once]: failed to open stream: Permission denied in C:\xampp\htdocs\mysite.com\includes\bootstrap.inc on line 611."

I'm not sure if this is because of my setup with XAMPP, but the module worked fine before the patch. I've checked that the file permissions are not read-only.

dragonwize’s picture

@bomarmonk: I appreciate you testing this patch. However, a patch itself does not affect a files permissions. So while I hope you find the issue, it is not this or any patch. You should check your file system again.

bomarmonk’s picture

Yes: I fixed this by following the instructions here: http://drupal.org/node/248176#comment-1001200. I'll let you know how the testing goes. Sorry for the unrelated issue: I just wasn't sure.

bomarmonk’s picture

All right, hopefully this is related to this patch. I didn't get this warning until after the patch: "warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\mysite.com\sites\all\modules\cck\includes\content.token.inc on line 59." This warning appears when editing my content type that includes my cck location field. It quickly disappeared after refreshing the page, but now, under "manage fields," my previously created CCk location field is reported as disabled: "This content type has inactive fields. Inactive fields are not included in lists of available fields until their modules are enabled...Location (field_location_cck_reusable2) is an inactive Location field that uses a Location Field widget." Is there no upgrade path for prior fields?

yrre7’s picture

subscribe

yrre7’s picture

The patch #31 doesn't seem to work with proximity search. If you input a number in the "miles" field, it will always display empty. If the "miles" field is empty with the correct zipcode, then it's able to produce the result. Any idea why it's like this?

fred0’s picture

Hmm... I've been digging around in the voluminous list of issues here and this is the closest to my problem that I've found. And since this seems to be the most active work on location_cck, it seems like the place to post. The patch in #31 works against the July 31 dev and certainly does seem to make improvements. The cck data is related properly and one can use the Location fields to display the various data. However, what doesn't seem to work is using the actual cck field itself. It appears in the Fields>Content list as an available cck data field, but when you add it to the display, it returns empty. The format pop-up is presented and provides the same options as the cck Display Fields setting (Address, Address with Map, Map only, Multiple field values on a single map) but none of those choice seem to matter.
I, in particular, would like to display the Address with map option in my view.
Anyone have any ideas?

And while I'm at it, the token support seems to have an issue with modules like auto_nodetitle and pathauto. The token isn't passed on the initial node save and the auto_nodetitle gets set to the token reference (ie - [field_location_name]) instead of the value of the field. Editing and re-saving the node then results in the proper behavior and the node is named.

fred0’s picture

The first half of my last comment was not very clear. I've now found an issue that is a bit more specific and done a better job explaining the bug here: http://drupal.org/node/427432#comment-2072838

cdale’s picture

@fred0 - I believe I provided a possible solution to the first part of your issue at http://drupal.org/node/427432#comment-2251824 (#14)

The second part, regarding the token support, is actually an auto_nodetitle bug, and can be fixed by applying the patch from http://drupal.org/node/194197#comment-2202358 (#69)

nickl’s picture

Status: Needs review » Needs work

I was just about to call this patch rtbc but then I rolled back to DRUPAL-6--3 to create another patch quick. I must admit that it took some serious configuring to get a node based view to work with the Location relationship and configuring every location_cck field for testing. You can imagine my shock when after removing the patch only to find that the view is still working. Filters, exposed filters, arguments, sort criteria, all the styles, grouping by location field the whole shebang, everything I've just tested works the same with the patch as without.

The idea for this issue, correct me if I'm wrong, is to create backward compatibility with location_node. Which it is failing to do completely, by using a relationship to expose the cck location data to views, rendering the view incompatible with node location data. What is the point then, we will be better of going the location_instance route which can indeed have these two misfits behave each other in one view. See #391160: CCK/Views: location_instance fix Did I mention easy as pie to configure?

For the second part of the patch, I fail to see what the benefit is to populating $node->location and $node-locations. If these do somehow make our lives easier and the code base simpler and more stable or even just one of the above then I will agree, lets go ahead and commit, until then I'm marking this issue "needs work".

Instead of making things more complicated, lets work together to fix all these outstanding bugs, get the issue queue cleaned out, write some documentation, get more maintainers involved and lets turn this very special project into something extraordinary.

Back to the topic: How can we get these two very similar modules to stop stepping on each others toes and work together? Do we even need to concern ourselves with compatibility? Why are we keeping both? What are the pros and cons? Lets talk about it again and again until we find a practical solution...

KISS

thill_’s picture

subscribe

roball’s picture

Status: Needs work » Fixed

@nickl: confirmed - the patch is no longer required for Location 6.x-3.x-dev (2009-Dec-17) used with Views 6.x-2.8 :-)

piepkrak’s picture

subscribing

Status: Fixed » Closed (fixed)
Issue tags: -location cck, -location cck views

Automatically closed -- issue fixed for 2 weeks with no activity.