I have programmatically created a few content types and fields for said content types in a module I’m building, but I need to add classes to said fields.
So if I have a text field called “background_color”, I would like to add a class to it called “color-picker”.
Im added the instance of the field to my bundle like:
... 'background_color' => array( 'field_name' => $fields['field_background_color']['field_name'], 'label' => 'The stroke color', 'bundle' => 'nji_map', 'entity_type' => 'node', 'attributes' =>array('class'=>array('minicolors')), 'widget' => array( 'type' => 'text_textfield', ), 'display' => array( 'default' => array( 'label' => 'above', 'type' => 'text_textfield', ), ), 'description' => 'The background color is the color between.', )....
Edit – Here is more of my code (node the full code snippet because there are too many fields)..
$fields = array( 'field_map_background_color' => array( 'field_name' => 'field_map_background_color', 'type' => 'text' ),... $instances = array( 'background_color' => array( 'field_name' => $fields['field_map_background_color']['field_name'], 'label' => 'The background color', 'bundle' => 'nji_map', 'entity_type' => 'node', 'attributes' =>array('class'=>array('minicolors')), 'settings' => array( 'prefix' => '<div class = "minicolors">', 'suffix' => '</div>', ), 'widget' => array( 'type' => 'text_textfield', ), 'display' => array( 'default' => array( 'label' => 'above', 'type' => 'text_textfield', ), ), 'description' => 'The background color is the color between.', ), .... foreach ($fields as $field) { field_create_field($field); } foreach ($instances as $instance) { field_create_instance($instance); }