Skip to content

IBX-10091 Preview Siteaccess: Show hidden locations #572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/contracts/Ibexa.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ final class Ibexa
/**
* Ibexa DXP Version.
*/
public const VERSION = '4.6.19';
public const VERSION = '4.6.20';
}
31 changes: 29 additions & 2 deletions src/lib/Persistence/Legacy/Content/Location/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,28 @@
*/
class Mapper
{
public static $IS_PREVIEW_MODE = null;

/**
* Check if siteaccess is in preview mode.
* Update config/app/services.yaml
* Add the settting in parameters:
* ibexa.{siteaccess_name}.show_hidden_locations: true
* @return bool
*/
public static function isPreviewMode() {
// caching preview mode
if(self::$IS_PREVIEW_MODE === null) {
$container = (method_exists($GLOBALS[ 'app' ], 'getKernel') ? $GLOBALS[ 'app' ]->getKernel()->getContainer() : $GLOBALS[ 'app' ]->getContainer());
$siteaccessName = $container->get('ibexa.siteaccess')->getCurrent()->name;
if($container->hasParameter( "ibexa.$siteaccessName.show_hidden_locations" )) {
self::$IS_PREVIEW_MODE = $container->getParameter( "ibexa.$siteaccessName.show_hidden_locations" );
} else {
self::$IS_PREVIEW_MODE = false;
}
}
return self::$IS_PREVIEW_MODE;
}
/**
* Creates a Location from a $data row.
*
Expand All @@ -33,8 +55,13 @@ public function createLocationFromRow(array $data, $prefix = '', ?Location $loca

$location->id = (int)$data[$prefix . 'node_id'];
$location->priority = (int)$data[$prefix . 'priority'];
$location->hidden = (bool)$data[$prefix . 'is_hidden'];
$location->invisible = (bool)$data[$prefix . 'is_invisible'];
if(self::isPreviewMode()) {
$location->hidden = false;
$location->invisible = false;
} else {
$location->hidden = (bool)$data[$prefix . 'is_hidden'];
$location->invisible = (bool)$data[$prefix . 'is_invisible'];
}
$location->remoteId = $data[$prefix . 'remote_id'];
$location->contentId = (int)$data[$prefix . 'contentobject_id'];
$location->parentId = (int)$data[$prefix . 'parent_node_id'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Ibexa\Core\Persistence\Legacy\Content\Location\Gateway as LocationGateway;
use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter;
use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler;
use Ibexa\Core\Persistence\Legacy\Content\Location\Mapper;

/**
* Visibility criterion handler.
Expand All @@ -36,29 +37,33 @@ public function handle(
array $languageSettings
) {
$subSelect = $this->connection->createQueryBuilder();

if ($criterion->value[0] === Criterion\Visibility::VISIBLE) {
$expression = $queryBuilder->expr()->andX(
$queryBuilder->expr()->eq(
'subquery_location.is_hidden',
0
),
$queryBuilder->expr()->eq(
'subquery_location.is_invisible',
0
)
);
if(!Mapper::isPreviewMode()) {
if ($criterion->value[0] === Criterion\Visibility::VISIBLE) {
$expression = $queryBuilder->expr()->andX(
$queryBuilder->expr()->eq(
'subquery_location.is_hidden',
0
),
$queryBuilder->expr()->eq(
'subquery_location.is_invisible',
0
)
);
} else {
$expression = $queryBuilder->expr()->orX(
$queryBuilder->expr()->eq(
'subquery_location.is_hidden',
1
),
$queryBuilder->expr()->eq(
'subquery_location.is_invisible',
1
)
);
}
} else {
$expression = $queryBuilder->expr()->orX(
$queryBuilder->expr()->eq(
'subquery_location.is_hidden',
1
),
$queryBuilder->expr()->eq(
'subquery_location.is_invisible',
1
)
);
// Dummy query to not break the WHERE statement
$expression = $queryBuilder->expr()->eq( '1', '1' );
}

$subSelect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter;
use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler;
use RuntimeException;
use Ibexa\Core\Persistence\Legacy\Content\Location\Mapper;

/**
* Location visibility criterion handler.
Expand All @@ -37,24 +38,28 @@ public function handle(
array $languageSettings
) {
$column = 't.is_invisible';
if(!Mapper::isPreviewMode()) {
switch ($criterion->value[0]) {
case Criterion\Visibility::VISIBLE:
return $queryBuilder->expr()->eq(
$column,
$queryBuilder->createNamedParameter(0, ParameterType::INTEGER)
);

switch ($criterion->value[0]) {
case Criterion\Visibility::VISIBLE:
return $queryBuilder->expr()->eq(
$column,
$queryBuilder->createNamedParameter(0, ParameterType::INTEGER)
);
case Criterion\Visibility::HIDDEN:
return $queryBuilder->expr()->eq(
$column,
$queryBuilder->createNamedParameter(1, ParameterType::INTEGER)
);

case Criterion\Visibility::HIDDEN:
return $queryBuilder->expr()->eq(
$column,
$queryBuilder->createNamedParameter(1, ParameterType::INTEGER)
);

default:
throw new RuntimeException(
"Unknown value '{$criterion->value[0]}' for Visibility Criterion handler."
);
default:
throw new RuntimeException(
"Unknown value '{$criterion->value[0]}' for Visibility Criterion handler."
);
}
} else {
// Dummy query to not break the WHERE statement
return $queryBuilder->expr()->eq( '1', '1' );
}
}
}
Expand Down
Loading