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

Introduce NumberMinMaxFilterType and IntegerMinMaxFilterType #14320

Merged
merged 5 commits into from Jul 12, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions admin-dev/themes/new-theme/scss/components/_grid.scss
Expand Up @@ -85,6 +85,17 @@ table .column-filters td:last-child .grid-reset-button {

.grid {
table.grid-table {
thead {
tr {
td {
.min-field,
.max-field {
display: inline-block;
width: 60px;
}
}
}
}
tbody {
tr {
$tr: &;
Expand Down
@@ -0,0 +1,59 @@
<?php

namespace PrestaShopBundle\Form\Admin\Type;

use PrestaShopBundle\Translation\TranslatorAwareTrait;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* Defines the integer type two inputs of min and max value - designed to fit grid in grid filter.
*/
final class IntegerMinMaxFilterType extends AbstractType
{
use TranslatorAwareTrait;

/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'min_field_options' => [],
'max_field_options' => [],
]);

$resolver->setAllowedTypes('min_field_options', 'array');
$resolver->setAllowedTypes('max_field_options', 'array');
}

/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
if (!isset($options['min_field_options']['attr']['placeholder'])) {
$options['min_field_options']['attr']['placeholder'] = $this->trans('Min', [], 'Admin.Global');
}

if (!isset($options['max_field_options']['attr']['placeholder'])) {
$options['max_field_options']['attr']['placeholder'] = $this->trans('Max', [], 'Admin.Global');
}

if (!isset($options['min_field_options']['attr']['min'])) {
$options['min_field_options']['attr']['min'] = 0;
}

if (!isset($options['max_field_options']['attr']['min'])) {
$options['max_field_options']['attr']['min'] = 0;
}

$options['min_field_options']['attr']['step'] = 1;
$options['max_field_options']['attr']['step'] = 1;

$builder->add('min_field', IntegerType::class, $options['min_field_options']);
$builder->add('max_field', IntegerType::class, $options['max_field_options']);
}
}
48 changes: 48 additions & 0 deletions src/PrestaShopBundle/Form/Admin/Type/NumberMinMaxFilterType.php
@@ -0,0 +1,48 @@
<?php

namespace PrestaShopBundle\Form\Admin\Type;

use PrestaShopBundle\Translation\TranslatorAwareTrait;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* Defines the number type two inputs of min and max value - designed to fit grid in grid filter.
*/
final class NumberMinMaxFilterType extends AbstractType
{
use TranslatorAwareTrait;

/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'min_field_options' => [],
'max_field_options' => [],
]);

$resolver->setAllowedTypes('min_field_options', 'array');
$resolver->setAllowedTypes('max_field_options', 'array');
}

/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
if (!isset($options['min_field_options']['attr']['placeholder'])) {
$options['min_field_options']['attr']['placeholder'] = $this->trans('Min', [], 'Admin.Global');
}

if (!isset($options['max_field_options']['attr']['placeholder'])) {
$options['max_field_options']['attr']['placeholder'] = $this->trans('Max', [], 'Admin.Global');
}

$builder->add('min_field', NumberType::class, $options['min_field_options']);
$builder->add('max_field', NumberType::class, $options['max_field_options']);
}
}
Expand Up @@ -865,3 +865,19 @@ services:
- '@=service("prestashop.core.form.choice_provider.mail_themes").getChoices()'
tags:
- { name: form.type }

form.type.integer_min_max_filter:
class: 'PrestaShopBundle\Form\Admin\Type\IntegerMinMaxFilterType'
public: true
calls:
- { method: setTranslator, arguments: ['@translator'] }
tags:
- { name: form.type }

form.type.number_min_max_filter:
class: 'PrestaShopBundle\Form\Admin\Type\NumberMinMaxFilterType'
public: true
calls:
- { method: setTranslator, arguments: ['@translator'] }
tags:
- { name: form.type }
Expand Up @@ -780,3 +780,13 @@
</em>
</small>
{% endblock text_with_recommended_length_widget %}

{% block integer_min_max_filter_widget %}
{{ form_widget(form['min_field'], { attr: {class: 'min-field'}}) }}
{{ form_widget(form['max_field'], { attr: {class: 'max-field'}}) }}
{% endblock %}

{% block number_min_max_filter_widget %}
{{ form_widget(form['min_field'], { attr: {class: 'min-field'}}) }}
{{ form_widget(form['max_field'], { attr: {class: 'max-field'}}) }}
{% endblock %}