protected function JuiceboxCaseTestBase::initNode in Juicebox HTML5 Responsive Image Galleries 8.2
Same name and namespace in other branches
- 8.3 tests/src/Functional/JuiceboxCaseTestBase.php \Drupal\Tests\juicebox\Functional\JuiceboxCaseTestBase::initNode()
Setup a new content type, with a image/file field.
4 calls to JuiceboxCaseTestBase::initNode()
- JuiceboxConfCase::setUp in tests/
src/ Functional/ JuiceboxConfCase.php - Define setup tasks.
- JuiceboxConfGlobalCase::setUp in tests/
src/ Functional/ JuiceboxConfGlobalCase.php - Define setup tasks.
- JuiceboxFieldFormatterCase::setUp in tests/
src/ Functional/ JuiceboxFieldFormatterCase.php - Define setup tasks.
- JuiceboxFileCase::setUp in tests/
src/ Functional/ JuiceboxFileCase.php - Define setup tasks.
File
- tests/
src/ Functional/ JuiceboxCaseTestBase.php, line 56
Class
- JuiceboxCaseTestBase
- Common helper class for Juicebox module tests.
Namespace
Drupal\Tests\juicebox\FunctionalCode
protected function initNode() {
// Create a new content type.
$this
->drupalCreateContentType([
'type' => $this->instBundle,
'name' => $this->instBundle,
]);
// Prep a field base.
$field_storage_settings = [
'display_field' => TRUE,
'display_default' => TRUE,
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
];
$field_storage = [
'entity_type' => 'node',
'field_name' => $this->instFieldName,
'type' => $this->instFieldType,
'settings' => $field_storage_settings,
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
];
entity_create('field_storage_config', $field_storage)
->save();
// Prep a field instance.
$field_settings = [];
if ($this->instFieldType == 'image') {
$field_settings['alt_field'] = TRUE;
$field_settings['alt_field_required'] = FALSE;
$field_settings['title_field'] = TRUE;
$field_settings['title_field_required'] = FALSE;
}
if ($this->instFieldType == 'file') {
$field_settings['description_field'] = TRUE;
$field_settings['file_extensions'] = 'txt jpg png mp3 rtf docx pdf';
}
$field = [
'field_name' => $this->instFieldName,
'label' => $this
->randomString(),
'entity_type' => 'node',
'bundle' => $this->instBundle,
'required' => FALSE,
'settings' => $field_settings,
];
entity_create('field_config', $field)
->save();
// Setup widget.
entity_get_form_display('node', $this->instBundle, 'default')
->setComponent($this->instFieldName, [
'type' => 'file_generic',
'settings' => [],
])
->save();
// Clear some caches for good measure.
$entity_manager = $this->container
->get('entity.manager');
$entity_manager
->getStorage('field_storage_config')
->resetCache();
$entity_manager
->getStorage('field_config')
->resetCache();
}