Last Updated: February 25, 2016
·
720
· rafaelcaceres

Create a float field programmatically in Drupal

    $field = array(
        'field_name' => 'field_amount',
        'type' => 'number_float',
        'cardinality' => 1,
      );
      field_create_field($field);

      $instance = array(
        'field_name' => 'field_amount',
        'entity_type' => 'transaction',
        'bundle' => 'payment',
        'label' => 'amount',
        'cardinality' => 1,
        'settings' => array(
          'text_processing' => TRUE,
          'prefix' => 'US$',
        ),
        'widget' => array(
          'type' => 'number',
          'settings'   => array('size' => 60),
        ),
        'display' => array(
          'full' => array(
            'type' => 'text_default',
          ),
        ),
      );
      field_create_instance($instance);
```