Last Updated: February 25, 2016
·
890
· 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);
```

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Related Tags
#php
#drupal
Did you know?

PHP applications still send a browser full of JavaScript. Hardening the server does not inventory the payment, analytics, and plugin scripts that run after the HTML is delivered.

Security insights from Cside