gpt4 book ai didi

javascript - SonataMediaBundle : a way to remove unlink thickbox

转载 作者:行者123 更新时间:2023-12-03 16:53:36 27 4
gpt4 key购买 nike

所以我想从 SonataMediaBundle 的形式中删除“Unlink”thickbox 和“Binary content”:

enter image description here

我在谷歌上什么也没找到。我应该使用 Javascript 来隐藏它们吗?

最佳答案

取消链接

我扩展了媒体类型表单,使取消链接复选框成为可选的(基于 abadius 的回答):

# src/MyNamespace/AppBundle/Form/Extension/MediaTypeExtension.php

namespace MyNamespace\AppBundle\Form\Extension;

use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\FormBuilderInterface;

class MediaTypeExtension extends AbstractTypeExtension
{
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'show_unlink' => true,
));
}

/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
if (!$options['show_unlink']) {
$builder->add('unlink', 'hidden', array(
'mapped' => false,
'data' => false,
'required' => false,
));
}
}

/**
* {@inheritdoc}
*/
public function getExtendedType()
{
return 'sonata_media_type';
}
}

将其添加为表单扩展服务:

# Bundle config

mynamespace.form.type_extension.media:
class: MyNamespace\AppBundle\Form\Extension\MediaTypeExtension
tags:
-
name: form.type_extension
alias: sonata_media_type

二进制内容

这里您需要覆盖文件提供程序以更改或删除标签(source):

# src/Application/Sonata/MediaBundle/Provider/FileProvider.php

namespace Application\Sonata\MediaBundle\Provider;

use Sonata\MediaBundle\Provider\FileProvider as BaseFileProvider;
use Symfony\Component\Form\FormBuilder;

class FileProvider extends BaseFileProvider
{
/**
* {@inheritdoc}
*/
public function buildMediaType(FormBuilder $formBuilder)
{
$formBuilder->add('binaryContent', 'file', array(
'label' => false,
));
}
}

并覆盖应用配置中的参数:

# app/config/config.yml

parameters:
sonata.media.provider.file.class: Application\Sonata\MediaBundle\Provider\FileProvider

关于javascript - SonataMediaBundle : a way to remove unlink thickbox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25386431/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com