本文整理汇总了PHP中Sonata\AdminBundle\Admin\FieldDescriptionInterface::mergeOptions方法的典型用法代码示例。如果您正苦于以下问题:PHP FieldDescriptionInterface::mergeOptions方法的具体用法?PHP FieldDescriptionInterface::mergeOptions怎么用?PHP FieldDescriptionInterface::mergeOptions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sonata\AdminBundle\Admin\FieldDescriptionInterface
的用法示例。
在下文中一共展示了FieldDescriptionInterface::mergeOptions方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fixFieldDescription
/**
* The method defines the correct default settings for the provided FieldDescription
*
* @param \Sonata\AdminBundle\Admin\AdminInterface $admin
* @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
* @param array $options
* @return void
*/
public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription, array $options = array())
{
$fieldDescription->mergeOptions($options);
if ($admin->getModelManager()->hasMetadata($admin->getClass())) {
$metadata = $admin->getModelManager()->getMetadata($admin->getClass());
// set the default field mapping
if (isset($metadata->fieldMappings[$fieldDescription->getName()])) {
$fieldDescription->setFieldMapping($metadata->fieldMappings[$fieldDescription->getName()]);
}
// set the default association mapping
if (isset($metadata->associationMappings[$fieldDescription->getName()])) {
$fieldDescription->setAssociationMapping($metadata->associationMappings[$fieldDescription->getName()]);
}
}
if (!$fieldDescription->getType()) {
throw new \RuntimeException(sprintf('Please define a type for field `%s` in `%s`', $fieldDescription->getName(), get_class($admin)));
}
$fieldDescription->setAdmin($admin);
$fieldDescription->setOption('edit', $fieldDescription->getOption('edit', 'standard'));
// fix template value for doctrine association fields
if (!$fieldDescription->getTemplate()) {
$fieldDescription->setTemplate(sprintf('SonataAdminBundle:CRUD:edit_%s.html.twig', $fieldDescription->getType()));
}
if ($fieldDescription->getType() == ClassMetadataInfo::ONE_TO_ONE) {
$fieldDescription->setTemplate('SonataAdminBundle:CRUD:edit_orm_one_to_one.html.twig');
$admin->attachAdminClass($fieldDescription);
}
if ($fieldDescription->getType() == ClassMetadataInfo::MANY_TO_ONE) {
$fieldDescription->setTemplate('SonataAdminBundle:CRUD:edit_orm_many_to_one.html.twig');
$admin->attachAdminClass($fieldDescription);
}
if ($fieldDescription->getType() == ClassMetadataInfo::MANY_TO_MANY) {
$fieldDescription->setTemplate('SonataAdminBundle:CRUD:edit_orm_many_to_many.html.twig');
$admin->attachAdminClass($fieldDescription);
}
if ($fieldDescription->getType() == ClassMetadataInfo::ONE_TO_MANY) {
$fieldDescription->setTemplate('SonataAdminBundle:CRUD:edit_orm_one_to_many.html.twig');
if ($fieldDescription->getOption('edit') == 'inline' && !$fieldDescription->getOption('widget_form_field')) {
$fieldDescription->setOption('widget_form_field', 'Bundle\\Sonata\\AdminBundle\\Form\\EditableFieldGroup');
}
$admin->attachAdminClass($fieldDescription);
}
// set correct default value
if ($fieldDescription->getType() == 'datetime') {
$options = $fieldDescription->getOption('form_field_options', array());
if (!isset($options['years'])) {
$options['years'] = range(1900, 2100);
}
$fieldDescription->setOption('form_field', $options);
}
}