1 field_permission_example.test protected GenericFieldTest::formAddAllFields($node_type = NULL)

Add all fields using Form API.

Parameters

mixed $node_type: A content type object. If none is specified, the test fails.

File

modules/examples/field_permission_example/tests/field_permission_example.test, line 226
Tests for Field Permission Example.

Class

GenericFieldTest
A generic field testing class.

Code

protected function formAddAllFields($node_type = NULL) {
  if (!$node_type) {
    $this->fail('No content type specified.');
  }
  // Get all our field types.
  $field_types = $this->getFieldTypes();
  // Keep a list of no_ui fields so we can tell the user.
  $unsafe_field_types = array();
  $field_names = array();

  $manage_path = 'admin/structure/types/manage/' . $node_type->name . '/fields';
  foreach ($field_types as $field_type) {
    // Get the field info.
    $field_info = field_info_field_types($field_type);
    // Exclude no_ui field types.
    if (isset($field_info['no_ui']) && $field_info['no_ui']) {
      $unsafe_field_types[] = $field_type;
    }
    else {
      // Generate a name for our field.
      // 26 is max length for field name.
      $field_name = backdrop_strtolower($this->randomName(26));
      $field_names[$field_type] = $field_name;
      // Create the field through Form API.
      $this->formCreateField($manage_path, $field_type, $field_name, 
      $field_info['default_widget'], 1);
    }
  }

  // Tell the user which fields we couldn't test.
  if (!empty($unsafe_field_types)) {
    debug(
    'Unable to attach these no_ui fields: ' .
      implode(', ', $unsafe_field_types)
      );
  }

  menu_rebuild();
  return $field_names;
}