public function Serializer::deserializeForm in FillPDF 8.4
Same name and namespace in other branches
- 5.0.x src/Serializer.php \Drupal\fillpdf\Serializer::deserializeForm()
Deserializes a serialized FillPDF form for import.
Parameters
string $code: The serialized FillPDF form.
Return value
array Associative array containing the deserialized FillPDF form object keyed with 'form' and an array of deserialized FillPDF form objects keyed with 'fields'.
Overrides SerializerInterface::deserializeForm
File
- src/
Serializer.php, line 60
Class
- Serializer
- Class Serializer.
Namespace
Drupal\fillpdfCode
public function deserializeForm($code) {
$mappings_raw = json_decode($code, TRUE);
$decoded_fillpdf_form = $this->serializer
->denormalize($mappings_raw['form'], 'Drupal\\fillpdf\\Entity\\FillPdfForm');
// Denormalization is a pain; we have to iterate over the fields to actually
// recompose the $fields array.
$field_json = $mappings_raw['fields'];
$decoded_fields = [];
foreach ($field_json as $normalized_field) {
$field = $this->serializer
->denormalize($normalized_field, 'Drupal\\fillpdf\\Entity\\FillPdfFormField');
// @todo: Exported fields are now already keyed by PDF key. For now, we're
// not using the array keys to remain compatible with previous exports,
// but should do so that at some later point.
$decoded_fields[$field->pdf_key->value] = $field;
}
$return = [
'form' => $decoded_fillpdf_form,
'fields' => $decoded_fields,
];
return $return;
}