Skip to content

Commit

Permalink
- Adding support to content.tree_root.location_id setting, now top me…
Browse files Browse the repository at this point in the history
…nu, side menu and breadcrumb work properly with the chosen root node
  • Loading branch information
thiagocamposviana committed Jan 2, 2014
1 parent 8f7b748 commit be6f81d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
5 changes: 4 additions & 1 deletion Classes/Components/ExtraInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ public function render()
{

$pathString = $this->parameters['pathString'];
if ($pathString == '/1/') {
$rootLocationId = $this->controller->getConfigResolver()->getParameter( 'content.tree_root.location_id' );


if ( strpos( $pathString , '/' . $rootLocationId . '/' ) === false ) {
return new Response();
}

Expand Down
6 changes: 4 additions & 2 deletions Classes/Components/SideMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ public function render()

$response->setPublic();
$response->setSharedMaxAge(86400);
$rootLocationId = $this->controller->getConfigResolver()->getParameter( 'content.tree_root.location_id' );


$subPath = explode( '/'. $rootLocationId . '/', $this->parameters['pathString']);
$subLocations = explode( '/', $subPath[1]);

$locations = explode('/', $this->parameters['pathString']);
$locationId = $locations[3];
$locationId = $subLocations[0];

// Menu will expire when top location cache expires.
$response->headers->set('X-Location-Id', $locationId);
Expand Down
5 changes: 3 additions & 2 deletions Classes/Components/TopMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ public function render()
{

$response = new Response();
$rootLocationId = $this->controller->getConfigResolver()->getParameter( 'content.tree_root.location_id' );

$response->setPublic();
$response->setSharedMaxAge(86400);

// Menu will expire when top location cache expires.
$response->headers->set('X-Location-Id', 2);
$response->headers->set('X-Location-Id', $rootLocationId);
// Menu might vary depending on user permissions, so make the cache vary on the user hash.
$response->setVary('X-User-Hash');

Expand All @@ -42,7 +43,7 @@ public function render()
new LocationPriority(Operator::LT, 100),
);

$list = SearchHelper::fetchChildren($this->controller, 2, $filters);
$list = SearchHelper::fetchChildren($this->controller, $rootLocationId, $filters);

$pathString = '';
if (isset($this->parameters['pathString'])) {
Expand Down
10 changes: 8 additions & 2 deletions Classes/SearchHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,20 @@ public static function getPath($pathString, TuteiController $controller)
{

$repository = $controller->getRepository();
$rootLocationId = $controller->getConfigResolver()->getParameter( 'content.tree_root.location_id' );

$locationService = $repository->getLocationService();
$locations = explode('/', $pathString);

$path = array();
$start = false;
foreach ($locations as $id) {

if (!in_array($id, array('', '1'))) {
if(!$start){
if($id == $rootLocationId){
$start = true;
}
}
if ($start and !in_array($id, array('', '1'))) {
$path[] = $locationService->loadLocation($id);
}
}
Expand Down

0 comments on commit be6f81d

Please sign in to comment.