Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7468 from NeverResponse/form-menu-builder
[UI][Admin] Form menu builders for Product and Product Variant edits
- Loading branch information
Showing
17 changed files
with
416 additions
and
58 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/Sylius/Bundle/AdminBundle/Event/ProductMenuBuilderEvent.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sylius\Bundle\AdminBundle\Event; | ||
|
||
use Knp\Menu\FactoryInterface; | ||
use Knp\Menu\ItemInterface; | ||
use Sylius\Bundle\UiBundle\Menu\Event\MenuBuilderEvent; | ||
use Sylius\Component\Product\Model\ProductInterface; | ||
|
||
/** | ||
* @author Jan Góralski <jan.goralski@lakion.com> | ||
*/ | ||
class ProductMenuBuilderEvent extends MenuBuilderEvent | ||
{ | ||
/** | ||
* @var ProductInterface | ||
*/ | ||
private $product; | ||
|
||
/** | ||
* @param FactoryInterface $factory | ||
* @param ItemInterface $menu | ||
* @param ProductInterface $product | ||
*/ | ||
public function __construct(FactoryInterface $factory, ItemInterface $menu, ProductInterface $product) | ||
{ | ||
parent::__construct($factory, $menu); | ||
|
||
$this->product = $product; | ||
} | ||
|
||
/** | ||
* @return ProductInterface | ||
*/ | ||
public function getProduct() | ||
{ | ||
return $this->product; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/Sylius/Bundle/AdminBundle/Event/ProductVariantMenuBuilderEvent.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sylius\Bundle\AdminBundle\Event; | ||
|
||
use Knp\Menu\FactoryInterface; | ||
use Knp\Menu\ItemInterface; | ||
use Sylius\Bundle\UiBundle\Menu\Event\MenuBuilderEvent; | ||
use Sylius\Component\Core\Model\ProductVariantInterface; | ||
|
||
/** | ||
* @author Jan Góralski <jan.goralski@lakion.com> | ||
*/ | ||
class ProductVariantMenuBuilderEvent extends MenuBuilderEvent | ||
{ | ||
/** | ||
* @var ProductVariantInterface | ||
*/ | ||
private $productVariant; | ||
|
||
/** | ||
* @param FactoryInterface $factory | ||
* @param ItemInterface $menu | ||
* @param ProductVariantInterface $productVariant | ||
*/ | ||
public function __construct(FactoryInterface $factory, ItemInterface $menu, ProductVariantInterface $productVariant) | ||
{ | ||
parent::__construct($factory, $menu); | ||
|
||
$this->productVariant = $productVariant; | ||
} | ||
|
||
/** | ||
* @return ProductVariantInterface | ||
*/ | ||
public function getProductVariant() | ||
{ | ||
return $this->productVariant; | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
src/Sylius/Bundle/AdminBundle/Menu/ProductFormMenuBuilder.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sylius\Bundle\AdminBundle\Menu; | ||
|
||
use Knp\Menu\FactoryInterface; | ||
use Knp\Menu\ItemInterface; | ||
use Sylius\Bundle\AdminBundle\Event\ProductMenuBuilderEvent; | ||
use Sylius\Component\Core\Model\ProductInterface; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
|
||
/** | ||
* @author Jan Góralski <jan.goralski@lakion.com> | ||
*/ | ||
final class ProductFormMenuBuilder | ||
{ | ||
const EVENT_NAME = 'sylius.menu.admin.product.form'; | ||
|
||
/** | ||
* @var FactoryInterface | ||
*/ | ||
private $factory; | ||
|
||
/** | ||
* @var EventDispatcherInterface | ||
*/ | ||
private $eventDispatcher; | ||
|
||
/** | ||
* @param FactoryInterface $factory | ||
* @param EventDispatcherInterface $eventDispatcher | ||
*/ | ||
public function __construct(FactoryInterface $factory, EventDispatcherInterface $eventDispatcher) | ||
{ | ||
$this->factory = $factory; | ||
$this->eventDispatcher = $eventDispatcher; | ||
} | ||
|
||
/** | ||
* @param array $options | ||
* | ||
* @return ItemInterface | ||
*/ | ||
public function createMenu(array $options = []) | ||
{ | ||
$menu = $this->factory->createItem('root'); | ||
|
||
if (!array_key_exists('product', $options) || !$options['product'] instanceof ProductInterface) { | ||
return $menu; | ||
} | ||
|
||
$menu | ||
->addChild('details') | ||
->setAttribute('template', '@SyliusAdmin/Product/Tab/_details.html.twig') | ||
->setLabel('sylius.ui.details') | ||
->setCurrent(true) | ||
; | ||
|
||
$menu | ||
->addChild('taxonomy') | ||
->setAttribute('template', '@SyliusAdmin/Product/Tab/_taxonomy.html.twig') | ||
->setLabel('sylius.ui.taxonomy') | ||
; | ||
|
||
$menu | ||
->addChild('attributes') | ||
->setAttribute('template', '@SyliusAdmin/Product/Tab/_attributes.html.twig') | ||
->setLabel('sylius.ui.attributes') | ||
; | ||
|
||
$menu | ||
->addChild('associations') | ||
->setAttribute('template', '@SyliusAdmin/Product/Tab/_associations.html.twig') | ||
->setLabel('sylius.ui.associations') | ||
; | ||
|
||
$menu | ||
->addChild('media') | ||
->setAttribute('template', '@SyliusAdmin/Product/Tab/_media.html.twig') | ||
->setLabel('sylius.ui.media') | ||
; | ||
|
||
$this->eventDispatcher->dispatch( | ||
self::EVENT_NAME, | ||
new ProductMenuBuilderEvent($this->factory, $menu, $options['product']) | ||
); | ||
|
||
return $menu; | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
src/Sylius/Bundle/AdminBundle/Menu/ProductVariantFormMenuBuilder.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sylius\Bundle\AdminBundle\Menu; | ||
|
||
use Knp\Menu\FactoryInterface; | ||
use Knp\Menu\ItemInterface; | ||
use Sylius\Bundle\AdminBundle\Event\ProductVariantMenuBuilderEvent; | ||
use Sylius\Component\Product\Model\ProductVariantInterface; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
|
||
/** | ||
* @author Jan Góralski <jan.goralski@lakion.com> | ||
*/ | ||
final class ProductVariantFormMenuBuilder | ||
{ | ||
const EVENT_NAME = 'sylius.menu.admin.product_variant.form'; | ||
|
||
/** | ||
* @var FactoryInterface | ||
*/ | ||
private $factory; | ||
|
||
/** | ||
* @var EventDispatcherInterface | ||
*/ | ||
private $eventDispatcher; | ||
|
||
/** | ||
* @param FactoryInterface $factory | ||
* @param EventDispatcherInterface $eventDispatcher | ||
*/ | ||
public function __construct(FactoryInterface $factory, EventDispatcherInterface $eventDispatcher) | ||
{ | ||
$this->factory = $factory; | ||
$this->eventDispatcher = $eventDispatcher; | ||
} | ||
|
||
/** | ||
* @param array $options | ||
* | ||
* @return ItemInterface | ||
*/ | ||
public function createMenu(array $options = []) | ||
{ | ||
$menu = $this->factory->createItem('root'); | ||
|
||
if (!array_key_exists('product_variant', $options) || !$options['product_variant'] instanceof ProductVariantInterface) { | ||
return $menu; | ||
} | ||
|
||
$menu | ||
->addChild('details') | ||
->setAttribute('template', '@SyliusAdmin/ProductVariant/Tab/_details.html.twig') | ||
->setLabel('sylius.ui.details') | ||
->setCurrent(true) | ||
; | ||
|
||
$menu | ||
->addChild('taxes') | ||
->setAttribute('template', '@SyliusAdmin/ProductVariant/Tab/_taxes.html.twig') | ||
->setLabel('sylius.ui.taxes') | ||
; | ||
|
||
$this->eventDispatcher->dispatch( | ||
self::EVENT_NAME, | ||
new ProductVariantMenuBuilderEvent($this->factory, $menu, $options['product_variant']) | ||
); | ||
|
||
return $menu; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/Sylius/Bundle/AdminBundle/Resources/private/js/sylius-compound-form-errors.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
(function ($) { | ||
'use strict'; | ||
|
||
$.fn.extend({ | ||
addTabErrors: function () { | ||
var element = $(this); | ||
var tabElements = element.find('.ui.segment'); | ||
|
||
$(tabElements).each(function () { | ||
var errors = $(this).find('.sylius-validation-error'); | ||
|
||
if(0 !== errors.length) { | ||
var tabName = $(this).find('.ui.tab').attr('data-tab'); | ||
var tabWithErrors = $(element).find('a.item[data-tab="' + tabName + '"]'); | ||
|
||
var label = tabWithErrors.html(); | ||
var newLabel = label + '<span class="ui small horizontal circular label" style="background-color: #DB2828">' + errors.length + '</span>'; | ||
|
||
tabWithErrors.html(newLabel); | ||
} | ||
}); | ||
}, | ||
addAccordionErrors: function () { | ||
var element = $(this); | ||
var accordionElements = element.find('.ui.content'); | ||
|
||
$(accordionElements).each(function () { | ||
var errors = $(this).find('.sylius-validation-error'); | ||
|
||
if(0 !== errors.length) { | ||
var ribWithErrors = $(this).closest('[data-locale]').find('.title'); | ||
|
||
ribWithErrors.css('color', '#DB2828'); | ||
} | ||
}); | ||
} | ||
}) | ||
})( jQuery ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 2 additions & 12 deletions
14
src/Sylius/Bundle/AdminBundle/Resources/views/Product/_form.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,2 @@ | ||
{{ form_errors(form) }} | ||
|
||
<div class="ui stackable grid"> | ||
<div class="three wide column"> | ||
{% include '@SyliusAdmin/Product/_menu.html.twig' %} | ||
</div> | ||
<div class="thirteen wide column"> | ||
<div class="ui segment"> | ||
{% include '@SyliusAdmin/Product/_tabs.html.twig' %} | ||
</div> | ||
</div> | ||
</div> | ||
{% set menu = knp_menu_get('sylius.admin.product_form', [], {'product': product}) %} | ||
{{ knp_menu_render(menu, {'template': 'SyliusAdminBundle:Product:_menu.html.twig', 'form': form, 'product': product}) }} |
Oops, something went wrong.