function Export::buildForm in Default Content 8
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides EntityForm::buildForm
File
- src/Export.php, line 19 
- Contains \Drupal\defaultcontent\Export.
Class
- Export
- Converts a node to a config entity and shows it on screen We use the EntityForm here because it is an easy way to get the node from the routing system
Namespace
Drupal\defaultcontentCode
function buildForm(array $form, \Drupal\Core\Form\FormStateInterface $form_state) {
  $entity = $form_state
    ->getFormObject()
    ->getEntity();
  $entities = \Drupal::service('defaultcontent.manager')
    ->exportContentWithReferences($entity
    ->getEntityTypeId(), $entity
    ->id());
  $content = $entities[$entity
    ->getEntityTypeId()][$entity
    ->uuid()];
  $headers = [
    'Content-Type' => 'application/octet-stream',
    'Content-Length' => strlen($content),
    'Content-Disposition' => 'attachment; filename=' . $entity
      ->uuid() . '.json',
  ];
  $response = new Response($content, 200, $headers);
  $response
    ->send();
  exit;
}