src/Application/Sonata/MediaBundle/Provider/LinkProvider.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Application\Sonata\MediaBundle\Provider;
  3. use Sonata\AdminBundle\Form\FormMapper;
  4. use Sonata\MediaBundle\Form\Type\MediaType;
  5. use Sonata\MediaBundle\Provider\ImageProvider as BaseImageProvider;
  6. use Sonata\MediaBundle\Provider\Metadata;
  7. use Symfony\Component\Form\Extension\Core\Type\FileType;
  8. use Symfony\Component\Form\Extension\Core\Type\TextType;
  9. use Symfony\Component\Form\FormBuilder;
  10. use Symfony\Component\Validator\Constraints\NotBlank;
  11. use Symfony\Component\Validator\Constraints\NotNull;
  12. class LinkProvider extends BaseImageProvider
  13. {
  14.     public function getProviderMetadata()
  15.     {
  16.         return new Metadata($this->getName(),
  17.             $this->getName().'.description',
  18.             null,
  19.             'SonataMediaBundle',
  20.             ['class' => 'fa fa-link']
  21.         );
  22.     }
  23.     public function buildEditForm(FormMapper $formMapper)
  24.     {
  25.         $formMapper->add('name');
  26.         $formMapper->add('enabled'null, ['required' => false]);
  27.         $formMapper->add('authorName');
  28.         $formMapper->add('cdnIsFlushable');
  29.         $formMapper->add('description');
  30.         $formMapper->add('copyright');
  31.         $formMapper->add('binaryContent'TextType::class, ['required' => false]);
  32.     }
  33.     public function buildCreateForm(FormMapper $formMapper)
  34.     {
  35.         $formMapper
  36.             ->add('binaryContent'TextType::class, [
  37.                 'constraints' => [
  38.                     new NotBlank(),
  39.                     new NotNull(),
  40.                 ],
  41.                 'label' => 'URL',
  42.             ]);
  43.     }
  44.     public function buildMediaType(FormBuilder $formBuilder)
  45.     {
  46.         $formBuilder->add('binaryContent'TextType::class, [
  47.             'label' => 'widget_label_binary_content',
  48.         ]);
  49.     }
  50. }