public static function FillPdfTestBase::mapFillPdfFieldsToEntityFields in FillPDF 5.0.x
Same name and namespace in other branches
- 8.4 tests/src/Functional/FillPdfTestBase.php \Drupal\Tests\fillpdf\Functional\FillPdfTestBase::mapFillPdfFieldsToEntityFields()
Maps FillPdf fields to entity fields.
Parameters
string $entity_type: The entity type.
\Drupal\fillpdf\Entity\FillPdfFormField[] $fields: Array of FillPdfFormFields.
5 calls to FillPdfTestBase::mapFillPdfFieldsToEntityFields()
- FillPdfFormFormTest::testFormFormUpload in tests/
src/ Functional/ FillPdfFormFormTest.php - Tests the FillPdfForm entity's edit form.
- PdfPopulationTest::backendTest in tests/
src/ Functional/ PdfPopulationTest.php - Tests a backend.
- PdfPopulationTest::testImageStamping in tests/
src/ Functional/ PdfPopulationTest.php - Tests Core image stamping.
- PdfPopulationTest::testPdfPopulation in tests/
src/ Functional/ PdfPopulationTest.php - Tests Core entity population and image stamping.
- PdfPopulationTest::testProxyMerge in tests/
src/ Functional/ PdfPopulationTest.php - Tests that merging with the backend proxy works.
File
- tests/
src/ Functional/ FillPdfTestBase.php, line 58
Class
- FillPdfTestBase
- Base class that can be inherited by FillPDF tests.
Namespace
Drupal\Tests\fillpdf\FunctionalCode
public static function mapFillPdfFieldsToEntityFields($entity_type, array $fields) {
/** @var \Drupal\token\TokenEntityMapperInterface $token_entity_mapper */
$token_entity_mapper = \Drupal::service('token.entity_mapper');
$token_type = $token_entity_mapper
->getTokenTypeForEntityType($entity_type);
foreach ($fields as $pdf_key => $field) {
switch ($pdf_key) {
case 'ImageField':
case 'Button2':
case 'TestButton':
$field->value = "[{$token_type}:field_fillpdf_test_image]";
break;
case 'TextField1':
case 'Text1':
$label_key = \Drupal::entityTypeManager()
->getDefinition($entity_type)
->getKey('label');
$field->value = "[{$token_type}:{$label_key}]";
$field->replacements = 'Hello & how are you?|Hello & how are you doing?';
break;
case 'TextField2':
case 'Text2':
if ($token_type == 'node') {
$field->value = '[node:body]';
}
elseif ($token_type == 'term') {
$field->value = '[term:description]';
}
break;
}
$field
->save();
}
}