Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors in composer container page #1623

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions assets/scss/composer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -396,15 +396,19 @@ $color_red: #f56954;
margin-top: 11px;
}

.page-composer__container__child__edit {
.page-composer__container__child__edit,
.page-composer__container__child__error {
border-left: 3px solid #f9f9f9;
color: #404040 !important;
cursor: pointer;
display: block;
padding: 10px 15px 10px 27px;
text-decoration: none !important;
}

.page-composer__container__child__edit {
cursor: pointer;
}

.page-composer__container__child__right {
position: absolute;
right: 5px;
Expand Down
18 changes: 9 additions & 9 deletions src/Admin/BlockAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,25 +172,25 @@ protected function configureFormFields(FormMapper $form): void
$form->add('position', IntegerType::class);
}

$form->end();

$form->with('options', $optionsGroupOptions);

$this->configureBlockFields($form, $block);

if (false !== $isComposer) {
$form->add('enabled', HiddenType::class, ['data' => true]);
} else {
$form->add('enabled');
}

$form->end();

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is better this way, this looks more similar to what we do on shared blocks.

$form->with('options', $optionsGroupOptions);

$this->configureBlockFields($form, $block);

$form->end();
} else {
$form
->with('options', $optionsGroupOptions)
->add('type', ServiceListType::class, ['context' => 'sonata_page_bundle'])
->add('enabled')
->add('position', IntegerType::class)
->add('type', ServiceListType::class, ['context' => 'sonata_page_bundle'])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing indentation. better to code readability.

->add('enabled')
->add('position', IntegerType::class)
->end();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/public/app.css

Large diffs are not rendered by default.

62 changes: 41 additions & 21 deletions src/Resources/views/BlockAdmin/compose_preview.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,49 @@
data-block-enabled="{{ child.enabled|default('0') }}"
data-block-type="{{ child.type }}"
>
<a class="page-composer__container__child__edit"
href="{{ blockAdmin.generateUrl('edit', { 'id': child.id, 'composer': true }) }}"
{% set service = attribute(blockServices, child.type) ?? null %}

{% if service %}
<a
class="page-composer__container__child__edit"
href="{{ blockAdmin.generateUrl('edit', { 'id': child.id, 'composer': true }) }}"
>
{% set service = attribute(blockServices, child.type) %}
{% if service.metadata is defined %}
{% set metadata = service.metadata %}
{% else %}
<div class="page-composer__container__child__error">
{% endif %}
{% if service %}
{% set metadataTitle = service.metadata.title|trans({}, service.metadata.domain|default('SonataPageBundle')) %}
{% set blockTitle = child.name|default(metadataTitle) %}
{% set blockImage = service.metadata.image ? asset(service.metadata.image) : null %}
{% set blockClass = service.metadata.option('class') %}
{% else %}
{% set metadata = service.blockMetadata %}
{% set metadataTitle = child.type %}
{% set blockTitle = child.name %}
{% set blockImage = null %}
{% set blockClass = null %}
{% endif %}
<h4 class="page-composer__container__child__name">
{{ child.name|default(metadata.title)|trans({}, metadata.domain|default('SonataPageBundle')) }}
</h4>
{% if not metadata.image %}
<i class="{{ metadata.option('class') }}" ></i>
{% else %}
<img src="{{ asset(metadata.image) }}" style="max-height: 20px; max-width: 100px;"/>

<h4 class="page-composer__container__child__name">{{ blockTitle }}</h4>

{% if blockImage %}
<img src="{{ blockImage }}" style="max-height: 20px; max-width: 100px;"/>
{% elseif blockClass %}
<i class="{{ blockClass }}" ></i>
{% endif %}
<small>{{ metadata.title|trans({}, metadata.domain|default('SonataPageBundle')) }}</small>
<span class="page-composer__container__child__toggle">
<i class="fa fa-chevron-down"></i>
<i class="fa fa-chevron-up"></i>
</span>

<small>{{ metadataTitle }}</small>

{% if service %}
<span class="page-composer__container__child__toggle">
<i class="fa fa-chevron-down"></i>
<i class="fa fa-chevron-up"></i>
</span>
{% endif %}
{% if service %}
</a>
{% else %}
</div>
{% endif %}

<div class="page-composer__container__child__right">
<div class="page-composer__container__child__remove">
Expand All @@ -45,7 +65,8 @@
'context': 'list',
'field': 'enabled',
'_sonata_admin': 'sonata.page.admin.block'
}) }}">
}) }}"
>
{% if child.enabled %}{{ 'composer.disable'|trans({}, 'SonataPageBundle') }}
<i class="fa fa-toggle-off"></i>
{% else %}
Expand All @@ -60,8 +81,7 @@
</div>
</div>

