-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hannes Giesenow
committed
Dec 15, 2023
1 parent
63bbcae
commit 6ed2991
Showing
18 changed files
with
244 additions
and
31 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,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 } |
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,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 |
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,32 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Elbformat\IbexaIconFieldtype\DependencyInjection; | ||
|
||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
class Configuration implements ConfigurationInterface | ||
{ | ||
public function getConfigTreeBuilder() | ||
{ | ||
$treeBuilder = new TreeBuilder('elbformat_icon_fieldtype'); | ||
|
||
$treeBuilder->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; | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Elbformat\IbexaIconFieldtype\Form\Type; | ||
|
||
use Elbformat\IbexaIconFieldtype\IconSet\IconSetManager; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||
use Symfony\Component\Form\Extension\Core\Type\TextType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
|
||
final class IconSettingsType extends AbstractType | ||
{ | ||
public function __construct( | ||
private readonly IconSetManager $iconSetManager, | ||
) { } | ||
|
||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
$builder->add('iconset', ChoiceType::class,[ | ||
'choices' => $this->iconSetManager->getSetList() | ||
]); | ||
} | ||
} |
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 | ||
declare(strict_types=1); | ||
|
||
namespace Elbformat\IbexaIconFieldtype\IconSet; | ||
|
||
class IconSet | ||
{ | ||
/** @var array<string,string> */ | ||
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; | ||
} | ||
} |
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,51 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Elbformat\IbexaIconFieldtype\IconSet; | ||
|
||
use Symfony\Component\Filesystem\Filesystem; | ||
use Symfony\Component\Finder\Finder; | ||
|
||
class IconSetManager | ||
{ | ||
/** @var array<string,IconSet> */ | ||
protected array $sets; | ||
|
||
/** array<string,array{?items:string[],?folder:string,?pattern:string} */ | ||
public function __construct(array $configs) | ||
{ | ||
foreach ($configs as $setName => $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<string,string> */ | ||
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; | ||
} | ||
} |
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 @@ | ||
{# | ||
@var icon ?string | ||
@var iconset string | ||
#} | ||
{% if icon is not null %} | ||
<i class="icon-{{ icon }}"></i> | ||
{% if "set2" == iconset %} | ||
<img src="assets/build/images/icons/{{ icon }}" /> | ||
{% endif %} | ||
{% endif %} |
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,6 +1,6 @@ | ||
{% block icon_field %} | ||
{% if field.value.icon is not null %} | ||
<i class="icon-{{ field.value.icon }}"></i> | ||
<img src="{{ field.value.icon }}.svg" /> | ||
{% endif %} | ||
{{ include('@ElbformatIconFieldtype/icon.html.twig', { | ||
icon: field.value.icon, | ||
iconset: fieldSettings.iconset | ||
}, with_context=false) }} | ||
{% endblock %} |
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,7 @@ | ||
{% block icon_field_definition_edit %} | ||
<div class="{% if group_class is not empty %}{{ group_class }}{% endif %}"> | ||
{{- form_label(form.fieldSettings.iconset) -}} | ||
{{- form_errors(form.fieldSettings.iconset) -}} | ||
{{- form_widget(form.fieldSettings.iconset) -}} | ||
</div> | ||
{% endblock %} |
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 @@ | ||
icon.name: Symbol |
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 @@ | ||
icon.name: Icon |