You are here

public function MobileNumberFieldTestCase::createField in Mobile Number 7

Create mobile number field.

1 call to MobileNumberFieldTestCase::createField()
MobileNumberFieldTestCase::testNumberUniqueness in tests/mobile_number.field.test
Test number validation.

File

tests/mobile_number.field.test, line 213

Class

MobileNumberFieldTestCase
Class for testing mobile_number field.

Code

public function createField($content_type, $field_name, $unique, $cardinality) {
  $field = array(
    'field_name' => $field_name,
    'type' => 'mobile_number',
    'settings' => array(
      'unique' => $unique,
    ),
    'cardinality' => $cardinality,
  );
  field_create_field($field);

  // Create the instance on the bundle.
  $instance = array(
    'field_name' => $field_name,
    'entity_type' => 'node',
    'label' => 'Mobile Number',
    'bundle' => $content_type,
    // If you don't set the "required" property then the field wont be required by default.
    'required' => TRUE,
    'widget' => array(
      'type' => 'mobile_number_default',
      'settings' => array(
        'verify' => MOBILE_NUMBER_VERIFY_OPTIONAL,
      ),
    ),
  );
  field_create_instance($instance);
}