-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from daniellienert/feature/make-suggestionCont…
…ext-configurable FEATURE: Make suggestion context configurable
- Loading branch information
Showing
6 changed files
with
147 additions
and
19 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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Flowpack\SearchPlugin\Suggestion; | ||
|
||
/* | ||
* This file is part of the Flowpack.SearchPlugin package. | ||
* | ||
* (c) Contributors of the Flowpack Team - flowpack.org | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Neos\ContentRepository\Domain\Model\NodeInterface; | ||
|
||
class SuggestionContext implements SuggestionContextInterface | ||
{ | ||
|
||
/** | ||
* Rhe length of '/sites/' | ||
* @var int | ||
*/ | ||
protected const SITES_OFFSET = 7; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $contextValues = []; | ||
|
||
public function buildForIndex(NodeInterface $node): self | ||
{ | ||
$this->contextValues = [ | ||
'siteName' => $this->getSiteName($node), | ||
'workspace' => $node->getWorkspace()->getName(), | ||
'isHidden' => $node->isHidden() ? 'hidden' : 'visible', | ||
]; | ||
|
||
return $this; | ||
} | ||
|
||
public function buildForSearch(NodeInterface $node): self | ||
{ | ||
$this->contextValues = [ | ||
'siteName' => $this->getSiteName($node), | ||
'workspace' => $node->getWorkspace()->getName(), | ||
'isHidden' => 'visible', | ||
]; | ||
|
||
return $this; | ||
} | ||
|
||
public function getContextIdentifier(): string | ||
{ | ||
return implode('_', $this->contextValues); | ||
} | ||
|
||
public function __toString() | ||
{ | ||
return $this->getContextIdentifier(); | ||
} | ||
|
||
/** | ||
* @param NodeInterface $node | ||
* @return string | ||
*/ | ||
protected function getSiteName(NodeInterface $node): string | ||
{ | ||
return substr($node->getPath(), self::SITES_OFFSET, strpos($node->getPath() . '/', '/', self::SITES_OFFSET) - self::SITES_OFFSET); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Flowpack.SearchPlugin package. | ||
* | ||
* (c) Contributors of the Flowpack Team - flowpack.org | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
namespace Flowpack\SearchPlugin\Suggestion; | ||
|
||
use Neos\ContentRepository\Domain\Model\NodeInterface; | ||
|
||
interface SuggestionContextInterface | ||
{ | ||
|
||
/** | ||
* Build the context from a given node | ||
* @param NodeInterface $node | ||
*/ | ||
public function buildForIndex(NodeInterface $node): self; | ||
|
||
/** | ||
* Build the context from a given node | ||
* @param NodeInterface $node | ||
*/ | ||
public function buildForSearch(NodeInterface $node): self; | ||
|
||
/** | ||
* Returns the calculated context identifier | ||
* @return string | ||
*/ | ||
public function getContextIdentifier(): string; | ||
} |
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