0

In a Drupal 7 site, I want to have automatic node titles taken from user contributed content.

I have Location 7.x-3.x-dev (enabled Location and Location CCK) and Automatic Nodetitles 7.x-1.x-dev.

The problem is location tokens in the automatic title generation tab of the content type are returning empty input. I have tried [node:location:city:?], [node:location:city:0] and [node:location:city], but all three return nothing.

Tokens from the other fields are showing their input properlu.

Any help will be greatly appreciated.

0

I have taken some good looks at your issue. At the moment I find that the code for Location CCK is problematic, I managed to make it work with the following modification:

diff --git a/contrib/location_cck/location_cck.module b/contrib/location_cck/location_cck.module
index b302960..443b6a0 100644
--- a/contrib/location_cck/location_cck.module
+++ b/contrib/location_cck/location_cck.module
@@ -657,9 +657,9 @@ function location_cck_tokens($type, $tokens, array $data = array(), array $optio
   $replacements = array();

   // Make sure we have a node.
-  if (isset($data['entity_type']) && $data['entity_type'] == 'node') {
+  if ($type == 'node') {

-    $node = $data['entity'];
+    $node = $data['node'];

     // Get the available fields from the location module.
     $available = location_field_names(TRUE);

The token that worked after this patching was specific to the CCK field I added to my content type:

[node:field_my_location_field:city]

Alternatively, for your goal "...to have automatic node titles taken from user contributed content...", you can use the Node Locations submodule, this works as expected out of the box. The following tokens

[node:location:city]
and
[node:location:city:0]

both worked fine in combination with Automatic Nodetitles.

Hope this helps!

  • Hi, @Stefanos, many thanks for your help! I started from the alternative solution - I enabled Node Locations, but this unfortunately does not solve the issue ([node:location:city] or [node:location:city:0] still not working). In my content type I have a Location field, where the user types the address. After enabling the Node Locations submodule I have a second Location field, which in existing nodes takes the data from the original field, but in new nodes the address from the original field is not saved and after save both the old and the new Location fields are empty. – user48533 Feb 24 '16 at 15:25
  • I will also try the first solution, but for that one I presume the address fields (City, postal code, Street, etc) must be separate text fields, and not the address from the Location module. That is not optimal, as I also use the Location field to generate on the page a Gmap of the address. – user48533 Feb 24 '16 at 15:28
  • Hi @peer, you're welcome. Some points following from your comments above: – Stefanos Petrakis Feb 24 '16 at 17:54
  • a) You cannot have Node Locations and Location CCK activated at the same time, read here please => (drupal.org/node/1051582). This alternative really worked best for me, no headaches there. – Stefanos Petrakis Feb 24 '16 at 18:01
  • b) Regarding the first solution: No, the address fields are all part of the Location CCK field that you add to your content type. In my example, field_my_location_field, is a Location type of field, which comes with all the address fields you mention. So, that should work too for you. – Stefanos Petrakis Feb 24 '16 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy