我正在使用Oro平台和AccountBundle(OroCRM)。
我想删除(隐藏)社交字段,并自定义我的位置的地址(隐藏不必要的字段)。我怎样才能做到这一点?在代码中编辑什么?自定义字段(在ui中创建)可以自由编辑。问题出在系统领域。
我可以编辑视图(twig.html)吗?还有另外一种方法吗?什么是好的做法?
UserBundle /形式/类型/ UserType.php
<?php
namespace Oro\Bundle\UserBundle\Form\Type;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Oro\Bundle\FormBundle\Form\Type\OroBirthdayType;
use Oro\Bundle\SecurityBundle\SecurityFacade;
use Oro\Bundle\UserBundle\Entity\User;
use Oro\Bundle\UserBundle\Form\EventListener\UserSubscriber;
use Oro\Bundle\UserBundle\Form\Provider\PasswordFieldOptionsProvider;
class UserType extends AbstractType
{
/** @var SecurityContextInterface */
protected $security;
/** @var SecurityFacade */
protected $securityFacade;
/** @var bool */
protected $isMyProfilePage;
/** @var PasswordFieldOptionsProvider */
protected $optionsProvider;
/**
* @param SecurityContextInterface $security Security context
* @param SecurityFacade $securityFacade
* @param Request $request Request
* @param PasswordFieldOptionsProvider $optionsProvider
*/
public function __construct(
SecurityContextInterface $security,
SecurityFacade $securityFacade,
Request $request,
PasswordFieldOptionsProvider $optionsProvider
) {
$this->security = $security;
$this->securityFacade = $securityFacade;
$this->isMyProfilePage = $request->attributes->get('_route') === 'oro_user_profile_update';
$this->optionsProvider = $optionsProvider;
}
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$this->addEntityFields($builder);
}
/**
* {@inheritdoc}
*/
public function addEntityFields(FormBuilderInterface $builder)
{
// user fields
$builder->addEventSubscriber(new UserSubscriber($builder->getFormFactory(), $this->security));
$this->setDefaultUserFields($builder);
if ($this->securityFacade->isGranted('oro_user_role_view')) {
$builder->add(
'roles',
'entity',
[
'property_path' => 'rolesCollection',
'label' => 'oro.user.roles.label',
'class' => 'OroUserBundle:Role',
'property' => 'label',
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('r')
->where('r.role <> :anon')
->setParameter('anon', User::ROLE_ANONYMOUS)
->orderBy('r.label');
},
'multiple' => true,
'expanded' => true,
'required' => !$this->isMyProfilePage,
'read_only' => $this->isMyProfilePage,
'disabled' => $this->isMyProfilePage,
'translatable_options' => false
]
);
}
if ($this->securityFacade->isGranted('oro_user_group_view')) {
$builder->add(
'groups',
'entity',
[
'label' => 'oro.user.groups.label',
'class' => 'OroUserBundle:Group',
'property' => 'name',
'multiple' => true,
'expanded' => true,
'required' => false,
'read_only' => $this->isMyProfilePage,
'disabled' => $this->isMyProfilePage,
'translatable_options' => false
]
);
}
$this->addOrganizationField($builder);
$builder
->add(
'plainPassword',
'repeated',
[
'invalid_message' => 'oro.user.message.password_mismatch',
'type' => 'password',
'required' => true,
'first_options' => [
'label' => 'oro.user.password.label',
'tooltip' => $this->optionsProvider->getTooltip(),
'attr' => [
'data-validation' => $this->optionsProvider->getDataValidationOption()
]
],
'second_options' => [
'label' => 'oro.user.password_re.label',
],
]
)
->add(
'emails',
'collection',
[
'label' => 'oro.user.emails.label',
'type' => 'oro_user_email',
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'prototype' => true,
'prototype_name' => 'tag__name__'
]
)
->add('change_password', ChangePasswordType::NAME)
->add('avatar', 'oro_image', ['label' => 'oro.user.avatar.label', 'required' => false]);
$this->addInviteUserField($builder);
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
[
'data_class' => 'Oro\Bundle\UserBundle\Entity\User',
'intention' => 'user',
'validation_groups' => function ($form) {
if ($form instanceof FormInterface) {
$user = $form->getData();
} elseif ($form instanceof FormView) {
$user = $form->vars['value'];
} else {
$user = null;
}
return $user && $user->getId()
? ['Roles', 'Default']
: ['Registration', 'Roles', 'Default'];
},
'ownership_disabled' => $this->isMyProfilePage
]
);
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'oro_user_user';
}
/**
* Set user fields
*
* @param FormBuilderInterface $builder
*/
protected function setDefaultUserFields(FormBuilderInterface $builder)
{
$builder
->add('username', 'text', ['label' => 'oro.user.username.label', 'required' => true])
->add('email', 'email', ['label' => 'oro.user.email.label', 'required' => true])
->add('phone', 'text', ['label' => 'oro.user.phone.label', 'required' => false])
->add('namePrefix', 'text', ['label' => 'oro.user.name_prefix.label', 'required' => false])
->add('firstName', 'text', ['label' => 'oro.user.first_name.label', 'required' => true])
->add('middleName', 'text', ['label' => 'oro.user.middle_name.label', 'required' => false])
->add('lastName', 'text', ['label' => 'oro.user.last_name.label', 'required' => true])
->add('nameSuffix', 'text', ['label' => 'oro.user.name_suffix.label', 'required' => false])
->add('birthday', OroBirthdayType::class, ['label' => 'oro.user.birthday.label', 'required' => false]);
}
/**
* Add Invite user fields
*
* @param FormBuilderInterface $builder
*/
protected function addInviteUserField(FormBuilderInterface $builder)
{
$builder->add(
'inviteUser',
'checkbox',
[
'label' => 'oro.user.invite.label',
'mapped' => false,
'required' => false,
'tooltip' => 'oro.user.invite.tooltip',
'data' => true
]
);
}
/**
* @param FormBuilderInterface $builder
*/
protected function addOrganizationField(FormBuilderInterface $builder)
{
if ($this->securityFacade->isGranted('oro_organization_view')
&& $this->securityFacade->isGranted('oro_business_unit_view')
) {
$builder->add(
'organizations',
'oro_organizations_select',
[
'required' => false,
]
);
}
}
... /Entity/User.php
<?php
namespace Oro\Bundle\UserBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Event\PreUpdateEventArgs;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as JMS;
use Oro\Bundle\EmailBundle\Entity\EmailOrigin;
use Oro\Bundle\EmailBundle\Entity\EmailOwnerInterface;
use Oro\Bundle\EmailBundle\Model\EmailHolderInterface;
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\Config;
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\ConfigField;
use Oro\Bundle\ImapBundle\Entity\UserEmailOrigin;
use Oro\Bundle\ImapBundle\Form\Model\AccountTypeModel;
use Oro\Bundle\LocaleBundle\Model\FullNameInterface;
use Oro\Bundle\NotificationBundle\Entity\NotificationEmailInterface;
use Oro\Bundle\OrganizationBundle\Entity\BusinessUnit;
use Oro\Bundle\OrganizationBundle\Entity\Organization;
use Oro\Bundle\OrganizationBundle\Entity\OrganizationInterface;
use Oro\Bundle\UserBundle\Model\ExtendUser;
use Oro\Bundle\UserBundle\Security\AdvancedApiUserInterface;
/**
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @SuppressWarnings(PHPMD.ExcessiveClassLength)
*
* @ORM\Entity(repositoryClass="Oro\Bundle\UserBundle\Entity\Repository\UserRepository")
* @ORM\Table(name="oro_user", indexes = {
* @ORM\Index("user_first_name_last_name_idx", columns = {"first_name", "last_name"})
* })
* @ORM\HasLifecycleCallbacks()
* @Config(
* routeName="oro_user_index",
* routeView="oro_user_view",
* defaultValues={
* "entity"={
* "icon"="fa-user"
* },
* "grouping"={
* "groups"={"dictionary"}
* },
* "dictionary"={
* "virtual_fields"={"id"},
* "search_fields"={"firstName", "lastName"},
* "representation_field"="fullName",
* "activity_support"="true"
* },
* "ownership"={
* "owner_type"="BUSINESS_UNIT",
* "owner_field_name"="owner",
* "owner_column_name"="business_unit_owner_id",
* "organization_field_name"="organization",
* "organization_column_name"="organization_id"
* },
* "dataaudit"={"auditable"=true},
* "security"={
* "type"="ACL",
* "group_name"="",
* "category"="account_management"
* },
* "form"={
* "form_type"="oro_user_select",
* "grid_name"="users-select-grid"
* },
* "grid"={
* "default"="users-grid",
* "context"="users-for-context-grid"
* },
* "tag"={
* "enabled"=true
* }
* }
* )
* @JMS\ExclusionPolicy("ALL")
*/
class User extends ExtendUser implements
EmailOwnerInterface,
EmailHolderInterface,
FullNameInterface,
NotificationEmailInterface,
OrganizationAwareUserInterface,
AdvancedApiUserInterface
{
const ROLE_DEFAULT = 'ROLE_USER';
const ROLE_ADMINISTRATOR = 'ROLE_ADMINISTRATOR';
const ROLE_ANONYMOUS = 'IS_AUTHENTICATED_ANONYMOUSLY';
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
* @JMS\Type("integer")
* @JMS\Expose
*/
protected $id;
/**
* @var string
*
* @ORM\Column(type="string", length=255, unique=true)
* @JMS\Type("string")
* @JMS\Expose
* @ConfigField(
* defaultValues={
* "dataaudit"={
* "auditable"=true
* },
* "importexport"={
* "identity"=true
* }
* }
* )
*/
protected $username;
/**
* @var string
*
* @ORM\Column(type="string", length=255, unique=true)
* @JMS\Type("string")
* @JMS\Expose
* @ConfigField(
* defaultValues={
* "dataaudit"={
* "auditable"=true
* }
* }
* )
*/
protected $email;
/**
* Name prefix
*
* @var string
*
* @ORM\Column(name="name_prefix", type="string", length=255, nullable=true)
* @JMS\Type("string")
* @JMS\Expose
* @ConfigField(
* defaultValues={
* "dataaudit"={
* "auditable"=true
* }
* }
* )
*/
protected $namePrefix;
/**
* First name
*
* @var string
*
* @ORM\Column(name="first_name", type="string", length=255, nullable=true)
* @JMS\Type("string")
* @JMS\Expose
* @ConfigField(
* defaultValues={
* "dataaudit"={
* "auditable"=true
* }
* }
* )
*/
protected $firstName;
/**
* Middle name
*
* @var string
*
* @ORM\Column(name="middle_name", type="string", length=255, nullable=true)
* @JMS\Type("string")
* @JMS\Expose
* @ConfigField(
* defaultValues={
* "dataaudit"={
* "auditable"=true
* }
* }
* )
*/
protected $middleName;
/**
* Last name
*
* @var string
*
* @ORM\Column(name="last_name", type="string", length=255, nullable=true)
* @JMS\Type("string")
* @JMS\Expose
* @ConfigField(
* defaultValues={
* "dataaudit"={
* "auditable"=true
* }
* }
* )
*/
protected $lastName;
/**
* Name suffix
*
* @var string
*
* @ORM\Column(name="name_suffix", type="string", length=255, nullable=true)
* @JMS\Type("string")
* @JMS\Expose
* @ConfigField(
* defaultValues={
* "dataaudit"={
* "auditable"=true
* }
* }
* )
*/
protected $nameSuffix;
/**
* @var Group[]|Collection
*
* @ORM\ManyToMany(targetEntity="Oro\Bundle\UserBundle\Entity\Group")
* @ORM\JoinTable(name="oro_user_access_group",
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE")},
* inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id", onDelete="CASCADE")}
* )
* @ConfigField(
* defaultValues={
* "dataaudit"={
* "auditable"=true
* }
* }
* )
*/
(...)
答案 0 :(得分:0)
您可以继承UserBundle并覆盖您需要的部分。 https://gstreamer.freedesktop.org/data/pkg/osx/1.12.0/