Skip to content
Snippets Groups Projects
Commit a67d71f0 authored by Bernd Oliver Suenderhauf's avatar Bernd Oliver Suenderhauf
Browse files

Followup to: Issue #3057102 by Pancho: Replace ImageFieldTestBase by...

Followup to: Issue #3057102 by Pancho: Replace ImageFieldTestBase by entity-type agnostic test methods
parent 9927d1c2
No related branches found
No related tags found
No related merge requests found
...@@ -39,15 +39,22 @@ trait TestImageFieldTrait { ...@@ -39,15 +39,22 @@ trait TestImageFieldTrait {
} }
$type_manager = \Drupal::entityTypeManager(); $type_manager = \Drupal::entityTypeManager();
$label_key = $type_manager->getDefinition($entity_type)->getKey('label'); $definition = $type_manager->getDefinition($entity_type);
$entity = $type_manager->getStorage($entity_type)->create([
'type' => $bundle, $values = [];
$label_key => $this->randomMachineName(), if ($bundle_key = $definition->getKey('bundle')) {
$field_name => [ $values[$bundle_key] = $bundle;
'target_id' => $image->id(), }
'alt' => $alt, $label_key = $entity_type == 'user' ? 'name' : $definition->getKey('label');
], if ($label_key) {
]); $values[$label_key] = $this->randomMachineName();
}
$values[$field_name] = [
'target_id' => $image->id(),
'alt' => $alt,
];
$entity = $type_manager->getStorage($entity_type)->create($values);
$entity->save(); $entity->save();
return $entity->id(); return $entity->id();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment