Your Ad Here

Posted By

theroamingcoder on 02/20/10


Tagged

drupal field cck


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

Onfire60
ctronci


Drupal 6 CCK Get Allowed Fields List


 / Published in: PHP
 

Only tested for Text and Number field types.

  1. function get_cck_text_field_allowed_values($field_name)
  2. {
  3. $result = db_query("SELECT * FROM {node_field} WHERE field_name = '%s'", $field_name);
  4. if($row = db_fetch_array($result)){
  5. $field = unserialize($row['global_settings']);
  6. if($field['allowed_values']){
  7.  
  8. $allowed_values = array();
  9. if ($field['allowed_values_php']) {
  10. $result = eval($field['allowed_values_php']);
  11. if (is_array($result)) {
  12. $allowed_values = $result;
  13. }
  14. }
  15. if (!$allowed_values) {
  16.  
  17. $list = explode("\n", $field['allowed_values']);
  18. $list = array_map('trim', $list);
  19. $list = array_filter($list, 'strlen');
  20. foreach ($list as $opt) {
  21. // Sanitize the user input with a permissive filter.
  22. $opt = content_filter_xss($opt);
  23. list($key, $value) = explode('|', $opt);
  24. $allowed_values[$key] = (isset($value) && $value !=='') ? $value : $key;
  25. }
  26. }
  27. return $allowed_values;
  28. }
  29. }
  30. return NULL;
  31. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: syakely on November 24, 2010

The table is now contentnodefield Besides that, it works good, thanks. SY

You need to login to post a comment.