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

Feature ibexa 3 #2

Open
wants to merge 6 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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The bundle provides a "step" field for the Form Builder in eZ Platform EE which
## Usage
This bundle provides a default (and very basic) template that uses Bootstrap 4 to create a carousel which is used for
step transitions, but you can use any solution you prefer. To do so, you will have to override the default template
(`EzPlatformFormBuilderMultiStepFormsBundle::form_steps.html.twig`).
(`@ezdesign/formbuilder_multistep/steps.html.twig`).

If Step Field is not the very first field used in the Form, fields before first Step Field will be rendered below the
carousel (in the default template). If there is no Step Field inside Form it will be rendered normally.
Expand Down
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
}
},
"require": {
"php": ">=7.1",
"ezsystems/ezpublish-kernel": "^7.5",
"ezsystems/ezplatform-form-builder": "^1.2"
"php": ">=7.4",
"ezsystems/ezplatform-form-builder": "^2.3"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "2.7.*",
"phpunit/phpunit": "~7.0"
"phpunit/phpunit": "^9.5",
"symfony/phpunit-bridge": "^6.0"
},
"scripts": {
"fix-cs": "@php ./vendor/bin/php-cs-fixer fix -v --show-progress=estimating"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function prepend(ContainerBuilder $container): void
}

/**
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
* @param ContainerBuilder $container
*/
private function prependFieldType(ContainerBuilder $container): void
{
Expand All @@ -48,14 +48,14 @@ private function prependFieldType(ContainerBuilder $container): void
}

/**
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
* @param ContainerBuilder $container
*/
private function prependTemplates(ContainerBuilder $container): void
{
$config = Yaml::parseFile(
__DIR__ . '/../Resources/config/ez_field_templates.yml'
);

$container->prependExtensionConfig('ezpublish', $config);
$container->prependExtensionConfig('ezplatform', $config);
}
}
7 changes: 3 additions & 4 deletions src/bundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ services:
autoconfigure: true
public: false

MateuszBieniek\EzPlatformFormBuilderMultiStepFormsBundle\Twig\:
resource: '../../Twig'

MateuszBieniek\EzPlatformFormBuilderMultiStepForms\FormBuilder\Field\Mapper\StepMapper:
arguments:
$fieldIdentifier: 'mb_step'
Expand All @@ -19,7 +22,3 @@ services:
decorates: EzSystems\EzPlatformFormBuilder\FieldType\Type
arguments: ['@MateuszBieniek\EzPlatformFormBuilderMultiStepForms\FieldType\EzForm\Type.inner']
public: true

MateuszBieniek\EzPlatformFormBuilderMultiStepFormsBundle\Twig\MultiStepExtension:
tags:
- { name: twig.extension }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "EzPublishCoreBundle::content_fields.html.twig" %}
{% extends "@EzPublishCore/content_fields.html.twig" %}

{% block ezform_field %}
{% set formValue = field.value.getForm() %}
Expand All @@ -7,11 +7,11 @@
{% set isMultiStep = field.value.isMultiStep() %}

{% apply spaceless %}
{% if not ez_is_field_empty(content, field) %}
{% if not ez_field_is_empty(content, field) %}
{% if isMultiStep %}
{{ form_start(form) }}
{% set steps = multistep_form(form) %}
{% include 'EzPlatformFormBuilderMultiStepFormsBundle::form_steps.html.twig' with {'form': form, 'steps': steps} %}
{% include '@ezdesign/formbuilder_multistep/steps.html.twig' with {'form': form, 'steps': steps} %}
{{ form_end(form) }}
{% else %}
{{ form(form) }}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{{ form_errors(form) }}
<div id="{{form.vars.name}}-carousel" class="carousel slide" data-ride="carousel" data-interval="false">
<div class="carousel-inner">
{% for step in steps %}
<div class="carousel-item{% if loop.first %} active{% endif %}{% if step.step_field.vars.attr["step_class"] is not empty %} {{ step.step_field.vars.attr["step_class"] }}{% endif %}">
{% if step.step_field.vars.attr["custom_template"] is not empty %}
{% include step.step_field.vars.attr["custom_template"] with { 'step': step } %}
{% else %}
{{ form_row(step.step_field) }}
{% for field in step.fields %}
{{ form_row(field) }}
{% endfor%}

{% if step.step_field.vars.attr["back_label"] is not empty %}
<button
data-target="#{{form.vars.name}}-carousel"
type="button"
class="btn btn-secondary back-step"
role="button"
data-slide="prev"
>
{{ step.step_field.vars.attr["back_label"] }}
</button>
{% endif %}
{% if step.step_field.vars.attr["next_label"] is not empty %}
<button
data-target="#{{form.vars.name}}-carousel"
type="button"
class="btn btn-primary next-step"
role="button"
data-slide="next"
>
{{ step.step_field.vars.attr["next_label"] }}
</button>
{% endif %}
{% endif %}
</div>
{% endfor %}
</div>
</div>
31 changes: 31 additions & 0 deletions src/bundle/Twig/AppExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace MateuszBieniek\EzPlatformFormBuilderMultiStepFormsBundle\Twig;

use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class AppExtension extends AbstractExtension
{
/**
* getFilters.
*
* @return array
*/
public function getFunctions()
{
return [
new TwigFunction('multistep_form', [AppRuntime::class, 'prepareMultistepForm']),
];
}

/**
* getName.
*
* @return string
*/
public function getName()
{
return 'multi_step_form_builder_twig_extensions';
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
<?php

declare(strict_types=1);

namespace MateuszBieniek\EzPlatformFormBuilderMultiStepFormsBundle\Twig;

use MateuszBieniek\EzPlatformFormBuilderMultiStepForms\Form\Type\StepFieldType;
use Symfony\Component\Form\FormView;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
use Twig\Extension\RuntimeExtensionInterface;

class MultiStepExtension extends AbstractExtension
class AppRuntime implements RuntimeExtensionInterface
{
public function getFunctions()
{
return [
new TwigFunction('multistep_form', [$this, 'prepareMultistepForm']),
];
}

public function prepareMultistepForm(FormView $form)
public function prepareMultistepForm(FormView $form): array
{
$steps = [];
$currentStep = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/FieldType/EzForm/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ public function getFieldTypeIdentifier()
/**
* {@inheritdoc}
*/
public function getName(ValueInterface $value)
public function getName(ValueInterface $value, FieldDefinition $fieldDefinition, string $languageCode): string
{
$this->decoratedType->getName($value);
return $this->decoratedType->getName($value, $fieldDefinition, $languageCode);
}

/**
Expand Down