Skip to content

Commit

Permalink
Add title to list (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz authored and wachterjohannes committed Nov 18, 2019
1 parent a43e8fa commit 756944d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 7 deletions.
7 changes: 3 additions & 4 deletions Content/Infrastructure/Doctrine/MetadataLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event): void
'references' => [
'entity' => MediaInterface::class,
'field' => 'id',
'onDelete' => 'CASCADE',
'onUpdate' => 'CASCADE',
'onDelete' => 'SET NULL',
],
],
]);
Expand All @@ -105,8 +104,7 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event): void
'references' => [
'entity' => MediaInterface::class,
'field' => 'id',
'onDelete' => 'CASCADE',
'onUpdate' => 'CASCADE',
'onDelete' => 'SET NULL',
],
],
]);
Expand Down Expand Up @@ -136,6 +134,7 @@ private function addManyToOne(
[
'name' => $namingStrategy->joinKeyColumnName($name),
'referencedColumnName' => $referencedColumnName,
'nullable' => false,
'onDelete' => 'CASCADE',
'onUpdate' => 'CASCADE',
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Sulu\Bundle\ContentBundle\Content\Application\Message\SaveContentMessage;
use Sulu\Bundle\ContentBundle\Tests\Application\ExampleTestBundle\Entity\Example;
use Sulu\Component\Rest\AbstractRestController;
use Sulu\Component\Rest\ListBuilder\Doctrine\DoctrineListBuilder;
use Sulu\Component\Rest\ListBuilder\Doctrine\DoctrineListBuilderFactoryInterface;
use Sulu\Component\Rest\ListBuilder\Doctrine\FieldDescriptor\DoctrineFieldDescriptorInterface;
use Sulu\Component\Rest\ListBuilder\Metadata\FieldDescriptorFactoryInterface;
Expand Down Expand Up @@ -74,11 +75,13 @@ public function __construct(
parent::__construct($viewHandler, $tokenStorage);
}

public function cgetAction(): Response
public function cgetAction(Request $request): Response
{
/** @var DoctrineFieldDescriptorInterface[] $fieldDescriptors */
$fieldDescriptors = $this->fieldDescriptorFactory->getFieldDescriptors(Example::RESOURCE_KEY);
/** @var DoctrineListBuilder $listBuilder */
$listBuilder = $this->listBuilderFactory->create(Example::class);
$listBuilder->setParameter('locale', $request->query->get('locale'));
$this->restHelper->initializeListBuilder($listBuilder, $fieldDescriptors);

$listRepresentation = new PaginatedRepresentation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,40 @@
<list xmlns="http://schemas.sulu.io/list-builder/list">
<key>examples</key>

<joins name="contentDimension" ref="dimension">
<join>
<entity-name>contentDimension</entity-name>
<field-name>Sulu\Bundle\ContentBundle\Tests\Application\ExampleTestBundle\Entity\Example.dimensions</field-name>
<method>LEFT</method>
<condition>contentDimension.dimension = %sulu.model.dimension.class%.no</condition>
</join>
</joins>

<joins name="dimension">
<join>
<entity-name>%sulu.model.dimension.class%</entity-name>
<condition>%sulu.model.dimension.class%.locale = :locale AND %sulu.model.dimension.class%.workflowStage = 'draft'</condition>
</join>
</joins>

<properties>
<property name="id" translation="sulu_admin.id">
<field-name>id</field-name>
<entity-name>Sulu\Bundle\ContentBundle\Tests\Application\ExampleTestBundle\Entity\Example</entity-name>
</property>

<property name="dimensionId" visibility="never">
<field-name>id</field-name>
<entity-name>%sulu.model.dimension.class%</entity-name>

<joins ref="dimension"/>
</property>

<property name="title" visibility="yes" translation="sulu_admin.title">
<field-name>title</field-name>
<entity-name>contentDimension</entity-name>

<joins ref="contentDimension"/>
</property>
</properties>
</list>
7 changes: 6 additions & 1 deletion Tests/Functional/Integration/ExampleControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

use Sulu\Bundle\ContentBundle\Tests\Functional\BaseTestCase;

/**
* The integration test should have no impact on the coverage so we set it to coversNothing.
*
* @coversNothing
*/
class ExampleControllerTest extends BaseTestCase
{
protected $client;
Expand Down Expand Up @@ -109,7 +114,7 @@ public function testPut(int $id): void
*/
public function testGetList(): void
{
$this->client->request('GET', '/admin/api/examples');
$this->client->request('GET', '/admin/api/examples?locale=en');
$response = $this->client->getResponse();

$this->assertResponseContent('example_cget.json', $response, 200);
Expand Down
3 changes: 2 additions & 1 deletion Tests/Functional/Integration/responses/example_cget.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"_embedded": {
"examples": [
{
"id": "@integer@"
"id": "@integer@",
"title": "Test Example 2"
}
]
},
Expand Down

0 comments on commit 756944d

Please sign in to comment.