Skip to content

Commit

Permalink
Init Bootstrap theme component
Browse files Browse the repository at this point in the history
  • Loading branch information
loic425 committed Sep 13, 2024
1 parent d77fa7c commit ee30a5a
Show file tree
Hide file tree
Showing 402 changed files with 20,074 additions and 6 deletions.
8 changes: 8 additions & 0 deletions app/Entity/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,25 @@
use Sylius\Component\Resource\Annotation\SyliusCrudRoutes;
use Sylius\Component\Resource\Model\ResourceInterface;
use Sylius\Resource\Metadata\AsResource;
use Sylius\Resource\Metadata\BulkDelete;
use Sylius\Resource\Metadata\Create;
use Sylius\Resource\Metadata\Delete;
use Sylius\Resource\Metadata\Index;
use Sylius\Resource\Metadata\Update;
use Symfony\Component\Validator\Constraints as Assert;

#[ORM\Entity(repositoryClass: BookRepository::class)]
#[AsResource(
section: 'admin',
templatesDir: '@SyliusAdminUi/crud',
routePrefix: '/admin',
pluralName: 'library',
operations: [
new Create(),
new Update(),
new Index(grid: BookGrid::class),
new Delete(),
new BulkDelete(),
],
)]
#[SyliusCrudRoutes(
Expand All @@ -55,9 +61,11 @@ class Book implements ResourceInterface
private ?int $id = null;

#[ORM\Column(type: 'string', length: 255)]
#[Assert\NotBlank]
private ?string $title = null;

#[ORM\Column(type: 'string', length: 255)]
#[Assert\NotBlank]
private ?string $authorName = null;

#[ORM\Column(type: 'datetime_immutable')]
Expand Down
37 changes: 37 additions & 0 deletions app/Form/BookType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Form;

use App\Entity\Book;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class BookType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('title')
->add('authorName')
;
}

public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Book::class,
]);
}
}
86 changes: 86 additions & 0 deletions app/Menu/AdminMenuBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Menu;

use Knp\Menu\ItemInterface;
use Sylius\AdminUi\Knp\Menu\MenuBuilderInterface;
use Symfony\Component\DependencyInjection\Attribute\AsDecorator;

#[AsDecorator(decorates: 'sylius_admin_ui.knp.menu_builder')]
final class AdminMenuBuilder implements MenuBuilderInterface
{
public function __construct(private MenuBuilderInterface $menuBuilder)
{
}

public function createMenu(array $options): ItemInterface
{
$menu = $this->menuBuilder->createMenu($options);

$menu
->addChild('dashboard')
->setLabel('sylius.ui.dashboard')
->setLabelAttribute('icon', 'dashboard')
;

$this->addLibrarySubMenu($menu);
$this->addConfigurationSubMenu($menu);

return $menu;
}

private function addLibrarySubMenu(ItemInterface $menu): void
{
$library = $menu
->addChild('library')
->setLabel('app.ui.library')
->setLabelAttribute('icon', 'users')
;

$library->addChild('backend_pet', ['route' => 'app_admin_book_index'])
->setLabel('app.ui.books')
->setLabelAttribute('icon', 'book')
;

$library->addChild('backend_plop')
->setLabel('Authors')
->setLabelAttribute('icon', 'folder')
;
}

private function addConfigurationSubMenu(ItemInterface $menu): void
{
$library = $menu
->addChild('configuration')
->setLabel('Configuration')
->setLabelAttribute('icon', 'dashboard')
;

$library->addChild('backend_channel')
->setLabel('Channels')
->setLabelAttribute('icon', 'shuffle');

$library->addChild('backend_countries')
->setLabel('Countries')
->setLabelAttribute('icon', 'flag');

$library->addChild('backend_zones')
->setLabel('Zones')
->setLabelAttribute('icon', 'globe');

$library->addChild('backend_administrators')
->setLabel('Admin Users')
->setLabelAttribute('icon', 'lock');
}
}
50 changes: 50 additions & 0 deletions app/Twig/Component/Book/BookFormComponent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Twig\Component\Book;

use App\Entity\Book;
use App\Form\BookType;
use Sylius\TwigHooks\LiveComponent\HookableLiveComponentTrait;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\Attribute\LiveProp;
use Symfony\UX\LiveComponent\ComponentWithFormTrait;
use Symfony\UX\LiveComponent\DefaultActionTrait;

