From 63bbcae1a77a5740f56eaf49b9cc33897b6de071 Mon Sep 17 00:00:00 2001 From: Hannes Giesenow Date: Thu, 14 Dec 2023 13:26:42 +0100 Subject: [PATCH 1/4] Added fieldtype --- README.md | 25 ++++++++++++++ Resources/config/ezplatform.yaml | 5 +++ Resources/config/services.yaml | 13 +++++++ composer.json | 7 +++- .../ElbformatIconFieldtypeExtension.php | 31 +++++++++++++++++ src/ElbformatIconFieldtypeBundle.php | 11 ++++++ src/FieldType/Icon/Type.php | 34 +++++++++++++++++++ src/FieldType/Icon/Value.php | 23 +++++++++++++ src/Form/Type/IconType.php | 25 ++++++++++++++ templates/icon_field.html.twig | 6 ++++ 10 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 README.md create mode 100644 Resources/config/ezplatform.yaml create mode 100644 Resources/config/services.yaml create mode 100644 src/DependencyInjection/ElbformatIconFieldtypeExtension.php create mode 100644 src/ElbformatIconFieldtypeBundle.php create mode 100644 src/FieldType/Icon/Type.php create mode 100644 src/FieldType/Icon/Value.php create mode 100644 src/Form/Type/IconType.php create mode 100644 templates/icon_field.html.twig diff --git a/README.md b/README.md new file mode 100644 index 0000000..b65ce7a --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +# Ibexa Icon FieldType +This bundle provides a new field type "icon". +It allows an editor to select an icon from a predefined set of icons + +## Features +* Configure multiple icon sets +* Select the icon set at content-type edit level +* Select icon from a dropdown instead of text + +## Installation +1. Add the bundle +```shell +composer require elbformat/ibexa-icon-fieldtype +``` + +2. Activate the bundle +```php +Elbformat\IconFieldtypeBundle\IconFieldtypeBundle::class => ['all' => true], +``` + +3. Add iconset configuration +TBD. + +## Usage +Edit a content-type and add \ No newline at end of file diff --git a/Resources/config/ezplatform.yaml b/Resources/config/ezplatform.yaml new file mode 100644 index 0000000..c0bdfba --- /dev/null +++ b/Resources/config/ezplatform.yaml @@ -0,0 +1,5 @@ +ezplatform: + system: + default: + field_templates: + - { template: '@ElbformatIconFieldtype/icon_field.html.twig', priority: 0 } \ No newline at end of file diff --git a/Resources/config/services.yaml b/Resources/config/services.yaml new file mode 100644 index 0000000..f2cebec --- /dev/null +++ b/Resources/config/services.yaml @@ -0,0 +1,13 @@ +services: + Elbformat\IbexaIconFieldtype\FieldType\Icon\Type: + arguments: + $serializer: '@eZ\Publish\SPI\FieldType\ValueSerializerInterface' + $validator: '@Symfony\Component\Validator\Validator\ValidatorInterface' + tags: + - { name: ezplatform.field_type, alias: icon } + - { name: ezplatform.field_type.form_mapper.value, fieldType: icon } + + Elbformat\IbexaIconFieldtype\FieldType\Icon\SearchField: + class: '%ezpublish.fieldType.indexable.unindexed.class%' + tags: + - { name: ezplatform.field_type.indexable, alias: icon } \ No newline at end of file diff --git a/composer.json b/composer.json index 74e8767..ba5226b 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ } }, "require": { - "php": ">=8.1", + "php": "^8.1", "ezsystems/ezplatform-core": "^2.3" }, "require-dev": { @@ -36,5 +36,10 @@ "symfony/flex": true, "ibexa/post-install": true } + }, + "extra": { + "platform": { + "php": "8.1" + } } } diff --git a/src/DependencyInjection/ElbformatIconFieldtypeExtension.php b/src/DependencyInjection/ElbformatIconFieldtypeExtension.php new file mode 100644 index 0000000..a619232 --- /dev/null +++ b/src/DependencyInjection/ElbformatIconFieldtypeExtension.php @@ -0,0 +1,31 @@ +load('services.yaml'); + } + + public function prepend(ContainerBuilder $container) + { + // Add template for rendering + $configFile = __DIR__ . '/../../Resources/config/ezplatform.yaml'; + $config = Yaml::parse(file_get_contents($configFile)); + $container->prependExtensionConfig('ezpublish', $config['ezplatform']); + // register namespace (as this is not done automatically. Maybe the missing "bundle" in path?) + $container->prependExtensionConfig('twig', ['paths'=> [__DIR__.'/../../templates' => 'ElbformatIconFieldtype']]); + + } +} \ No newline at end of file diff --git a/src/ElbformatIconFieldtypeBundle.php b/src/ElbformatIconFieldtypeBundle.php new file mode 100644 index 0000000..91299f4 --- /dev/null +++ b/src/ElbformatIconFieldtypeBundle.php @@ -0,0 +1,11 @@ +fieldDefinition; + $fieldForm->add('value', IconType::class, [ + 'required' => $definition->isRequired, + 'label' => $definition->getName(), + ]); + } + + public function isSearchable(): bool + { + return false; + } +} \ No newline at end of file diff --git a/src/FieldType/Icon/Value.php b/src/FieldType/Icon/Value.php new file mode 100644 index 0000000..e34e04b --- /dev/null +++ b/src/FieldType/Icon/Value.php @@ -0,0 +1,23 @@ +icon = $icon; } + + public function __toString(): string + { + return $this->icon; + } + + public function getIcon(): ?string + { + return $this->icon; + } +} \ No newline at end of file diff --git a/src/Form/Type/IconType.php b/src/Form/Type/IconType.php new file mode 100644 index 0000000..64b2260 --- /dev/null +++ b/src/Form/Type/IconType.php @@ -0,0 +1,25 @@ +add('icon', ChoiceType::class); + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => Value::class, + ]); + } +} \ No newline at end of file diff --git a/templates/icon_field.html.twig b/templates/icon_field.html.twig new file mode 100644 index 0000000..d167e0f --- /dev/null +++ b/templates/icon_field.html.twig @@ -0,0 +1,6 @@ +{% block icon_field %} +{% if field.value.icon is not null %} + + +{% endif %} +{% endblock %} From 6ed29917ad084d636f55d2de1f6fc42c501ad72f Mon Sep 17 00:00:00 2001 From: Hannes Giesenow Date: Fri, 15 Dec 2023 16:12:47 +0100 Subject: [PATCH 2/4] Set configuration --- Resources/config/ezplatform.yaml | 5 -- Resources/config/services.yaml | 13 ----- composer.json | 3 +- config/ezplatform.yaml | 7 +++ config/services.yaml | 29 +++++++++++ src/DependencyInjection/Configuration.php | 32 ++++++++++++ .../ElbformatIconFieldtypeExtension.php | 19 +++++-- src/FieldType/Icon/Type.php | 23 +++++++-- src/FieldType/Icon/Value.php | 5 ++ src/Form/Type/IconSettingsType.php | 24 +++++++++ src/Form/Type/IconType.php | 13 ++++- src/IconSet/IconSet.php | 24 +++++++++ src/IconSet/IconSetManager.php | 51 +++++++++++++++++++ templates/icon.html.twig | 10 ++++ templates/icon_field.html.twig | 8 +-- .../icon_field_type_definition.html.twig | 7 +++ translations/fieldtypes.de.yaml | 1 + translations/fieldtypes.en.yaml | 1 + 18 files changed, 244 insertions(+), 31 deletions(-) delete mode 100644 Resources/config/ezplatform.yaml delete mode 100644 Resources/config/services.yaml create mode 100644 config/ezplatform.yaml create mode 100644 config/services.yaml create mode 100644 src/DependencyInjection/Configuration.php create mode 100644 src/Form/Type/IconSettingsType.php create mode 100644 src/IconSet/IconSet.php create mode 100644 src/IconSet/IconSetManager.php create mode 100644 templates/icon.html.twig create mode 100644 templates/icon_field_type_definition.html.twig create mode 100644 translations/fieldtypes.de.yaml create mode 100644 translations/fieldtypes.en.yaml diff --git a/Resources/config/ezplatform.yaml b/Resources/config/ezplatform.yaml deleted file mode 100644 index c0bdfba..0000000 --- a/Resources/config/ezplatform.yaml +++ /dev/null @@ -1,5 +0,0 @@ -ezplatform: - system: - default: - field_templates: - - { template: '@ElbformatIconFieldtype/icon_field.html.twig', priority: 0 } \ No newline at end of file diff --git a/Resources/config/services.yaml b/Resources/config/services.yaml deleted file mode 100644 index f2cebec..0000000 --- a/Resources/config/services.yaml +++ /dev/null @@ -1,13 +0,0 @@ -services: - Elbformat\IbexaIconFieldtype\FieldType\Icon\Type: - arguments: - $serializer: '@eZ\Publish\SPI\FieldType\ValueSerializerInterface' - $validator: '@Symfony\Component\Validator\Validator\ValidatorInterface' - tags: - - { name: ezplatform.field_type, alias: icon } - - { name: ezplatform.field_type.form_mapper.value, fieldType: icon } - - Elbformat\IbexaIconFieldtype\FieldType\Icon\SearchField: - class: '%ezpublish.fieldType.indexable.unindexed.class%' - tags: - - { name: ezplatform.field_type.indexable, alias: icon } \ No newline at end of file diff --git a/composer.json b/composer.json index ba5226b..205cadb 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,8 @@ }, "require": { "php": "^8.1", - "ezsystems/ezplatform-core": "^2.3" + "ezsystems/ezplatform-core": "^2.3", + "symfony/finder": "^5.4|^6.4" }, "require-dev": { "phpunit/phpunit": "^9.5" diff --git a/config/ezplatform.yaml b/config/ezplatform.yaml new file mode 100644 index 0000000..04f6406 --- /dev/null +++ b/config/ezplatform.yaml @@ -0,0 +1,7 @@ +ezplatform: + system: + default: + field_templates: + - { template: '@ElbformatIconFieldtype/icon_field.html.twig', priority: 0 } + fielddefinition_edit_templates: + - { template: '@ElbformatIconFieldtype/icon_field_type_definition.html.twig', priority: 0 } \ No newline at end of file diff --git a/config/services.yaml b/config/services.yaml new file mode 100644 index 0000000..16df04e --- /dev/null +++ b/config/services.yaml @@ -0,0 +1,29 @@ +services: + Elbformat\IbexaIconFieldtype\FieldType\Icon\Type: + arguments: + $serializer: '@eZ\Publish\SPI\FieldType\ValueSerializerInterface' + $validator: '@Symfony\Component\Validator\Validator\ValidatorInterface' + tags: + - { name: ezplatform.field_type, alias: icon } + - { name: ezplatform.field_type.form_mapper.value, fieldType: icon } + - { name: ezplatform.field_type.form_mapper.definition, fieldType: icon } + + Elbformat\IbexaIconFieldtype\FieldType\Icon\SearchField: + class: '%ezpublish.fieldType.indexable.unindexed.class%' + tags: + - { name: ezplatform.field_type.indexable, alias: icon } + + Elbformat\IbexaIconFieldtype\Form\Type\IconType: + arguments: + $iconSetManager: '@Elbformat\IbexaIconFieldtype\IconSet\IconSetManager' + tags: + - { name: form.type } + Elbformat\IbexaIconFieldtype\Form\Type\IconSettingsType: + arguments: + $iconSetManager: '@Elbformat\IbexaIconFieldtype\IconSet\IconSetManager' + tags: + - { name: form.type } + + Elbformat\IbexaIconFieldtype\IconSet\IconSetManager: + arguments: + $configs: [] # Will be set from bundle config diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php new file mode 100644 index 0000000..4d3fc6b --- /dev/null +++ b/src/DependencyInjection/Configuration.php @@ -0,0 +1,32 @@ +getRootNode() + ->arrayPrototype() // Name of the set + ->normalizeKeys(false) + ->children() + ->arrayNode('items') // Fix list + ->requiresAtLeastOneElement() + ->normalizeKeys(false) + ->scalarPrototype()->end() + ->end() + ->scalarNode('folder')->end() // Path to look in + ->scalarNode('pattern')->end() // Glob expression + ->end() + ->end() + ; + + return $treeBuilder; + } +} \ No newline at end of file diff --git a/src/DependencyInjection/ElbformatIconFieldtypeExtension.php b/src/DependencyInjection/ElbformatIconFieldtypeExtension.php index a619232..43a4c83 100644 --- a/src/DependencyInjection/ElbformatIconFieldtypeExtension.php +++ b/src/DependencyInjection/ElbformatIconFieldtypeExtension.php @@ -3,6 +3,7 @@ namespace Elbformat\IbexaIconFieldtype\DependencyInjection; +use Elbformat\IbexaIconFieldtype\IconSet\IconSetManager; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; @@ -14,18 +15,28 @@ class ElbformatIconFieldtypeExtension extends Extension implements PrependExtens { public function load(array $configs, ContainerBuilder $container) { - $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../../Resources/config/')); + $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../../config/')); $loader->load('services.yaml'); + + $configuration = new Configuration(); + $config = $this->processConfiguration($configuration, $configs); + + $definition = $container->getDefinition(IconSetManager::class); + $definition->setArgument('$configs', $config); } public function prepend(ContainerBuilder $container) { // Add template for rendering - $configFile = __DIR__ . '/../../Resources/config/ezplatform.yaml'; + $configFile = __DIR__.'/../../config/ezplatform.yaml'; $config = Yaml::parse(file_get_contents($configFile)); $container->prependExtensionConfig('ezpublish', $config['ezplatform']); - // register namespace (as this is not done automatically. Maybe the missing "bundle" in path?) - $container->prependExtensionConfig('twig', ['paths'=> [__DIR__.'/../../templates' => 'ElbformatIconFieldtype']]); + + // Register namespace (as this is not done automatically. Maybe the missing "bundle" in path?) + $container->prependExtensionConfig('twig', ['paths' => [__DIR__.'/../../templates' => 'ElbformatIconFieldtype']]); + + // Register translations (as this is not done automatically. Maybe the missing "bundle" in path?) + $container->prependExtensionConfig('framework', ['translator' => ['paths' => [__DIR__.'/../../translations']]]); } } \ No newline at end of file diff --git a/src/FieldType/Icon/Type.php b/src/FieldType/Icon/Type.php index 2649539..1291319 100644 --- a/src/FieldType/Icon/Type.php +++ b/src/FieldType/Icon/Type.php @@ -3,15 +3,18 @@ namespace Elbformat\IbexaIconFieldtype\FieldType\Icon; +use Elbformat\IbexaIconFieldtype\Form\Type\IconSettingsType; use Elbformat\IbexaIconFieldtype\Form\Type\IconType; use eZ\Publish\SPI\FieldType\Generic\Type as GenericType; use eZ\Publish\SPI\Persistence\Content\Field; use eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition; +use EzSystems\EzPlatformAdminUi\FieldType\FieldDefinitionFormMapperInterface; +use EzSystems\EzPlatformAdminUi\Form\Data\FieldDefinitionData; use EzSystems\EzPlatformContentForms\Data\Content\FieldData; use EzSystems\EzPlatformContentForms\FieldType\FieldValueFormMapperInterface; use Symfony\Component\Form\FormInterface; -final class Type extends GenericType implements FieldValueFormMapperInterface +final class Type extends GenericType implements FieldValueFormMapperInterface, FieldDefinitionFormMapperInterface { public function getFieldTypeIdentifier(): string { @@ -21,14 +24,28 @@ public function getFieldTypeIdentifier(): string public function mapFieldValueForm(FormInterface $fieldForm, FieldData $data) { $definition = $data->fieldDefinition; + $iconSet = $definition->getFieldSettings()['iconset']; $fieldForm->add('value', IconType::class, [ 'required' => $definition->isRequired, 'label' => $definition->getName(), + 'icon_set' => $iconSet, ]); } - public function isSearchable(): bool + public function getSettingsSchema(): array { - return false; + return [ + 'iconset' => [ + 'type' => 'string', + 'default' => '', + ], + ]; + } + + public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $data): void + { + $fieldDefinitionForm->add('fieldSettings', IconSettingsType::class, [ + 'label' => false, + ]); } } \ No newline at end of file diff --git a/src/FieldType/Icon/Value.php b/src/FieldType/Icon/Value.php index e34e04b..57bcfc3 100644 --- a/src/FieldType/Icon/Value.php +++ b/src/FieldType/Icon/Value.php @@ -20,4 +20,9 @@ public function getIcon(): ?string { return $this->icon; } + + public function setIcon(?string $icon): void + { + $this->icon = $icon; + } } \ No newline at end of file diff --git a/src/Form/Type/IconSettingsType.php b/src/Form/Type/IconSettingsType.php new file mode 100644 index 0000000..beae35f --- /dev/null +++ b/src/Form/Type/IconSettingsType.php @@ -0,0 +1,24 @@ +add('iconset', ChoiceType::class,[ + 'choices' => $this->iconSetManager->getSetList() + ]); + } +} \ No newline at end of file diff --git a/src/Form/Type/IconType.php b/src/Form/Type/IconType.php index 64b2260..8ad1655 100644 --- a/src/Form/Type/IconType.php +++ b/src/Form/Type/IconType.php @@ -4,6 +4,7 @@ namespace Elbformat\IbexaIconFieldtype\Form\Type; use Elbformat\IbexaIconFieldtype\FieldType\Icon\Value; +use Elbformat\IbexaIconFieldtype\IconSet\IconSetManager; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; @@ -11,15 +12,25 @@ final class IconType extends AbstractType { + public function __construct( + private readonly IconSetManager $iconSetManager, + ) { } + + public function buildForm(FormBuilderInterface $builder, array $options): void { - $builder->add('icon', ChoiceType::class); + $iconSet = $options['icon_set']; + $builder->add('icon', ChoiceType::class,[ + 'choices' => $this->iconSetManager->getSet($iconSet)->getList() + ]); } public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'data_class' => Value::class, + 'icon_set' => null, ]); + $resolver->addAllowedTypes('icon_set','string'); } } \ No newline at end of file diff --git a/src/IconSet/IconSet.php b/src/IconSet/IconSet.php new file mode 100644 index 0000000..ac36d5e --- /dev/null +++ b/src/IconSet/IconSet.php @@ -0,0 +1,24 @@ + */ + protected array $items; + + /** @param string[] */ + public function __construct(array $items) + { + // Convert to string => string array + $this->items = array_flip($items); + array_walk($this->items, fn(&$val, $key) => $val = $key); + } + + /** @return string[] */ + public function getList(): array + { + return $this->items; + } +} \ No newline at end of file diff --git a/src/IconSet/IconSetManager.php b/src/IconSet/IconSetManager.php new file mode 100644 index 0000000..fc62569 --- /dev/null +++ b/src/IconSet/IconSetManager.php @@ -0,0 +1,51 @@ + */ + protected array $sets; + + /** array $setConfig) { + $items = []; + if (null !== ($setConfig['items']??null)) { + $items = $setConfig['items']; + } + if (null !== ($setConfig['folder']??null)) { + $finder = (new Finder())->files()->in($setConfig['folder']); + if (null !== ($setConfig['pattern']??null)) { + $finder = $finder->name($setConfig['pattern']); + } + foreach ($finder as $file) { + $items[] = $file->getFilename(); + } + } + $this->sets[$setName] = new IconSet($items); + } + } + + public function getSet(string $name): IconSet + { + if (!isset($this->sets[$name])) { + throw new \InvalidArgumentException('IconSet not found'); + } + return $this->sets[$name]; + } + + /** @return array */ + public function getSetList():array + { + // Convert to string => string array + $sets = array_flip(array_keys($this->sets)); + array_walk($sets, fn(&$val, $key) => $val = $key); + return $sets; + } +} \ No newline at end of file diff --git a/templates/icon.html.twig b/templates/icon.html.twig new file mode 100644 index 0000000..1fe7b81 --- /dev/null +++ b/templates/icon.html.twig @@ -0,0 +1,10 @@ +{# + @var icon ?string + @var iconset string +#} +{% if icon is not null %} + + {% if "set2" == iconset %} + + {% endif %} +{% endif %} \ No newline at end of file diff --git a/templates/icon_field.html.twig b/templates/icon_field.html.twig index d167e0f..2611835 100644 --- a/templates/icon_field.html.twig +++ b/templates/icon_field.html.twig @@ -1,6 +1,6 @@ {% block icon_field %} -{% if field.value.icon is not null %} - - -{% endif %} + {{ include('@ElbformatIconFieldtype/icon.html.twig', { + icon: field.value.icon, + iconset: fieldSettings.iconset + }, with_context=false) }} {% endblock %} diff --git a/templates/icon_field_type_definition.html.twig b/templates/icon_field_type_definition.html.twig new file mode 100644 index 0000000..6998a59 --- /dev/null +++ b/templates/icon_field_type_definition.html.twig @@ -0,0 +1,7 @@ +{% block icon_field_definition_edit %} +
+ {{- form_label(form.fieldSettings.iconset) -}} + {{- form_errors(form.fieldSettings.iconset) -}} + {{- form_widget(form.fieldSettings.iconset) -}} +
+{% endblock %} \ No newline at end of file diff --git a/translations/fieldtypes.de.yaml b/translations/fieldtypes.de.yaml new file mode 100644 index 0000000..753bd10 --- /dev/null +++ b/translations/fieldtypes.de.yaml @@ -0,0 +1 @@ +icon.name: Symbol \ No newline at end of file diff --git a/translations/fieldtypes.en.yaml b/translations/fieldtypes.en.yaml new file mode 100644 index 0000000..5ae7326 --- /dev/null +++ b/translations/fieldtypes.en.yaml @@ -0,0 +1 @@ +icon.name: Icon \ No newline at end of file From a6025a8e2e6980596030b667982cd3db5100dc63 Mon Sep 17 00:00:00 2001 From: Hannes Giesenow Date: Fri, 15 Dec 2023 16:31:57 +0100 Subject: [PATCH 3/4] Abstracted icon template --- templates/icon.html.twig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/icon.html.twig b/templates/icon.html.twig index 1fe7b81..8189c42 100644 --- a/templates/icon.html.twig +++ b/templates/icon.html.twig @@ -1,4 +1,6 @@ {# + Use this template to render a single icon (for backend and frontend) + @var icon ?string @var iconset string #} From 0e8eeaa9637eb923300a150d83a52008c5815818 Mon Sep 17 00:00:00 2001 From: Hannes Giesenow Date: Fri, 15 Dec 2023 16:55:43 +0100 Subject: [PATCH 4/4] Renaming --- README.md | 24 +++++++++++++------ composer.json | 7 +++--- doc/configuration.md | 24 +++++++++++++++++++ src/DependencyInjection/Configuration.php | 6 ++--- ...tension.php => ElbformatIconExtension.php} | 10 ++++---- src/ElbformatIconBundle.php | 11 +++++++++ src/ElbformatIconFieldtypeBundle.php | 11 --------- src/FieldType/Icon/Type.php | 10 ++++---- src/FieldType/Icon/Value.php | 2 +- src/Form/Type/IconSettingsType.php | 5 ++-- src/Form/Type/IconType.php | 6 ++--- src/IconSet/IconSet.php | 2 +- src/IconSet/IconSetManager.php | 3 +-- 13 files changed, 76 insertions(+), 45 deletions(-) create mode 100644 doc/configuration.md rename src/DependencyInjection/{ElbformatIconFieldtypeExtension.php => ElbformatIconExtension.php} (85%) create mode 100644 src/ElbformatIconBundle.php delete mode 100644 src/ElbformatIconFieldtypeBundle.php diff --git a/README.md b/README.md index b65ce7a..3788c91 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,35 @@ -# Ibexa Icon FieldType +# Ibexa Icon Fieldtype This bundle provides a new field type "icon". It allows an editor to select an icon from a predefined set of icons ## Features -* Configure multiple icon sets -* Select the icon set at content-type edit level +* Configure multiple icon-sets +* Select the icon-set at content-type edit level * Select icon from a dropdown instead of text ## Installation 1. Add the bundle ```shell -composer require elbformat/ibexa-icon-fieldtype +composer require elbformat/icon-bundle ``` 2. Activate the bundle ```php -Elbformat\IconFieldtypeBundle\IconFieldtypeBundle::class => ['all' => true], +Elbformat\IconBundle\ElbformatIconBundle::class => ['all' => true], ``` 3. Add iconset configuration -TBD. +Add `config/packages/elbformat_icon.yaml` +```yaml +elbformat_icon: + iconset1: + - clock + - house + iconset2: + folder: "vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/public/img/icons" +``` +See [configuration](doc/configuration.md) for more advanced examples ## Usage -Edit a content-type and add \ No newline at end of file +Edit a content-type and add an "Icon" field. Select icon-set to use. +When editing the content, a dropdown with icons will be shown. \ No newline at end of file diff --git a/composer.json b/composer.json index 205cadb..e75fb77 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { - "name": "elbformat/ibexa-icon-fieldtype", - "description": "Field type to select an icon from a predefined set.", + "name": "elbformat/icon-bundle", + "description": "Ibexa fieldtype to select an icon from a predefined set.", "type": "symfony-bundle", "license": "MIT", "keywords": [ @@ -17,12 +17,13 @@ ], "autoload": { "psr-4": { - "Elbformat\\IbexaIconFieldtype\\": "src/" + "Elbformat\\IconBundle\\": "src/" } }, "require": { "php": "^8.1", "ezsystems/ezplatform-core": "^2.3", + "ezsystems/ezplatform-admin-ui": "^2.3", "symfony/finder": "^5.4|^6.4" }, "require-dev": { diff --git a/doc/configuration.md b/doc/configuration.md new file mode 100644 index 0000000..1bc740e --- /dev/null +++ b/doc/configuration.md @@ -0,0 +1,24 @@ +# Configuration + +To configure your icon sets, there are two options: +1. Fixed sets of icon names +2. A list of icons derived from a filesystem folder + +## Fixed set +To configure a fixed set of icons (e.g. "myicons"), use the following config syntax +```yaml +elbformat_icon: + myicons: + - clock + - house +``` + +## From filesystem +You can specify a folder that is being scanned for files. Optionally you can add a pattern to ignore non-icon files. +This example will look into the public/assets/build/images/icons folder and scans for svg files. +```yaml +elbformat_icon: + myiconsfromfolder: + folder: '%webroot_dir%/assets/build/images/icons' + pattern: '*.svg' +``` diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 4d3fc6b..54a14eb 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -1,16 +1,16 @@ getRootNode() ->arrayPrototype() // Name of the set diff --git a/src/DependencyInjection/ElbformatIconFieldtypeExtension.php b/src/DependencyInjection/ElbformatIconExtension.php similarity index 85% rename from src/DependencyInjection/ElbformatIconFieldtypeExtension.php rename to src/DependencyInjection/ElbformatIconExtension.php index 43a4c83..5c4af52 100644 --- a/src/DependencyInjection/ElbformatIconFieldtypeExtension.php +++ b/src/DependencyInjection/ElbformatIconExtension.php @@ -1,9 +1,9 @@ load('services.yaml'); @@ -25,7 +25,7 @@ public function load(array $configs, ContainerBuilder $container) $definition->setArgument('$configs', $config); } - public function prepend(ContainerBuilder $container) + public function prepend(ContainerBuilder $container): void { // Add template for rendering $configFile = __DIR__.'/../../config/ezplatform.yaml'; diff --git a/src/ElbformatIconBundle.php b/src/ElbformatIconBundle.php new file mode 100644 index 0000000..1382191 --- /dev/null +++ b/src/ElbformatIconBundle.php @@ -0,0 +1,11 @@ +fieldDefinition; $iconSet = $definition->getFieldSettings()['iconset']; diff --git a/src/FieldType/Icon/Value.php b/src/FieldType/Icon/Value.php index 57bcfc3..d140df8 100644 --- a/src/FieldType/Icon/Value.php +++ b/src/FieldType/Icon/Value.php @@ -1,7 +1,7 @@