-
Notifications
You must be signed in to change notification settings - Fork 21
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 #36 from maximehuran/feature/slug-selector
Add slug selector in modal to simplify URL field completion
- Loading branch information
Showing
36 changed files
with
744 additions
and
20 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
imports: | ||
- { resource: "@MonsieurBizSyliusMenuPlugin/Resources/config/config.yaml" } | ||
|
||
twig: | ||
form_themes: ['@MonsieurBizSyliusMenuPlugin/Admin/Browser/Form/_theme.html.twig'] |
Empty file.
5 changes: 5 additions & 0 deletions
5
recipes/1.3-dev/config/packages/monsieurbiz_sylius_menu_plugin.yaml
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,5 @@ | ||
imports: | ||
- { resource: "@MonsieurBizSyliusMenuPlugin/Resources/config/config.yaml" } | ||
|
||
twig: | ||
form_themes: ['@MonsieurBizSyliusMenuPlugin/Admin/Browser/Form/_theme.html.twig'] |
3 changes: 3 additions & 0 deletions
3
recipes/1.3-dev/config/routes/monsieurbiz_sylius_menu_plugin.yaml
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,3 @@ | ||
monsieurbiz_menu_admin_menu: | ||
resource: "@MonsieurBizSyliusMenuPlugin/Resources/config/routes/admin.yaml" | ||
prefix: /%sylius_admin.path_name% |
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,10 @@ | ||
{ | ||
"bundles": { | ||
"MonsieurBiz\\SyliusMenuPlugin\\MonsieurBizSyliusMenuPlugin": [ | ||
"all" | ||
] | ||
}, | ||
"copy-from-recipe": { | ||
"config/": "%CONFIG_DIR%/" | ||
} | ||
} |
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,66 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Monsieur Biz' Menu plugin for Sylius. | ||
* | ||
* (c) Monsieur Biz <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MonsieurBiz\SyliusMenuPlugin\Controller; | ||
|
||
use MonsieurBiz\SyliusMenuPlugin\Provider\BrowsableObjectProviderInterface; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
final class BrowserController extends AbstractController | ||
{ | ||
public function __construct( | ||
private BrowsableObjectProviderInterface $browsableObjectProvider | ||
) { | ||
} | ||
|
||
public function listAction( | ||
Request $request, | ||
): ?Response { | ||
$inputName = (string) $request->query->get('inputName', ''); | ||
$inputValue = (string) $request->query->get('inputValue', ''); | ||
$locale = (string) $request->query->get('locale', ''); | ||
|
||
return $this->render('@MonsieurBizSyliusMenuPlugin/Admin/Browser/_modal.html.twig', [ | ||
'urlProviders' => $this->browsableObjectProvider->getUrlProviders(), | ||
'inputName' => $inputName, | ||
'inputValue' => $inputValue, | ||
'locale' => $locale, | ||
]); | ||
} | ||
|
||
public function listItemsAction( | ||
Request $request, | ||
): ?Response { | ||
$providerCode = (string) $request->query->get('providerCode', ''); | ||
$inputName = (string) $request->query->get('inputName', ''); | ||
$inputValue = (string) $request->query->get('inputValue', ''); | ||
$locale = (string) $request->query->get('locale', ''); | ||
$search = (string) $request->query->get('search', ''); | ||
|
||
$urlProvider = $this->browsableObjectProvider->findProviderByCode($providerCode); | ||
if (null === $urlProvider) { | ||
return new JsonResponse(['error' => 'URL Provider not found'], 404); | ||
} | ||
|
||
return $this->render('@MonsieurBizSyliusMenuPlugin/Admin/Browser/_modal.html.twig', [ | ||
'urlProvider' => $urlProvider, | ||
'inputName' => $inputName, | ||
'inputValue' => $inputValue, | ||
'locale' => $locale, | ||
'search' => $search, | ||
]); | ||
} | ||
} |
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
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,24 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Monsieur Biz' Menu plugin for Sylius. | ||
* | ||
* (c) Monsieur Biz <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MonsieurBiz\SyliusMenuPlugin\Form\Type; | ||
|
||
use Symfony\Component\Form\Extension\Core\Type\TextType; | ||
|
||
final class UrlType extends TextType | ||
{ | ||
public function getBlockPrefix(): string | ||
{ | ||
return 'monsieurbiz_sylius_menu_url'; | ||
} | ||
} |
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,85 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Monsieur Biz' Menu plugin for Sylius. | ||
* | ||
* (c) Monsieur Biz <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MonsieurBiz\SyliusMenuPlugin\Provider; | ||
|
||
use Symfony\Component\Routing\RouterInterface; | ||
|
||
abstract class AbstractUrlProvider implements UrlProviderInterface | ||
{ | ||
protected int $maxResults = 1000; | ||
|
||
protected string $code; | ||
|
||
protected string $icon = 'angle right'; | ||
|
||
protected int $priority = 0; | ||
|
||
protected array $items = []; | ||
|
||
public function __construct( | ||
protected RouterInterface $router | ||
) { | ||
} | ||
|
||
public function getIcon(): string | ||
{ | ||
return $this->icon; | ||
} | ||
|
||
public function getCode(): string | ||
{ | ||
return $this->code; | ||
} | ||
|
||
public function getPriority(): int | ||
{ | ||
return $this->priority; | ||
} | ||
|
||
public function getMaxResults(): int | ||
{ | ||
return $this->maxResults; | ||
} | ||
|
||
protected function addItem(string $name, string $path): void | ||
{ | ||
$this->items[] = [ | ||
'name' => $name, | ||
'value' => $path, | ||
]; | ||
} | ||
|
||
protected function sortItems(): void | ||
{ | ||
usort($this->items, fn ($itemA, $itemB) => $itemA['name'] <=> $itemB['name']); | ||
} | ||
|
||
abstract protected function getResults(string $locale, string $search = ''): iterable; | ||
|
||
abstract protected function addItemFromResult(object $result, string $locale): void; | ||
|
||
public function getItems(string $locale, string $search = ''): array | ||
{ | ||
$this->items = []; | ||
$results = $this->getResults($locale, $search); | ||
|
||
foreach ($results as $result) { | ||
$this->addItemFromResult($result, $locale); | ||
} | ||
|
||
$this->sortItems(); | ||
|
||
return $this->items; | ||
} | ||
} |
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,45 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Monsieur Biz' Menu plugin for Sylius. | ||
* | ||
* (c) Monsieur Biz <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MonsieurBiz\SyliusMenuPlugin\Provider; | ||
|
||
class BrowsableObjectProvider implements BrowsableObjectProviderInterface | ||
{ | ||
public function __construct(private iterable $urlProviders) | ||
{ | ||
} | ||
|
||
public function getUrlProviders(): array | ||
{ | ||
$urlProviders = []; | ||
foreach ($this->urlProviders as $urlProvider) { | ||
$urlProviders[$urlProvider->getCode()] = $urlProvider; | ||
} | ||
|
||
uasort($urlProviders, fn ($urlProviderA, $urlProviderB) => $urlProviderB->getPriority() <=> $urlProviderA->getPriority()); | ||
|
||
return $urlProviders; | ||
} | ||
|
||
public function findProviderByCode(string $code): ?UrlProviderInterface | ||
{ | ||
/** @var UrlProviderInterface $urlProvider */ | ||
foreach ($this->getUrlProviders() as $urlProvider) { | ||
if ($urlProvider->getCode() === $code) { | ||
return $urlProvider; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Monsieur Biz' Menu plugin for Sylius. | ||
* | ||
* (c) Monsieur Biz <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MonsieurBiz\SyliusMenuPlugin\Provider; | ||
|
||
interface BrowsableObjectProviderInterface | ||
{ | ||
public function getUrlProviders(): array; | ||
|
||
public function findProviderByCode(string $code): ?UrlProviderInterface; | ||
} |
Oops, something went wrong.