function EntityTestBase::createNodeType in Translation Management Tool 8
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\TestsCode
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();
}
}