Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 10a0b6a

Browse files
committed
Added node name and label
1 parent 0bfb162 commit 10a0b6a

File tree

6 files changed

+19
-0
lines changed

6 files changed

+19
-0
lines changed

Enhancer/SonataAdminEnhancer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public function enhance(array $data, Resource $resource)
7676
$links[$routeRole] = $url;
7777
}
7878

79+
$data['label'] = $admin->toString($object);
7980
$data['sonata_label'] = $admin->getLabel();
8081
$data['sonata_links'] = $links;
8182

Serializer/Jms/Handler/ResourceHandler.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use JMS\Serializer\JsonSerializationVisitor;
1616
use JMS\Serializer\Context;
1717
use PHPCR\NodeInterface;
18+
use PHPCR\Util\PathHelper;
1819
use Puli\Repository\Api\Resource\Resource;
1920
use Symfony\Cmf\Component\Resource\RepositoryRegistryInterface;
2021
use Symfony\Cmf\Bundle\ResourceRestBundle\Registry\PayloadAliasRegistry;
@@ -85,6 +86,7 @@ private function doSerializeResource(Resource $resource, $depth = 0)
8586
}
8687

8788
$data['path'] = $resource->getPath();
89+
$data['label'] = $data['node_name'] = PathHelper::getNodeName($data['path']);
8890
$data['repository_path'] = $resource->getRepositoryPath();
8991

9092
$enhancers = $this->enhancerRegistry->getEnhancers($repositoryAlias);

Tests/Features/resource_api_phpcr.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Feature: PHPCR resource repository
3434
"payload_alias": null,
3535
"payload_type": "nt:unstructured",
3636
"path": "\/foo",
37+
"node_name": "foo",
38+
"label": "foo",
3739
"repository_path": "\/foo",
3840
"children": []
3941
}

Tests/Features/resource_api_phpcr_odm.feature

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ Feature: PHPCR-ODM resource repository
3535
"payload_alias": "article",
3636
"payload_type": "Symfony\\Cmf\\Bundle\\ResourceRestBundle\\Tests\\Resources\\TestBundle\\Document\\Article",
3737
"path": "\/foo",
38+
"node_name": "foo",
39+
"label": "foo",
3840
"repository_path": "\/foo",
3941
"children": []
4042
}
@@ -61,6 +63,8 @@ Feature: PHPCR-ODM resource repository
6163
"payload_alias": "article",
6264
"payload_type": "Symfony\\Cmf\\Bundle\\ResourceRestBundle\\Tests\\Resources\\TestBundle\\Document\\Article",
6365
"path": "\/foo",
66+
"node_name": "foo",
67+
"label": "foo",
6468
"repository_path": "\/foo",
6569
"children": {
6670
"bar": {
@@ -69,6 +73,8 @@ Feature: PHPCR-ODM resource repository
6973
"payload_alias": "article",
7074
"payload_type": "Symfony\\Cmf\\Bundle\\ResourceRestBundle\\Tests\\Resources\\TestBundle\\Document\\Article",
7175
"path": "/foo/bar",
76+
"node_name": "bar",
77+
"label": "bar",
7278
"repository_path": "/foo/bar",
7379
"children": [ ]
7480
},
@@ -78,6 +84,8 @@ Feature: PHPCR-ODM resource repository
7884
"payload_alias": "article",
7985
"payload_type": "Symfony\\Cmf\\Bundle\\ResourceRestBundle\\Tests\\Resources\\TestBundle\\Document\\Article",
8086
"path": "/foo/boo",
87+
"node_name": "boo",
88+
"label": "boo",
8189
"repository_path": "/foo/boo",
8290
"children": [ ]
8391
}

Tests/Unit/Enhancer/SonataAdminEnhancerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,15 @@ public function testEnhancer()
7676

7777
$this->admin->getIdParameter()->willReturn('id');
7878
$this->admin->getLabel()->willReturn('Admin Label');
79+
$this->admin->toString($this->payload)->willReturn('Admin');
7980

8081
$result = $this->enhancer->enhance(
8182
$data,
8283
$this->resource->reveal()
8384
);
8485

8586
$this->assertEquals(array(
87+
'label' => 'Admin',
8688
'sonata_label' => 'Admin Label',
8789
'sonata_links' => array(
8890
'edit' => 'http://edit',

Tests/Unit/Serializer/Jms/Handler/ResourceHandlerTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ public function testHandler()
7676
'payload_alias' => 'alias',
7777
'payload_type' => 'payload_type',
7878
'path' => '/path/to',
79+
'node_name' => 'to',
80+
'label' => 'to',
7981
'repository_path' => '/repository/path',
8082
'children' => array(
8183
array(
@@ -84,6 +86,8 @@ public function testHandler()
8486
'payload_alias' => 'alias',
8587
'payload_type' => 'payload_type',
8688
'path' => '/path/to/child',
89+
'label' => 'child',
90+
'node_name' => 'child',
8791
'repository_path' => '/child/repository/path',
8892
'children' => array(),
8993
),

0 commit comments

Comments
 (0)