You are here

class EntityBrowserFormController in Entity Browser 8.2

Same name and namespace in other branches
  1. 8 src/Controllers/EntityBrowserFormController.php \Drupal\entity_browser\Controllers\EntityBrowserFormController

Standalone entity browser page.

Hierarchy

Expanded class hierarchy of EntityBrowserFormController

File

src/Controllers/EntityBrowserFormController.php, line 19

Namespace

Drupal\entity_browser\Controllers
View source
class EntityBrowserFormController extends HtmlFormController implements ContainerInjectionInterface {

  /**
   * Current route match service.
   *
   * @var \Drupal\Core\Routing\RouteMatchInterface
   */
  protected $currentRouteMatch;

  /**
   * The browser storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $browserStorage;

  /**
   * Current request.
   *
   * @var \Symfony\Component\HttpFoundation\Request
   */
  protected $request;

  /**
   * Constructs Entity browser form controller.
   *
   * @param \Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface $argument_resolver
   *   The argument resolver.
   * @param \Drupal\Core\Form\FormBuilderInterface $form_builder
   *   The form builder.
   * @param \Drupal\Core\DependencyInjection\ClassResolverInterface $class_resolver
   *   The class resolver.
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *   Current route match service.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   Entity type manager service.
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   Current 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;
  }

  /**
   * {@inheritdoc}
   */
  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());
  }

  /**
   * {@inheritdoc}
   */
  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();
  }

  /**
   * Standalone entity browser title callback.
   */
  public function title() {
    $browser = $this
      ->loadBrowser();
    return Xss::filter($browser
      ->label());
  }

  /**
   * Loads entity browser object for this page.
   *
   * @return \Drupal\entity_browser\EntityBrowserInterface
   *   Loads the entity browser object
   */
  protected function loadBrowser() {

    /* @var $route \Symfony\Component\Routing\Route */
    $route = $this->currentRouteMatch
      ->getRouteObject();

    /* @var $browser \Drupal\entity_browser\EntityBrowserInterface */
    return $this->browserStorage
      ->load($route
      ->getDefault('entity_browser_id'));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
EntityBrowserFormController::$browserStorage protected property The browser storage.
EntityBrowserFormController::$currentRouteMatch protected property Current route match service.
EntityBrowserFormController::$request protected property Current request.
EntityBrowserFormController::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
EntityBrowserFormController::getFormObject protected function Returns the object used to build the form. Overrides HtmlFormController::getFormObject
EntityBrowserFormController::loadBrowser protected function Loads entity browser object for this page.
EntityBrowserFormController::title public function Standalone entity browser title callback.
EntityBrowserFormController::__construct public function Constructs Entity browser form controller. Overrides HtmlFormController::__construct
FormController::$argumentResolver protected property The argument resolver.
FormController::$controllerResolver Deprecated protected property The controller resolver.
FormController::$formBuilder protected property The form builder.
FormController::getContentResult public function Invokes the form and returns the result.
HtmlFormController::$classResolver protected property The class resolver.
HtmlFormController::getFormArgument protected function Extracts the form argument string from a request. Overrides FormController::getFormArgument