fix file block type
This commit is contained in:
parent
a715f7e474
commit
17974843d9
|
@ -5,6 +5,8 @@ namespace App\Core\Form\Site\Page;
|
|||
use App\Core\Entity\Site\Page\FileBlock;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FileType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class FileBlockType extends TextBlockType
|
||||
|
@ -21,11 +23,21 @@ class FileBlockType extends TextBlockType
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
{
|
||||
$view->vars = array_replace($view->vars, [
|
||||
'is_image' => $options['is_image'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => FileBlock::class,
|
||||
'block_prefix' => 'file_block',
|
||||
'is_image' => false,
|
||||
'options' => [],
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace App\Core\Form\Site\Page;
|
|||
|
||||
use Symfony\Component\Form\Extension\Core\Type\FileType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Validator\Constraints\Image;
|
||||
|
||||
class ImageBlockType extends FileBlockType
|
||||
|
@ -22,4 +23,11 @@ class ImageBlockType extends FileBlockType
|
|||
], $options['options']),
|
||||
);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
parent::configureOptions($resolver);
|
||||
|
||||
$resolver->setDefault('is_image', true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,9 +11,10 @@
|
|||
<div class="row">
|
||||
<div class="col-12">
|
||||
{% set value = form.vars.data %}
|
||||
{% set isImage = form.parent.vars.is_image is defined and form.parent.vars.is_image %}
|
||||
|
||||
{% if value %}
|
||||
{% if value and value.extension in ['jpeg', 'jpg', 'gif', 'png', 'svg'] %}
|
||||
{% if isImage and value and value.extension in ['jpeg', 'jpg', 'gif', 'png', 'svg'] %}
|
||||
<div class="card">
|
||||
<div class="card-img-top bg-tiles text-center">
|
||||
<a href="{{ asset(value.pathname) }}" target="_blank">
|
||||
|
|
Loading…
Reference in a new issue