-
-
Notifications
You must be signed in to change notification settings - Fork 15
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 #923 from phpDocumentor/backport/1.x/pr-900
[1.x] Merge pull request #900 from phpDocumentor/task/menu-external
- Loading branch information
Showing
14 changed files
with
412 additions
and
65 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
...s/src/Compiler/NodeTransformers/MenuNodeTransformers/ExternalMenuEntryNodeTransformer.php
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,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of phpDocumentor. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @link https://phpdoc.org | ||
*/ | ||
|
||
namespace phpDocumentor\Guides\Compiler\NodeTransformers\MenuNodeTransformers; | ||
|
||
use phpDocumentor\Guides\Compiler\CompilerContext; | ||
use phpDocumentor\Guides\Nodes\DocumentTree\ExternalEntryNode; | ||
use phpDocumentor\Guides\Nodes\Menu\ExternalMenuEntryNode; | ||
use phpDocumentor\Guides\Nodes\Menu\MenuEntryNode; | ||
use phpDocumentor\Guides\Nodes\Menu\MenuNode; | ||
use phpDocumentor\Guides\Nodes\Menu\TocNode; | ||
use phpDocumentor\Guides\Nodes\Node; | ||
use phpDocumentor\Guides\Nodes\TitleNode; | ||
use Psr\Log\LoggerInterface; | ||
|
||
use function assert; | ||
|
||
final class ExternalMenuEntryNodeTransformer extends AbstractMenuEntryNodeTransformer | ||
{ | ||
use MenuEntryManagement; | ||
use SubSectionHierarchyHandler; | ||
|
||
public function __construct( | ||
LoggerInterface $logger, | ||
) { | ||
parent::__construct($logger); | ||
} | ||
|
||
public function supports(Node $node): bool | ||
{ | ||
return $node instanceof ExternalMenuEntryNode; | ||
} | ||
|
||
/** @return list<MenuEntryNode> */ | ||
protected function handleMenuEntry(MenuNode $currentMenu, MenuEntryNode $entryNode, CompilerContext $compilerContext): array | ||
{ | ||
assert($entryNode instanceof ExternalMenuEntryNode); | ||
|
||
$newEntryNode = new ExternalEntryNode( | ||
$entryNode->getUrl(), | ||
($entryNode->getValue() ?? TitleNode::emptyNode())->toString(), | ||
); | ||
|
||
if ($currentMenu instanceof TocNode) { | ||
$this->attachDocumentEntriesToParents([$newEntryNode], $compilerContext, ''); | ||
} | ||
|
||
return [$entryNode]; | ||
} | ||
|
||
public function getPriority(): int | ||
{ | ||
// After DocumentEntryTransformer | ||
return 4500; | ||
} | ||
} |
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
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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of phpDocumentor. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @link https://phpdoc.org | ||
*/ | ||
|
||
namespace phpDocumentor\Guides\Nodes\DocumentTree; | ||
|
||
use phpDocumentor\Guides\Nodes\AbstractNode; | ||
|
||
/** | ||
* @template TValue | ||
* @extends AbstractNode<TValue> | ||
*/ | ||
abstract class EntryNode extends AbstractNode | ||
{ | ||
private DocumentEntryNode|null $parent = null; | ||
|
||
public function getParent(): DocumentEntryNode|null | ||
{ | ||
return $this->parent; | ||
} | ||
|
||
public function setParent(DocumentEntryNode|null $parent): void | ||
{ | ||
$this->parent = $parent; | ||
} | ||
} |
Oops, something went wrong.