Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"phpstan/phpstan-doctrine": "^1.3.2",
"phpstan/phpstan-webmozart-assert": "^1.1",
"phpunit/phpunit": "^10.5",
"phpmd/phpmd": "^2.15"
"phpmd/phpmd": "^2.15",
"symfony/maker-bundle": "^1.65"
},
"suggest": {
"monsieurbiz/sylius-media-manager-plugin": "To use the media manager in the ui elements"
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ parameters:
- 'src/Maker/*.php'

ignoreErrors:
- identifier: missingType.generics
- identifier: missingType.iterableValue
1 change: 0 additions & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public function getConfigTreeBuilder(): TreeBuilder

private function addUiElements(ArrayNodeDefinition $rootNode): void
{
/** @phpstan-ignore-next-line */
$rootNode
->children()
->scalarNode('upload_directory')->end()
Expand Down
1 change: 0 additions & 1 deletion src/Fixture/FileFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public function getName(): string

protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void
{
/** @phpstan-ignore-next-line */
$optionsNode
->children()
->arrayNode('files')
Expand Down
20 changes: 10 additions & 10 deletions src/Form/Type/UiElement/ButtonLinkType.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,28 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
new Assert\NotBlank([]),
];
$constraintsLink = [
new Assert\AtLeastOneOf([
'includeInternalMessages' => false,
'message' => 'monsieurbiz_richeditor_plugin.not_valid_url',
'constraints' => [
new Assert\AtLeastOneOf(
constraints: [
new Assert\Url(['protocols' => ['http', 'https'], 'relativeProtocol' => true]),
new Assert\Regex(['pattern' => '`^(#|/|tel:|mailto:)`']),
],
]),
message: 'monsieurbiz_richeditor_plugin.not_valid_url',
includeInternalMessages: false
),
new Assert\NotBlank([]),
];
} else {
$constraintsLabel = [];
$constraintsLinkType = [];
$constraintsLink = [
new Assert\AtLeastOneOf([
'includeInternalMessages' => false,
'message' => 'monsieurbiz_richeditor_plugin.not_valid_url',
'constraints' => [
new Assert\AtLeastOneOf(
constraints: [
new Assert\Url(['protocols' => ['http', 'https'], 'relativeProtocol' => true]),
new Assert\Regex(['pattern' => '`^(#|/|tel:|mailto:)`']),
],
]),
message: 'monsieurbiz_richeditor_plugin.not_valid_url',
includeInternalMessages: false
),
];
}

Expand Down
10 changes: 5 additions & 5 deletions src/Form/Type/UiElement/ImageType.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ public function addFields(FormBuilderInterface $builder, array $options): void
'label' => 'monsieurbiz_richeditor_plugin.ui_element.monsieurbiz.image.field.link',
'help' => 'monsieurbiz_richeditor_plugin.ui_element.monsieurbiz.image.field.link_help',
'constraints' => [
new Assert\AtLeastOneOf([
'includeInternalMessages' => false,
'message' => 'monsieurbiz_richeditor_plugin.not_valid_url',
'constraints' => [
new Assert\AtLeastOneOf(
constraints: [
new Assert\Url(['protocols' => ['http', 'https'], 'relativeProtocol' => true]),
new Assert\Regex(['pattern' => '`^(#|/.*)$`']),
],
]),
message: 'monsieurbiz_richeditor_plugin.not_valid_url',
includeInternalMessages: false
),
],
])
->add('link_type', LinkTypeType::class, [
Expand Down
134 changes: 70 additions & 64 deletions src/Maker/UiElementMaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,77 +25,83 @@
use Symfony\Component\Form\AbstractType;
use Webmozart\Assert\Assert;

final class UiElementMaker extends AbstractMaker
{
public static function getCommandName(): string
if (class_exists(AbstractMaker::class)) {
final class UiElementMaker extends AbstractMaker
{
return 'make:ui-element';
}
public static function getCommandName(): string
{
return 'make:ui-element';
}

/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function configureCommand(Command $command, InputConfiguration $inputConfig): void
{
$command
->addArgument('code', InputArgument::OPTIONAL, 'The code of the UI Element (e.g. <fg=yellow>my_ui_element</>)')
->addArgument('icon', InputArgument::OPTIONAL, 'The semantic icon code for the UI Element (e.g. <fg=yellow>map pin</>)', 'square')
->addArgument('code_prefix', InputArgument::OPTIONAL, 'The code prefix for the UI Element (e.g. <fg=yellow>app</>)', 'app')
->setDescription('Creates a new UI Element FormType and templates')
;
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function configureCommand(Command $command, InputConfiguration $inputConfig): void
{
$command
->addArgument('code', InputArgument::OPTIONAL, 'The code of the UI Element (e.g. <fg=yellow>my_ui_element</>)')
->addArgument('icon', InputArgument::OPTIONAL, 'The semantic icon code for the UI Element (e.g. <fg=yellow>map pin</>)', 'square')
->addArgument('code_prefix', InputArgument::OPTIONAL, 'The code prefix for the UI Element (e.g. <fg=yellow>app</>)', 'app')
->setDescription('Creates a new UI Element FormType and templates')
;
}

public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator): void
{
$code = $input->getArgument('code');
$icon = $input->getArgument('icon');
$codePrefix = $input->getArgument('code_prefix');
Assert::string($code);
$name = Str::asCamelCase($code);
$uiElementFormClassNameDetails = $generator->createClassNameDetails(
$name,
'Form\\Type\\UiElement\\',
'Type'
);
$generator->generateClass(
$uiElementFormClassNameDetails->getFullName(),
__DIR__ . '/../Resources/skeleton/UiElementFormType.tpl.php',
[
'code' => \sprintf('%s.%s', $codePrefix, $code),
'icon' => $icon,
'tags' => json_encode([]),
]
);
public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator): void
{
$code = $input->getArgument('code');
$icon = $input->getArgument('icon');
$codePrefix = $input->getArgument('code_prefix');
Assert::string($code);
$name = Str::asCamelCase($code);
$uiElementFormClassNameDetails = $generator->createClassNameDetails(
$name,
'Form\\Type\\UiElement\\',
'Type'
);
$generator->generateClass(
$uiElementFormClassNameDetails->getFullName(),
__DIR__ . '/../Resources/skeleton/UiElementFormType.tpl.php',
[
'code' => \sprintf('%s.%s', $codePrefix, $code),
'icon' => $icon,
'tags' => json_encode([]),
]
);

// Generate templates
$generator->generateTemplate(
\sprintf('admin/ui_element/%s.html.twig', $code),
__DIR__ . '/../Resources/skeleton/UiElementTemplate.tpl.php',
[
'code' => $code,
]
);
$generator->generateTemplate(
\sprintf('shop/ui_element/%s.html.twig', $code),
__DIR__ . '/../Resources/skeleton/UiElementTemplate.tpl.php',
[
'code' => $code,
]
);
// Generate templates
$generator->generateTemplate(
\sprintf('admin/ui_element/%s.html.twig', $code),
__DIR__ . '/../Resources/skeleton/UiElementTemplate.tpl.php',
[
'code' => $code,
]
);
$generator->generateTemplate(
\sprintf('shop/ui_element/%s.html.twig', $code),
__DIR__ . '/../Resources/skeleton/UiElementTemplate.tpl.php',
[
'code' => $code,
]
);

$generator->writeChanges();
$generator->writeChanges();

$this->writeSuccessMessage($io);
$io->text([
'Next: Open your new UI Element FormType and templates, and start customizing it.',
]);
}
$this->writeSuccessMessage($io);
$io->text([
'Next: Open your new UI Element FormType and templates, and start customizing it.',
]);
}

public function configureDependencies(DependencyBuilder $dependencies): void
public function configureDependencies(DependencyBuilder $dependencies): void
{
$dependencies->addClassDependency(
AbstractType::class,
'monsieurbiz/sylius-rich-editor-plugin'
);
}
}
} else {
final class UiElementMaker
{
$dependencies->addClassDependency(
AbstractType::class,
'monsieurbiz/sylius-rich-editor-plugin'
);
}
}
4 changes: 4 additions & 0 deletions src/Twig/Components/UiElementForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,17 @@ protected function instantiateForm(): FormInterface
);
}

/**
* @deprecated
*/
#[LiveListener('media-manager:file-selected')]
public function mediaManagerFileSelected(
#[LiveArg]
string $inputName,
#[LiveArg]
string $filePath,
): void {
trigger_deprecation('monsieurbiz/sylius-rich-editor-plugin', '3.x', 'The "%s" method is deprecated and will be removed in a future version.', __METHOD__);
// Support any depth: e.g. menu_item[linkSettings][thumbnail] or menu_item[foo][bar][baz]
$inputNameParts = explode('[', str_replace(']', '', $inputName));
// Remove the first part (form name, e.g. menu_item)
Expand Down
Loading