Skip to content

Commit

Permalink
Merge pull request #32 from thelia-modules/feature/content-integration
Browse files Browse the repository at this point in the history
Feature/content integration
  • Loading branch information
Bdg0o committed May 14, 2021
2 parents 4e5075a + b8cb1f6 commit efa453f
Show file tree
Hide file tree
Showing 42 changed files with 625 additions and 3,529 deletions.
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

0 comments on commit efa453f

Please sign in to comment.