<div class="page-composer__container__child__content">
</div>
<div class="page-composer__container__child__content"></div>

<div class="page-composer__container__child__loader">
<span>{{ 'loading'|trans({}, 'SonataPageBundle') }}</span>
Expand Down
12 changes: 9 additions & 3 deletions tests/Functional/Admin/BlockAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Doctrine\ORM\EntityManagerInterface;
use Sonata\PageBundle\Tests\App\Entity\SonataPageBlock;
use Sonata\PageBundle\Tests\App\Entity\SonataPagePage;
use Sonata\PageBundle\Tests\App\Entity\SonataPageSite;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

final class BlockAdminTest extends WebTestCase
Expand Down Expand Up @@ -52,7 +53,7 @@ public static function provideCrudUrlsCases(): iterable

yield 'Edit Block' => ['/admin/tests/app/sonatapageblock/1/edit'];
yield 'Remove Block' => ['/admin/tests/app/sonatapageblock/1/delete'];
yield 'Compose preview Block' => ['/admin/tests/app/sonatapageblock/3/compose-preview'];
yield 'Compose preview Block' => ['/admin/tests/app/sonatapageblock/2/compose-preview'];
}

/**
Expand Down Expand Up @@ -233,9 +234,14 @@ private function prepareData(): void
$manager = $container->get('doctrine.orm.entity_manager');
\assert($manager instanceof EntityManagerInterface);

$site = new SonataPageSite();
$site->setName('name');
$site->setHost('localhost');

$page = new SonataPagePage();
$page->setName('name');
$page->setTemplateCode('default');
$page->setSite($site);

$parentBlock = new SonataPageBlock();
$parentBlock->setType('sonata.page.block.container');
Expand All @@ -245,13 +251,13 @@ private function prepareData(): void

$block = new SonataPageBlock();
$block->setType('sonata.block.service.text');
$block->setParent($parentBlock);

$page->addBlock($parentBlock);
$page->addBlock($parentBlock2);
$parentBlock->addChild($block);

$manager->persist($site);
$manager->persist($page);
$manager->persist($block);

$manager->flush();
}
Expand Down
9 changes: 6 additions & 3 deletions tests/Functional/Admin/PageAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static function provideCrudUrlsCases(): iterable
yield 'Show Page' => ['/admin/tests/app/sonatapagepage/1/show'];
yield 'Remove Page' => ['/admin/tests/app/sonatapagepage/1/delete'];
yield 'Compose Page' => ['/admin/tests/app/sonatapagepage/1/compose'];
yield 'Compose Show Page' => ['/admin/tests/app/sonatapagepage/compose/container/1'];
yield 'Compose Container Page' => ['/admin/tests/app/sonatapagepage/compose/container/1'];

// Snapshot child pages
yield 'List Snapshot Page' => ['/admin/tests/app/sonatapagepage/1/sonatapagesnapshot/list'];
Expand Down Expand Up @@ -296,10 +296,13 @@ private function prepareData(): void

$block = new SonataPageBlock();
$block->setType('sonata.block.service.text');
$block->setParent($parentBlock);

$block2 = new SonataPageBlock();
$block2->setType('non_existent_block');

$page->addBlock($parentBlock);
$page->addBlock($block);
$parentBlock->addChild($block);
$parentBlock->addChild($block2);

$manager->persist($site);
$manager->persist($site2);
Expand Down
3 changes: 1 addition & 2 deletions tests/Functional/Command/CloneSiteCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,9 @@ private function prepareData(): void

$block = new SonataPageBlock();
$block->setType('sonata.block.service.text');
$block->setParent($parentBlock);

$page->addBlock($parentBlock);
$page->addBlock($block);
$parentBlock->addChild($block);

$manager->persist($site);
$manager->persist($site2);
Expand Down
21 changes: 10 additions & 11 deletions tests/Functional/Frontend/PageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,9 @@ public static function providePages(): iterable
$block = new SonataPageBlock();
$block->setType('sonata.block.service.text');
$block->setSetting('content', 'Footer content');
$block->setParent($containerBlock);

$page->addBlock($containerBlock);
$page->addBlock($block);
$containerBlock->addChild($block);

return $page;
})(), '/random_route', 404, ['Footer content'], []];
Expand Down Expand Up @@ -257,20 +256,21 @@ private function prepareData(): void
$block = new SonataPageBlock();
$block->setType('sonata.page.block.shared_block');
$block->setSetting('blockId', 3);
$block->setParent($containerBlock);

$block2 = new SonataPageBlock();
$block2->setType('sonata.page.block.pagelist');
$block2->setParent($containerBlock);

$block3 = new SonataPageBlock();
$block3->setType('sonata.page.block.children_pages');
$block3->setSetting('pageId', 1);
$block3->setParent($containerBlock);

$block4 = new SonataPageBlock();
$block4->setType('sonata.page.block.breadcrumb');
$block4->setParent($containerBlock);

$containerBlock->addChild($block);
$containerBlock->addChild($block2);
$containerBlock->addChild($block3);
$containerBlock->addChild($block4);

$page->addBlock($containerBlock);
$page->addBlock($block);
Expand Down Expand Up @@ -308,7 +308,8 @@ private function preparePageTypesData(PageInterface $page): void
$block = new SonataPageBlock();
$block->setType('sonata.block.service.text');
$block->setSetting('content', 'Page content');
$block->setParent($containerBlock);

$containerBlock->addChild($block);

$page->setSite($site);
$page->addBlock($containerBlock);
Expand Down Expand Up @@ -363,17 +364,15 @@ private function prepareGlobalPageData(): void
$block = new SonataPageBlock();
$block->setType('sonata.block.service.text');
$block->setSetting('content', 'Footer content');
$block->setParent($containerBlock);

$block2 = new SonataPageBlock();
$block2->setType('sonata.block.service.text');
$block2->setSetting('content', 'Page content');
$block2->setParent($containerBlock2);

$page->addBlock($containerBlock);
$page->addBlock($block);
$page2->addBlock($containerBlock2);
$page2->addBlock($block2);
$containerBlock->addChild($block);
$containerBlock2->addChild($block2);

$manager->persist($site);
$manager->persist($page);
Expand Down
9 changes: 4 additions & 5 deletions tests/Functional/Frontend/SnapshotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ private function prepareSnapshotTypesData(PageInterface $page): void
$block = new SonataPageBlock();
$block->setType('sonata.block.service.text');
$block->setSetting('content', 'Page content');
$block->setParent($containerBlock);

$containerBlock->addChild($block);

$page->setSite($site);
$page->addBlock($containerBlock);
Expand Down Expand Up @@ -313,17 +314,15 @@ private function prepareGlobalSnapshotData(): void
$block = new SonataPageBlock();
$block->setType('sonata.block.service.text');
$block->setSetting('content', 'Footer content');
$block->setParent($containerBlock);

$block2 = new SonataPageBlock();
$block2->setType('sonata.block.service.text');
$block2->setSetting('content', 'Page content');
$block2->setParent($containerBlock2);

$page->addBlock($containerBlock);
$page->addBlock($block);
$page2->addBlock($containerBlock2);
$page2->addBlock($block2);
$containerBlock->addChild($block);
$containerBlock2->addChild($block2);

$manager->persist($site);
$manager->persist($page);
Expand Down