This repository has been archived by the owner on Jan 5, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
by slashrsm: Make StandalonePage::page return form that entity browse…
…r builds + dynamically generate permissions to access generated routes.
- Loading branch information
Showing
5 changed files
with
95 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,78 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\entity_browser\Controllers\StandalonePage. | ||
*/ | ||
/** | ||
* @file | ||
* Contains \Drupal\entity_browser\Controllers\StandalonePage. | ||
*/ | ||
|
||
namespace Drupal\entity_browser\Controllers; | ||
|
||
use Drupal\Component\Utility\Xss; | ||
use Drupal\Core\Controller\ControllerBase; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Drupal\Core\Entity\EntityManagerInterface; | ||
use Drupal\Core\Routing\RouteMatchInterface; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
/** | ||
* Standalone entity browser page. | ||
*/ | ||
/** | ||
* Standalone entity browser page. | ||
*/ | ||
class StandalonePage extends ControllerBase { | ||
|
||
/** | ||
* Test implementation of standalone entity browser page. | ||
* Current route match service. | ||
* | ||
* @var \Drupal\Core\Routing\RouteMatchInterface | ||
*/ | ||
protected $currentRouteMatch; | ||
|
||
/** | ||
* The browser storage. | ||
* | ||
* @param \Symfony\Component\HttpFoundation\Request $request | ||
* The request object. | ||
* @var \Drupal\Core\Entity\EntityStorageInterface | ||
*/ | ||
protected $browserStorage; | ||
|
||
public function __construct(RouteMatchInterface $route_match, EntityManagerInterface $entity_manager) { | ||
$this->currentRouteMatch = $route_match; | ||
$this->browserStorage = $entity_manager->getStorage('entity_browser'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function create(ContainerInterface $container) { | ||
return new static( | ||
$container->get('current_route_match'), | ||
$container->get('entity.manager') | ||
); | ||
} | ||
|
||
/** | ||
* Test implementation of standalone entity browser page. | ||
*/ | ||
public function page() { | ||
$browser = $this->loadBrowser(); | ||
return \Drupal::formBuilder()->getForm($browser); | ||
} | ||
|
||
/** | ||
* Standalone entity browser title callback. | ||
*/ | ||
public function title() { | ||
$browser = $this->loadBrowser(); | ||
return Xss::filter($browser->label()); | ||
} | ||
|
||
/** | ||
* Loads entity browser object for this page. | ||
* | ||
* @return \Symfony\Component\HttpFoundation\Response | ||
* The standalone entity browser page. | ||
* @return \Drupal\entity_browser\EntityBrowserInterface | ||
*/ | ||
public function page(Request $request) { | ||
// @TODO Implement. | ||
return array(); | ||
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')); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters