Skip to content

Commit 6734e5e

Browse files
committed
Merge pull request #66 from phpcr/list_show_pr_no_type
Show items primary value when listing node contents
2 parents 3d0bc36 + 8a5a12b commit 6734e5e

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ alpha-4
99
- [node] copy,move and clone - Target paths automatically append basename if target is a node.
1010
- [query] Always show path next to resultset
1111
- [node|shell] Most commands which accept a node path can also accept a UUID
12+
- [node] `node:list`: Show node primary item value
1213

1314
### Bugs Fixes
1415

src/PHPCR/Shell/Console/Command/Phpcr/NodeListCommand.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use Symfony\Component\Console\Input\InputArgument;
99
use Symfony\Component\Console\Input\InputOption;
1010
use PHPCR\PropertyType;
11+
use PHPCR\ItemNotFoundException;
12+
use PHPCR\PropertyInterface;
13+
use PHPCR\NodeInterface;
1114

1215
class NodeListCommand extends Command
1316
{
@@ -99,12 +102,24 @@ private function renderChildren($currentNode, $table, $spacers)
99102
unset($childNodeNames[$child->getName()]);
100103
}
101104

105+
$primaryItemValue = '';
106+
try {
107+
$primaryItem = $child->getPrimaryItem();
108+
109+
if ($primaryItem instanceof PropertyInterface) {
110+
$primaryItemValue = $this->textHelper->truncate($this->formatter->formatValue($primaryItem), 55);
111+
} elseif ($primaryItem instanceof NodeInterface) {
112+
$primaryItemValue = sprintf('+%s', $primaryItem->getName());
113+
}
114+
} catch (ItemNotFoundException $e) {
115+
}
116+
102117
$isLast = count($children) === $i;
103118

104119
$table->addRow(array(
105120
'<node>' . implode('', $spacers) . $this->formatter->formatNodeName($child) . '</node>',
106121
$child->getPrimaryNodeType()->getName(),
107-
'',
122+
$primaryItemValue,
108123
));
109124

110125
if (count($spacers) < $this->maxLevel) {
@@ -136,6 +151,12 @@ private function renderProperties($currentNode, $table, $spacers)
136151
{
137152
$properties = $currentNode->getProperties($this->filters ? : null);
138153

154+
try {
155+
$primaryItem = $currentNode->getPrimaryItem();
156+
} catch (ItemNotFoundException $e) {
157+
$primaryItem = null;
158+
}
159+
139160
$nodeType = $currentNode->getPrimaryNodeType();
140161
$propertyDefinitions = $nodeType->getDeclaredPropertyDefinitions();
141162

0 commit comments

Comments
 (0)