Error message

  • Warning: count(): Parameter must be an array or an object that implements Countable in _api_make_match_member_link() (line 1230 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).
  • Warning: count(): Parameter must be an array or an object that implements Countable in _api_make_match_member_link() (line 1230 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).

function EntityTestBase::createNodeType

Creates node type with several text fields with different cardinality.

Internally it calls TMGMTEntityTestCaseUtility::attachFields() to create and attach fields to newly created bundle. You can than use $this->field_names['node']['YOUR_BUNDLE_NAME'] to access them.

Parameters

string $machine_name: Machine name of the node type.

string $human_name: Human readable name of the node type.

bool $translation: TRUE if translation for this enitty type should be enabled. pparam bool $attach_fields (optional) If fields with the same translatability should automatically be attached to the node type.

File

src/Tests/EntityTestBase.php, line 46

Class

EntityTestBase
Utility test case class with helper methods to create entities and their fields with populated translatable content. Extend this class if you create tests in which you need Drupal entities and/or fields.

Namespace

Drupal\tmgmt\Tests

Code

function createNodeType($machine_name, $human_name, $translation = FALSE, $attach_fields = TRUE) {
  $type = $this
    ->drupalCreateContentType(array(
    'type' => $machine_name,
    'name' => $human_name,
  ));

  // Push in also the body field.
  $this->field_names['node'][$machine_name][] = 'body';
  if (\Drupal::hasService('content_translation.manager') && $translation) {
    $content_translation_manager = \Drupal::service('content_translation.manager');
    $content_translation_manager
      ->setEnabled('node', $machine_name, TRUE);
  }
  $this
    ->applySchemaUpdates();
  if ($attach_fields) {
    $this
      ->attachFields('node', $machine_name, $translation);
  }
  else {

    // Change body field to be translatable.
    $body = FieldConfig::loadByName('node', $machine_name, 'body');
    $body
      ->setTranslatable(TRUE);
    $body
      ->save();
  }
}