View source
<?php
namespace Drupal\forward\Services;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Flood\FloodInterface;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Mail\MailManager;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountSwitcherInterface;
use Drupal\Core\Utility\LinkGenerator;
use Drupal\Core\Utility\Token;
use Drupal\forward\Form\ForwardForm;
use Egulias\EmailValidator\EmailValidator;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
class ForwardFormBuilder implements ForwardFormBuilderInterface {
protected $formBuilder;
protected $routeMatch;
protected $moduleHandler;
protected $entityTypeManager;
protected $requestStack;
protected $database;
protected $tokenService;
protected $floodInterface;
protected $accountSwitcher;
protected $renderer;
protected $eventDispatcher;
protected $mailer;
protected $linkGenerator;
protected $time;
protected $emailValidator;
public function __construct(FormBuilderInterface $form_builder, RouteMatchInterface $route_match, ModuleHandlerInterface $module_handler, EntityTypeManagerInterface $entity_type_manager, RequestStack $request_stack, Connection $database, Token $token_service, FloodInterface $flood_interface, AccountSwitcherInterface $account_switcher, RendererInterface $renderer, ContainerAwareEventDispatcher $event_dispatcher, MailManager $mailer, LinkGenerator $link_generator, TimeInterface $time, EmailValidator $email_validator) {
$this->time = $time;
$this->formBuilder = $form_builder;
$this->routeMatch = $route_match;
$this->moduleHandler = $module_handler;
$this->entityTypeManager = $entity_type_manager;
$this->requestStack = $request_stack;
$this->database = $database;
$this->tokenService = $token_service;
$this->floodInterface = $flood_interface;
$this->accountSwitcher = $account_switcher;
$this->renderer = $renderer;
$this->eventDispatcher = $event_dispatcher;
$this->mailer = $mailer;
$this->linkGenerator = $link_generator;
$this->emailValidator = $email_validator;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('form_builder'), $container
->get('current_route_match'), $container
->get('module_handler'), $container
->get('entity_type.manager'), $container
->get('request'), $container
->get('database'), $container
->get('token'), $container
->get('flood'), $container
->get('account.switcher'), $container
->get('renderer'), $container
->get('event_dispatcher'), $container
->get('plugin.manager.mail'), $container
->get('link_generator'), $container
->get('datetime.time'), $container
->get('email_validator'));
}
public function buildForm(EntityInterface $entity) {
$render_array = [];
if ($entity
->access('view')) {
$form = new ForwardForm($entity, $this->routeMatch, $this->moduleHandler, $this->entityTypeManager, $this->requestStack, $this->database, $this->tokenService, $this->floodInterface, $this->accountSwitcher, $this->renderer, $this->eventDispatcher, $this->mailer, $this->linkGenerator, $this->time, $this->emailValidator);
$render_array = $this->formBuilder
->getForm($form);
}
return $render_array;
}
public function buildInlineForm(EntityInterface $entity) {
$render_array = [];
if ($entity
->access('view')) {
$form = new ForwardForm($entity, $this->routeMatch, $this->moduleHandler, $this->entityTypeManager, $this->requestStack, $this->database, $this->tokenService, $this->floodInterface, $this->accountSwitcher, $this->renderer, $this->eventDispatcher, $this->mailer, $this->linkGenerator, $this->time, $this->emailValidator);
$details = TRUE;
$render_array = $this->formBuilder
->getForm($form, $details);
}
return $render_array;
}
}