<?php
namespace App\Application\Sonata\MediaBundle\Provider;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\MediaBundle\Form\Type\MediaType;
use Sonata\MediaBundle\Provider\ImageProvider as BaseImageProvider;
use Sonata\MediaBundle\Provider\Metadata;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\NotNull;
class LinkProvider extends BaseImageProvider
{
public function getProviderMetadata()
{
return new Metadata($this->getName(),
$this->getName().'.description',
null,
'SonataMediaBundle',
['class' => 'fa fa-link']
);
}
public function buildEditForm(FormMapper $formMapper)
{
$formMapper->add('name');
$formMapper->add('enabled', null, ['required' => false]);
$formMapper->add('authorName');
$formMapper->add('cdnIsFlushable');
$formMapper->add('description');
$formMapper->add('copyright');
$formMapper->add('binaryContent', TextType::class, ['required' => false]);
}
public function buildCreateForm(FormMapper $formMapper)
{
$formMapper
->add('binaryContent', TextType::class, [
'constraints' => [
new NotBlank(),
new NotNull(),
],
'label' => 'URL',
]);
}
public function buildMediaType(FormBuilder $formBuilder)
{
$formBuilder->add('binaryContent', TextType::class, [
'label' => 'widget_label_binary_content',
]);
}
}