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

Feature/content integration #32

Merged
merged 3 commits into from
May 14, 2021
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
6 changes: 6 additions & 0 deletions Config/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
<hook id="theliablocks.hook.plugin" class="TheliaBlocks\Hook\TheliaBlocksPluginHook" scope="request">
<tag name="hook.event_listener" event="thelia.blocks.plugins" type="back" method="onPlugins" />
</hook>
<hook id="theliablocks.hook" class="TheliaBlocks\Hook\TheliaBlocksBackHook">
<tag name="hook.event_listener" event="product.tab" type="backoffice" method="onProductTab"/>
<tag name="hook.event_listener" event="category.tab" type="backoffice" method="onCategoryTab"/>
<tag name="hook.event_listener" event="content.tab" type="backoffice" method="onContentTab"/>
<tag name="hook.event_listener" event="folder.tab" type="backoffice" method="onFolderTab"/>
</hook>
</hooks>

</config>
94 changes: 94 additions & 0 deletions Hook/TheliaBlocksBackHook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace TheliaBlocks\Hook;

use TheliaBlocks\TheliaBlocks;
use Thelia\Core\Hook\BaseHook;
use Thelia\Core\Event\Hook\HookRenderBlockEvent;
use Thelia\Tools\URL;
use TheliaBlocks\Model\BlockGroupQuery;

class TheliaBlocksBackHook extends BaseHook
{
protected $requestStack;
protected $productDataImageService;

public function onProductTab(HookRenderBlockEvent $event): void
{
$formRedirectUrl = URL::getInstance()
->absoluteUrl(
'/admin/products/update',
[
'product_id' => $event->getArgument('id'),
'current_tab' => 'theliablocks_item_details',
]
);
$this->addTheliaBlocksConfigurationTab($event, 'product', $formRedirectUrl);
}

public function onCategoryTab(HookRenderBlockEvent $event): void
{
$formRedirectUrl = URL::getInstance()
->absoluteUrl(
'/admin/categories/update',
[
'category_id' => $event->getArgument('id'),
'current_tab' => 'theliablocks_item_details',
]
);
$this->addTheliaBlocksConfigurationTab($event, 'category', $formRedirectUrl);
}

public function onContentTab(HookRenderBlockEvent $event): void
{
$formRedirectUrl = URL::getInstance()
->absoluteUrl(
'/admin/content/update/'.$event->getArgument('id'),
[
'current_tab' => 'theliablocks_item_details',
]
);
$this->addTheliaBlocksConfigurationTab($event, 'content', $formRedirectUrl);
}

public function onFolderTab(HookRenderBlockEvent $event): void
{
$formRedirectUrl = URL::getInstance()
->absoluteUrl(
'/admin/folders/update/'.$event->getArgument('id'),
[
'current_tab' => 'theliablocks_item_details',
]
);
$this->addTheliaBlocksConfigurationTab($event, 'folder', $formRedirectUrl);
}


protected function addTheliaBlocksConfigurationTab(HookRenderBlockEvent $event, $itemType, $formRedirectUrl): void
{
$itemId = $event->getArgument('id');

$search = BlockGroupQuery::create();
$search->useItemBlockGroupQuery()
->filterByItemType($itemType)
->filterByItemId($itemId)
->endUse();

$group = $search->findOne();

$event->add(
[
'id' => 'theliablocks_item_details',
'title' => $this->trans('Thelia Blocks', [], TheliaBlocks::DOMAIN_NAME),
'content' => $this->render(
'thelia-blocks-item-configuration.html',
[
'itemId' => $itemId,
'itemType' => $itemType,
'groupId' => $group ? $group->getId() : null
]
),
]
);
}
}
2 changes: 1 addition & 1 deletion Model/Api/ItemBlockGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ItemBlockGroup extends BaseApiModel
/**
* @return int
*/
public function getId(): int
public function getId(): ?int
{
return $this->id;
}
Expand Down
2 changes: 1 addition & 1 deletion templates/backOffice/default/app/dist/style.css

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions templates/backOffice/default/app/dist/thelia-blocks.es.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions templates/backOffice/default/app/dist/thelia-blocks.umd.js

Large diffs are not rendered by default.

Loading