Helper function to create a content field (CCK field)


/ Published in: PHP
Save to your folder(s)

With thanks to emspace for the original code :)


Copy this code and paste it in your HTML
  1. /**
  2.  * Helper function to create a content field (CCK field).
  3.  *
  4.  * @param $type_name
  5.  * The content type for which the content field should be created.
  6.  * @param $properties
  7.  * An array with field type properties, that override the default ones.
  8.  */
  9. function _create_content_field($type_name, $properties) {
  10. $default = array(
  11. 'label' => 'A field label', // Override in $properties
  12. 'widget_type' => '', // Override in $properties
  13. 'op' => 'Create field',
  14. 'submit' => 'Create field',
  15. 'locked' => FALSE,
  16. 'field_name' => '', // Override in $properties, lowercase underscore
  17. );
  18.  
  19. $new_field = array_merge($default, $properties);
  20. $new_field['type_name'] = $type_name;
  21.  
  22. _content_admin_field_add_new_submit('_content_admin_field_add_new', $new_field);
  23. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.