ChannelFormController.php in Courier 2.x
File
src/Controller/ChannelFormController.php
View source
<?php
namespace Drupal\courier\Controller;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\HtmlCommand;
use Drupal\Core\Ajax\PrependCommand;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\courier\CourierTokenElementTrait;
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\courier\Ajax\CourierTemplate;
use Drupal\courier\Form\TemplateEditForm;
use Drupal\courier\TemplateCollectionInterface;
use Symfony\Component\HttpFoundation\Request;
class ChannelFormController extends ControllerBase implements ContainerInjectionInterface {
use CourierTokenElementTrait;
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;
}
public function tokens(Request $request, TemplateCollectionInterface $courier_template_collection) {
$template_collection = $courier_template_collection;
$render['tokens'] = [
'#type' => 'container',
];
$render['tokens']['list'] = $this
->templateCollectionTokenElement($template_collection);
if ($request->request
->get('js')) {
$selector = '.template_collection[template_collection=' . $template_collection
->id() . '] .properties_container';
$response = new AjaxResponse();
$response
->addCommand(new HtmlCommand($selector, $render));
return $response;
}
return $render;
}
}