Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ibexa field types #181

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .ddev/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ web_environment:
- PANTHER_CHROME_ARGUMENTS='--disable-dev-shm-usage --ignore-certificate-errors'
- PANTHER_NO_SANDBOX=1
- PANTHER_NO_HEADLESS=0
nodejs_version: "16"
nodejs_version: "18"
webimage_extra_packages:
- pngquant
- jpegoptim
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Please comply with `make codeclean` and `make tests` before to push, your PR won
| [SolrSearchExtraBundle](https://github.com/Novactive/NovaeZSolrSearchExtraBundle): Solr search handler additions. It adds many things, binary file plain text content indexation, fullText criterion, custom field configuration, exact matches boosting configuration, etc. | ![eZ-Platform-2.x-OK] ![eZ-Platform-3.x-UNSURE] ![Ibexa-3.3.x-UNSURE] | ![MIT] |
| [StaticTemplatesBundle](https://github.com/Novactive/NovaeZStaticTemplatesBundle): Render twig templates via their paths through the design engine mechanism. Simple and perfect tiny bundle to build your Front-end first using Twig. | ![eZ-Platform-2.x-OK] ![eZ-Platform-3.x-OK] ![Ibexa-3.3.x-OK] ![Ibexa-4.x-OK] | ![MIT] |
| [TranslationUiBundle](https://github.com/Novactive/AlmaviaCXIbexaTranslationUiBundle): This bundle allows to import translation files content into the database and provide a GUI to edit translations. | ![Ibexa-4.x-OK] | ![MIT] |
| [SélectionFieldType](https://github.com/Novactive/Ibexa-FieldTypes): Enhanced Ibexa sélection type for Ibexa: possibility to add configure selection option by yaml. | ![Ibexa-4.x-OK] | ![MIT] |

## For Maintainers

Expand Down
50 changes: 50 additions & 0 deletions components/IbexaFieldTypes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
## AlmaviaCX Ibexa FieldTypes
This bundle add some field types to ibexa

## Installation
```bash
composer require almaviacx/ibexa-field-types
```

update `config/bundles.php` file by adding this:

```php
AlmaviaCX\Ibexa\Bundle\FieldTypes\AlmaviaCXFieldTypesBundle::class => ['all' => true],,
```

## Configuration

### ACX selection fieldType

#### selection choices configuration
create a configuration `config/packages/acx_field_types.yaml` with the following
```yaml
acx_field_types:
system:
default: # or global or siteaccess GROUP
acx_selection:
my_selection_choices: # value of choices_entry in fiedltypes settings
# Label: value
"atlicon-grid": atlicon-grid
atlicon-industry: atlicon-industry
atlicon-people-simple: atlicon-people-simple
atlicon-gears: atlicon-gears
```
#### template to render `my_selection_choices` field value
create a template accessible throught: `@ibexadesign/fields/acxselection/my_custom_choices.html.twig`
#### edit (or create) the content_type
- add a field of type almaviacx selection
- fieldSettings:
- Choices entry: `my_selection_choices`
- template: `my_custom_choices`
- check single / multiple selection

update the template to your needs:
example for atlicon to diplay icon
`@ibexadesign/fields/acxselection/my_custom_choices.html.twig` content can be:
```twig
{% set selected_value = field.value.getSelection() %}
{% if selected_value is not empty %}
<span class='atlicon {{ selected_value }}" aria-hidden="true"/>
{% endif %}
```
20 changes: 20 additions & 0 deletions components/IbexaFieldTypes/bundle/AlmaviaCXFieldTypesBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace AlmaviaCX\Ibexa\Bundle\FieldTypes;

use AlmaviaCX\Ibexa\Bundle\FieldTypes\DependencyInjection\AlmaviaCXFieldTypesExtension;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class AlmaviaCXFieldTypesBundle extends Bundle
{
public function getContainerExtension()
{
if (null === $this->extension) {
$this->extension = new AlmaviaCXFieldTypesExtension();
}

return $this->extension;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace AlmaviaCX\Ibexa\Bundle\FieldTypes\DependencyInjection;

use Ibexa\Bundle\Core\DependencyInjection\Configuration\SiteAccessAware\ConfigurationProcessor;
use Ibexa\Bundle\Core\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Yaml\Yaml;

final class AlmaviaCXFieldTypesExtension extends Extension implements PrependExtensionInterface
{
public function getAlias(): string
{
return Configuration::CONFIG_RESOLVER_NAMESPACE;
}

public function load(array $configs, ContainerBuilder $container): void
{
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);

$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('default_settings.yaml');
$processor = new ConfigurationProcessor($container, Configuration::CONFIG_RESOLVER_NAMESPACE);
$processor->mapConfigArray('acx_selection', $config, ContextualizerInterface::MERGE_FROM_SECOND_LEVEL);

$loader->load('services.yaml');
}

public function prepend(ContainerBuilder $container): void
{
$configFile = __DIR__.'/../Resources/config/field_types_templates.yaml';
$container->prependExtensionConfig('ibexa', Yaml::parse(file_get_contents($configFile)));
$container->addResource(new FileResource($configFile));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace AlmaviaCX\Ibexa\Bundle\FieldTypes\DependencyInjection;

use Ibexa\Bundle\Core\DependencyInjection\Configuration\SiteAccessAware\Configuration as SAConfiguration;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;

class Configuration extends SAConfiguration
{
public const CONFIG_RESOLVER_NAMESPACE = 'acx_field_types';

public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder(self::CONFIG_RESOLVER_NAMESPACE);

$rootNode = $treeBuilder->getRootNode();

$this->generateScopeBaseNode($rootNode)
->arrayNode('acx_selection')->info('Choices entries')
->prototype('array')
->useAttributeAsKey('name')
->prototype('variable')->end()
->end()
->end()
;

return $treeBuilder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace AlmaviaCX\Ibexa\Bundle\FieldTypes\FieldType\AcxSelection\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;

class AcxSelectionSettingsType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add(
'isMultiple',
CheckboxType::class,
[
'required' => false,
'label' => 'Multiple',
]
);
$builder->add('choices_entry', TextType::class);
$builder->add('template', TextType::class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace AlmaviaCX\Ibexa\Bundle\FieldTypes\FieldType\AcxSelection\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class AcxSelectionType extends AbstractType
{
public function getBlockPrefix(): string
{
return 'ibexa_fieldtype_acxselection';
}

public function getName(): string
{
return $this->getBlockPrefix();
}

public function getParent(): string
{
return ChoiceType::class;
}

public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->addModelTransformer(new FieldValueTransformer($options['multiple']));
}

public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'expanded' => false,
'required' => true,
'multiple' => false,
'choices' => [],
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace AlmaviaCX\Ibexa\Bundle\FieldTypes\FieldType\AcxSelection\Form;

use AlmaviaCX\Ibexa\Bundle\FieldTypes\FieldType\AcxSelection\Value;
use Symfony\Component\Form\DataTransformerInterface;

final class FieldValueTransformer implements DataTransformerInterface
{
public function __construct(protected bool $isMultiple = false)
{
}

public function transform($value)
{
if (!$value instanceof Value) {
return null;
}
$selection = (array) ($value->selection ?? []);

return true === $this->isMultiple ? $selection : ($selection[0] ?? null);
}

public function reverseTransform($value): ?Value
{
$value = (array) $value;

return new Value(false === $this->isMultiple ? [reset($value)] : $value);
}
}
Loading
Loading