-
Notifications
You must be signed in to change notification settings - Fork 45
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 #217 from delyriand/feature/attribute-declaration
Allow UI Elements to be declared using PHP attributes
- Loading branch information
Showing
19 changed files
with
456 additions
and
54 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
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,13 @@ | ||
{# | ||
UI Element template | ||
type: google_map | ||
element fields: | ||
link: string | ||
element methods: | ||
getLocale(): string | ||
#} | ||
|
||
<div style="width: 100%"> | ||
{{ ui_element.getLocale() }} | ||
{{ element.link|replace({'hl=en': 'hl=' ~ ui_element.getLocale()}) }} | ||
</div> |
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,12 @@ | ||
{# | ||
UI Element template | ||
type: google_map | ||
element fields: | ||
link: string | ||
element methods: | ||
getLocale(): string | ||
#} | ||
|
||
<div style="width: 100%"> | ||
<iframe width="100%" height="600" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="{{ element.link }}"><a href="https://www.gps.ie/">gps devices</a></iframe> | ||
</div> |
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,96 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Monsieur Biz' Rich Editor plugin for Sylius. | ||
* | ||
* (c) Monsieur Biz <sylius@monsieurbiz.com> | ||
* | ||
* 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\SyliusRichEditorPlugin\Attribute; | ||
|
||
use Attribute; | ||
use MonsieurBiz\SyliusRichEditorPlugin\UiElement\UiElement; | ||
|
||
#[Attribute(Attribute::TARGET_CLASS)] | ||
class AsUiElement | ||
{ | ||
/** | ||
* @SuppressWarnings(PHPMD.ExcessiveParameterList) | ||
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) | ||
*/ | ||
public function __construct( | ||
public string $code, | ||
public string $icon, | ||
public ?string $title = null, | ||
public ?string $description = null, | ||
public string $uiElement = UiElement::class, | ||
public ?TemplatesUiElement $templates = null, | ||
public string $alias = '', | ||
public string $wireframe = '', | ||
public bool $enabled = true, | ||
public array $tags = [], | ||
) { | ||
} | ||
|
||
public function getCode(): string | ||
{ | ||
return $this->code; | ||
} | ||
|
||
public function getConfiguration(): array | ||
{ | ||
$configuration = [ | ||
'title' => $this->getTitle(), | ||
'description' => $this->getDescription(), | ||
'icon' => $this->icon, | ||
'wireframe' => $this->wireframe, | ||
'enabled' => $this->enabled, | ||
'tags' => $this->tags, | ||
'classes' => [ | ||
'ui_element' => $this->uiElement, | ||
], | ||
'templates' => [ | ||
'admin_render' => $this->getTemplates()->adminRender, | ||
'front_render' => $this->getTemplates()->frontRender, | ||
'admin_form' => $this->getTemplates()->adminForm, | ||
], | ||
'form_options' => [], | ||
]; | ||
|
||
if ($this->alias) { | ||
$configuration['alias'] = $this->alias; | ||
} | ||
|
||
return $configuration; | ||
} | ||
|
||
private function getTitle(): string | ||
{ | ||
return $this->title ?? 'app.ui_element.' . $this->getLastPartOfCode() . '.title'; | ||
} | ||
|
||
private function getDescription(): string | ||
{ | ||
return $this->description ?? 'app.ui_element.' . $this->getLastPartOfCode() . '.description'; | ||
} | ||
|
||
private function getTemplates(): TemplatesUiElement | ||
{ | ||
return $this->templates ?? new TemplatesUiElement( | ||
adminRender: 'Admin/UiElement/' . $this->getLastPartOfCode() . '.html.twig', | ||
frontRender: 'Shop/UiElement/' . $this->getLastPartOfCode() . '.html.twig', | ||
); | ||
} | ||
|
||
private function getLastPartOfCode(): string | ||
{ | ||
$parts = explode('.', $this->code); | ||
|
||
return end($parts); | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Monsieur Biz' Rich Editor plugin for Sylius. | ||
* | ||
* (c) Monsieur Biz <sylius@monsieurbiz.com> | ||
* | ||
* 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\SyliusRichEditorPlugin\Attribute; | ||
|
||
use Attribute; | ||
|
||
#[Attribute(Attribute::TARGET_PROPERTY)] | ||
final class TemplatesUiElement | ||
{ | ||
public function __construct( | ||
public string $adminRender, | ||
public string $frontRender, | ||
public string $adminForm = '@MonsieurBizSyliusRichEditorPlugin/Admin/form.html.twig', | ||
) { | ||
} | ||
} |
Oops, something went wrong.