3

I have a CCK field ("City") that is a select list, and has manually entered cities in the allowed values list. I added these cities (as the administrator of the website) but I would like to hand control over to the client.
However, changing their permissions, and allowing them full access to the CCK content types would be potentially disastrous; I need a way to give authenticated users permission to add values to this select list.

Is this possible?

4 Answers 4

1

A simple solution would be to use taxonomy.

  • Taxonomy has it's own permission system.
  • Drupal adds a lot of nice features for taxonomies.
  • Categories such as cities is a perfect match for a taxonomy.
7
  • I have already implemented this with CCK - I just need the added functionality for allowing users to add values. Thanks for your suggestion though.
    – Garry
    Commented Jun 22, 2011 at 10:36
  • @Garry My guess is that it would be simpler and more stable to re-create using taxonomy than to create an interface to manage this. It's the old tale about being 80% done.
    – googletorp
    Commented Jun 22, 2011 at 12:20
  • Does taxonomy have enough granular permission to allow peoples only add terms to a certain vocabulary ?
    – tostinni
    Commented Jun 23, 2011 at 13:31
  • @tostinni If you have an actual question ask it but not in comments, use the ask question link top right corner.
    – googletorp
    Commented Jun 23, 2011 at 13:54
  • It is an actual question but I think the answer is crucial to this question and it can help your answer to be accepted or not ;). Personnaly without adequate permissions I would never allow normal users to create taxonomy terms.
    – tostinni
    Commented Jun 23, 2011 at 14:09
1

There is a module which does exactly this - allows regular users to edit CCK field values. The module is called 'values' (http://drupal.org/project/values).

0

With CCK I would do the following:

  • create a content type "cities" with a "cityname" field
  • in the "City" field you defined, I would put some PHP code to populate the "allowed values" textarea:

    $cities = Array();
    $result = db_query("SELECT nid FROM {node} WHERE status = 1 AND type = 'cities'");
    while ($row = db_fetch_array($result)) {
      $node_city = node_load($row['nid']);
      $cities[$node->nid] = $node_city->field_cityname[0]['value'];
    }
    return $cities;
    

A couple of remarks here:

  • the code is for D6 but can be adapted quite easily I think.
  • you'll have to put in place some validation in the creation of "cityname" to avoid duplicates (maybe also think about a country field).
  • it can be quite heavy to load a big number of $node_city, personnaly I'd rather use the tables of CCK to query the value directly, it's a little more complicated but ligther.

    $cities = Array();
    $field = content_fields('field_cityname');
    $db_info = content_database_info($field);
    
    $result = db_query("SELECT n.nid, " . $db_info['columns']['value'] . " AS city
              FROM {node} n 
              INNER JOIN {'. $db_info['table'] . '} c ON c.vid = n.vid
              WHERE status = 1 AND type = 'cities'");
    while ($row = db_fetch_array($result)) {
      $cities[$row['nid']] = $row['city'];
    }
    return $cities;
    
0

I've created a (sandbox) module that does what you want. I'd just like to reiterate that you might find taxonomy a better fit... but if you do want to continue the CCK route this module might help :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.