You are here

public function ChannelFormController::template in Courier 8

Same name and namespace in other branches
  1. 2.x src/Controller/ChannelFormController.php \Drupal\courier\Controller\ChannelFormController::template()

Gets the template form for a channel in a template collection.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The current request.

\Drupal\courier\TemplateCollectionInterface $courier_template_collection: A template collection entity.

\Drupal\Core\Entity\ContentEntityTypeInterface $courier_channel: Entity type definition for the channel.

Return value

array|\Drupal\Core\Ajax\AjaxResponse A render array for regular requests, or AjaxResponse if called by ajax.

1 string reference to 'ChannelFormController::template'
courier.routing.yml in ./courier.routing.yml
courier.routing.yml

File

src/Controller/ChannelFormController.php, line 37

Class

ChannelFormController
Controller for channels.

Namespace

Drupal\courier\Controller

Code

public function template(Request $request, TemplateCollectionInterface $courier_template_collection, ContentEntityTypeInterface $courier_channel) {
  $template_collection = $courier_template_collection;
  $render = \Drupal::formBuilder()
    ->getForm(TemplateEditForm::class, $template_collection, $courier_channel);
  if ($request->request
    ->get('js')) {
    $selector = '.template_collection[template_collection=' . $template_collection
      ->id() . '] .editor.' . $courier_channel
      ->id();
    $response = new AjaxResponse();
    $response
      ->addCommand(new HtmlCommand($selector, $render))
      ->addCommand(new PrependCommand($selector, [
      '#type' => 'status_messages',
    ]))
      ->addCommand(new CourierTemplate($template_collection
      ->id(), $courier_channel
      ->id(), 'open'));
    return $response;
  }
  return $render;
}