#[AsLiveComponent(template: '@SyliusBootstrapTheme/shared/crud/common/content/form.html.twig')]
final class BookFormComponent
{
use ComponentWithFormTrait;
use DefaultActionTrait;
use HookableLiveComponentTrait;

#[LiveProp(fieldName: 'formData')]
public ?Book $resource = null;

public function __construct(
private readonly FormFactoryInterface $formFactory,
) {
}

protected function instantiateForm(): FormInterface
{
return $this->formFactory->create(BookType::class, $this->resource);
}

private function getDataModelValue(): ?string
{
return 'norender|*';
}
}
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"knplabs/knp-menu-bundle": "^3.0",
"laminas/laminas-stdlib": "^3.18",
"pagerfanta/doctrine-orm-adapter": "^4.6",
"pagerfanta/twig": "^4.6",
"symfony/asset": "^6.4 || ^7.0",
"sylius/grid-bundle": "^1.13@alpha",
"sylius/resource-bundle": "^1.11 || ^1.12@alpha",
"symfony/config": "^6.4 || ^7.0",
Expand All @@ -44,6 +46,7 @@
"sylius-labs/coding-standard": "^4.0",
"symfony/browser-kit": "^6.4 || ^7.0",
"symfony/console": "^6.4 || ^7.0",
"symfony/css-selector": "^6.4 || ^7.0",
"symfony/debug-bundle": "^6.4 || ^7.0",
"symfony/dom-crawler": "^6.4 || ^7.0",
"symfony/dotenv": "^6.4 || ^7.0",
Expand All @@ -59,8 +62,10 @@
"autoload": {
"psr-4": {
"Sylius\\AdminUi\\": "src/AdminUi/src/",
"Sylius\\BootstrapTheme\\": "src/BootstrapTheme/src/",
"Sylius\\TwigExtra\\": "src/TwigExtra/src/",
"Sylius\\TwigHooks\\": "src/TwigHooks/src/"
"Sylius\\TwigHooks\\": "src/TwigHooks/src/",
"Sylius\\UiTranslations\\": "src/UiTranslations/src/"
}
},
"autoload-dev": {
Expand Down
2 changes: 2 additions & 0 deletions config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
Sylius\TwigHooks\TwigHooksBundle::class => ['all' => true],
Sylius\TwigExtra\Symfony\TwigExtraBundle::class => ['all' => true],
Sylius\AdminUi\Symfony\SyliusAdminUiBundle::class => ['all' => true],
Sylius\UiTranslations\Symfony\UiTranslationsBundle::class => ['all' => true],
Sylius\BootstrapTheme\Symfony\SyliusBootstrapThemeBundle::class => ['all' => true],
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true],
Symfony\UX\LiveComponent\LiveComponentBundle::class => ['all' => true],
Expand Down
2 changes: 1 addition & 1 deletion config/packages/framework.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
framework:
secret: '%env(APP_SECRET)%'
#csrf_protection: true
http_method_override: false
http_method_override: true #needed for legacy routes

# Enables session support. Note that the session will ONLY be started if you read or write from it.
# Remove or comment this section to explicitly disable session support.
Expand Down
12 changes: 12 additions & 0 deletions config/packages/twig_hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,15 @@ twig_hooks:
'app.base':
content:
template: 'base/content.html.twig'
# 'sylius_admin.book.create.content':
# form:
# component: 'App\Twig\Component\Book\BookFormComponent'
# props:
# form: '@=_context.form'
# resource: '@=_context.resource'
'sylius_admin.book.update.content':
form:
component: 'App\Twig\Component\Book\BookFormComponent'
props:
form: '@=_context.form'
resource: '@=_context.resource'
2 changes: 2 additions & 0 deletions src/AdminUi/templates/crud/create.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{% extends '@SyliusAdminUi/base.html.twig' %}

{% set metadata = resource_metadata|default(metadata) %}

{% set prefixes = [
'sylius_admin.%resource_name%'|replace({'%resource_name%': resource_name|default(metadata.name)}),
'sylius_admin.common'
Expand Down
4 changes: 3 additions & 1 deletion src/AdminUi/templates/crud/index.html.twig
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{% extends '@SyliusAdminUi/base.html.twig' %}

{% set metadata = resource_metadata|default(metadata) %}

{% set prefixes = [
'sylius_admin.%resource_name%'|replace({'%resource_name%': resource_name|default(metadata.name)}),
'sylius_admin.common'
] %}

{% set header = configuration.vars.header|default(metadata.applicationName~'.ui.'~metadata.pluralName) %}
{% set header = vars.header|default(metadata.applicationName~'.ui.'~metadata.pluralName) %}

{% block title %}{{ header|trans }} {{ parent() }}{% endblock %}

Expand Down
2 changes: 2 additions & 0 deletions src/AdminUi/templates/crud/update.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{% extends '@SyliusAdminUi/base.html.twig' %}

{% set metadata = resource_metadata|default(metadata) %}

{% set prefixes = [
'sylius_admin.%resource_name%'|replace({'%resource_name%': resource_name|default(metadata.name)}),
'sylius_admin.common'
Expand Down
1 change: 1 addition & 0 deletions src/BootstrapTheme/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
21 changes: 21 additions & 0 deletions src/BootstrapTheme/assets/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

import {startStimulusApp} from '@symfony/stimulus-bridge';
import LiveController from '@symfony/ux-live-component';
import '@symfony/ux-live-component/styles/live.css';

// Registers Stimulus controllers from controllers.json and in the controllers/ directory
export const app = startStimulusApp(require.context(
'@symfony/stimulus-bridge/lazy-controller-loader!./controllers',
true,
/\.[jt]sx?$/
));

app.register('live', LiveController);
4 changes: 4 additions & 0 deletions src/BootstrapTheme/assets/controllers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"controllers": {},
"entrypoints": []
}
Empty file.
21 changes: 21 additions & 0 deletions src/BootstrapTheme/assets/entrypoint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

import './styles/main.scss';

import './bootstrap';

import './scripts/bulk-delete';
import './scripts/check-all';
import './scripts/choices';
import './scripts/menu-search';
import './scripts/sticky-header';
import './scripts/tree';

import './scripts/bootstrap';
Binary file not shown.
10 changes: 10 additions & 0 deletions src/BootstrapTheme/assets/images/no_data.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit ee30a5a

Please sign in to comment.