EntityBrowserFormController.php in Entity Browser 8.2
File
src/Controllers/EntityBrowserFormController.php
View source
<?php
namespace Drupal\entity_browser\Controllers;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Controller\HtmlFormController;
use Drupal\Core\DependencyInjection\ClassResolverInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
class EntityBrowserFormController extends HtmlFormController implements ContainerInjectionInterface {
protected $currentRouteMatch;
protected $browserStorage;
protected $request;
public function __construct(ArgumentResolverInterface $argument_resolver, FormBuilderInterface $form_builder, ClassResolverInterface $class_resolver, RouteMatchInterface $route_match, EntityTypeManagerInterface $entity_type_manager, Request $request) {
parent::__construct($argument_resolver, $form_builder, $class_resolver);
$this->currentRouteMatch = $route_match;
$this->browserStorage = $entity_type_manager
->getStorage('entity_browser');
$this->request = $request;
$this->formBuilder = $form_builder;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('http_kernel.controller.argument_resolver'), $container
->get('form_builder'), $container
->get('class_resolver'), $container
->get('current_route_match'), $container
->get('entity_type.manager'), $container
->get('request_stack')
->getCurrentRequest());
}
protected function getFormObject(RouteMatchInterface $route_match, $form_arg) {
$browser = $this
->loadBrowser();
if ($original_path = $this->request
->get('original_path')) {
$browser
->addAdditionalWidgetParameters([
'path_parts' => explode('/', $original_path),
]);
}
return $browser
->getFormObject();
}
public function title() {
$browser = $this
->loadBrowser();
return Xss::filter($browser
->label());
}
protected function loadBrowser() {
$route = $this->currentRouteMatch
->getRouteObject();
return $this->browserStorage
->load($route
->getDefault('entity_browser_id'));
}
}