You are here

public function Generic::downloadSubmit in Add to Cal 8

Parameters

\Drupal\Core\Entity\EntityInterface $entity:

array $settings:

int $delta:

\Drupal\Core\Form\FormStateInterface $form_state:

Overrides AddToCalTypeInterface::downloadSubmit

File

src/Plugin/AddToCal/Type/Generic.php, line 141

Class

Generic
Provides generic calendar type (ics).

Namespace

Drupal\addtocal\Plugin\AddToCal\Type

Code

public function downloadSubmit(EntityInterface $entity, array $settings, $delta, FormStateInterface $form_state) {
  $eventDetails = $this
    ->extractEventDetails($entity, $settings, $delta);
  $filename = preg_replace('/[\\x00-\\x1F]/u', '_', strip_tags($eventDetails['title'])) . '.ics';
  $ics = $this
    ->generateStructure($eventDetails);
  $response = new BinaryFileResponse($ics);
  $response->headers
    ->set('Content-Type', 'application/calendar; charset=utf-8');
  $response
    ->setContentDisposition('attachment', $filename);
  $form_state
    ->setResponse($response);
}