本文整理汇总了PHP中Sonata\AdminBundle\Admin\FieldDescriptionInterface::getMappingType方法的典型用法代码示例。如果您正苦于以下问题:PHP FieldDescriptionInterface::getMappingType方法的具体用法?PHP FieldDescriptionInterface::getMappingType怎么用?PHP FieldDescriptionInterface::getMappingType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sonata\AdminBundle\Admin\FieldDescriptionInterface
的用法示例。
在下文中一共展示了FieldDescriptionInterface::getMappingType方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fixFieldDescription
/**
* {@inheritdoc}
*/
public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription)
{
// set default values
$fieldDescription->setAdmin($admin);
if ($admin->getModelManager()->hasMetadata($admin->getClass())) {
list($metadata, $lastPropertyName, $parentAssociationMappings) = $admin->getModelManager()->getParentMetadataForProperty($admin->getClass(), $fieldDescription->getName());
// set the default field mapping
if (isset($metadata->fieldMappings[$lastPropertyName])) {
$fieldDescription->setOption('field_mapping', $fieldDescription->getOption('field_mapping', $metadata->fieldMappings[$lastPropertyName]));
if ($metadata->fieldMappings[$lastPropertyName]['type'] == 'string') {
$fieldDescription->setOption('global_search', $fieldDescription->getOption('global_search', true));
// always search on string field only
}
}
// set the default association mapping
if (isset($metadata->associationMappings[$lastPropertyName])) {
$fieldDescription->setOption('association_mapping', $fieldDescription->getOption('association_mapping', $metadata->associationMappings[$lastPropertyName]));
}
$fieldDescription->setOption('parent_association_mappings', $fieldDescription->getOption('parent_association_mappings', $parentAssociationMappings));
}
$fieldDescription->setOption('code', $fieldDescription->getOption('code', $fieldDescription->getName()));
$fieldDescription->setOption('name', $fieldDescription->getOption('name', $fieldDescription->getName()));
if (in_array($fieldDescription->getMappingType(), array(ClassMetadataInfo::ONE_TO_MANY, ClassMetadataInfo::MANY_TO_MANY, ClassMetadataInfo::MANY_TO_ONE, ClassMetadataInfo::ONE_TO_ONE))) {
$admin->attachAdminClass($fieldDescription);
}
}
示例2: getDefaultOptions
/**
* {@inheritdoc}
*/
public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescription)
{
$options = array();
$options['sonata_field_description'] = $fieldDescription;
if ($type == 'sonata_type_model' || $type == 'sonata_type_model_list' || $type == 'sonata_type_model_hidden') {
if ($fieldDescription->getOption('edit') == 'list') {
throw new \LogicException('The ``sonata_type_model`` type does not accept an ``edit`` option anymore, please review the UPGRADE-2.1.md file from the SonataAdminBundle');
}
$options['class'] = $fieldDescription->getTargetEntity();
$options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();
} elseif ($type == 'sonata_type_admin') {
if (!$fieldDescription->getAssociationAdmin()) {
throw new \RuntimeException(sprintf('The current field `%s` is not linked to an admin. Please create one for the target entity : `%s`', $fieldDescription->getName(), $fieldDescription->getTargetEntity()));
}
if (!in_array($fieldDescription->getMappingType(), array(ClassMetadataInfo::ONE_TO_ONE, ClassMetadataInfo::MANY_TO_ONE))) {
throw new \RuntimeException(sprintf('You are trying to add `sonata_type_admin` field `%s` which is not One-To-One or Many-To-One. Maybe you want `sonata_model_list` instead?', $fieldDescription->getName()));
}
$options['data_class'] = $fieldDescription->getAssociationAdmin()->getClass();
$fieldDescription->setOption('edit', $fieldDescription->getOption('edit', 'admin'));
} elseif ($type == 'sonata_type_collection') {
if (!$fieldDescription->getAssociationAdmin()) {
throw new \RuntimeException(sprintf('The current field `%s` is not linked to an admin. Please create one for the target entity : `%s`', $fieldDescription->getName(), $fieldDescription->getTargetEntity()));
}
$options['type'] = 'sonata_type_admin';
$options['modifiable'] = true;
$options['type_options'] = array('sonata_field_description' => $fieldDescription, 'data_class' => $fieldDescription->getAssociationAdmin()->getClass());
}
return $options;
}
示例3: fixFieldDescription
/**
* The method defines the correct default settings for the provided FieldDescription
*
* @param \Sonata\AdminBundle\Admin\AdminInterface $admin
* @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
* @return void
*/
public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription)
{
$fieldDescription->setAdmin($admin);
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->setOption('code', $fieldDescription->getOption('code', $fieldDescription->getName()));
$fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName()));
if (!$fieldDescription->getTemplate()) {
$fieldDescription->setTemplate(sprintf('SonataAdminBundle:CRUD:show_%s.html.twig', $fieldDescription->getType()));
if ($fieldDescription->getMappingType() == ClassMetadata::MANY_TO_ONE) {
$fieldDescription->setTemplate('SonataAdminBundle:CRUD:show_orm_many_to_one.html.twig');
}
if ($fieldDescription->getMappingType() == ClassMetadata::ONE_TO_ONE) {
$fieldDescription->setTemplate('SonataAdminBundle:CRUD:show_orm_one_to_one.html.twig');
}
if ($fieldDescription->getMappingType() == ClassMetadata::ONE_TO_MANY) {
$fieldDescription->setTemplate('SonataAdminBundle:CRUD:show_orm_one_to_many.html.twig');
}
if ($fieldDescription->getMappingType() == ClassMetadata::MANY_TO_MANY) {
$fieldDescription->setTemplate('SonataAdminBundle:CRUD:show_orm_many_to_many.html.twig');
}
}
if ($fieldDescription->getMappingType() == ClassMetadata::MANY_TO_ONE) {
$admin->attachAdminClass($fieldDescription);
}
if ($fieldDescription->getMappingType() == ClassMetadata::ONE_TO_ONE) {
$admin->attachAdminClass($fieldDescription);
}
if ($fieldDescription->getMappingType() == ClassMetadata::ONE_TO_MANY) {
$admin->attachAdminClass($fieldDescription);
}
if ($fieldDescription->getMappingType() == ClassMetadata::MANY_TO_MANY) {
$admin->attachAdminClass($fieldDescription);
}
}
示例4: fixFieldDescription
/**
* @param \Sonata\AdminBundle\Admin\AdminInterface $admin
* @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
*/
public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription)
{
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'));
if (in_array($fieldDescription->getMappingType(), array(\RelationMap::MANY_TO_MANY, \RelationMap::MANY_TO_ONE, \RelationMap::ONE_TO_MANY, \RelationMap::ONE_TO_ONE))) {
$admin->attachAdminClass($fieldDescription);
}
}
示例5: getFormTypeName
/**
* Returns the class associated to a FieldDescriptionInterface if any defined
*
* @throws RuntimeException
* @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
* @return bool|string
*/
public function getFormTypeName(FieldDescriptionInterface $fieldDescription)
{
$typeName = false;
// the user redefined the mapping type, use the default built in definition
if (!$fieldDescription->getFieldMapping() || $fieldDescription->getType() != $fieldDescription->getMappingType()) {
$typeName = array_key_exists($fieldDescription->getType(), $this->formTypes) ? $this->formTypes[$fieldDescription->getType()] : false;
} else {
if ($fieldDescription->getOption('form_field_type', false)) {
$typeName = $fieldDescription->getOption('form_field_type', false);
} else {
if (array_key_exists($fieldDescription->getType(), $this->formTypes)) {
$typeName = $this->formTypes[$fieldDescription->getType()];
}
}
}
if (!$typeName) {
throw new \RuntimeException(sprintf('No known form type for field `%s` (`%s`) is implemented.', $fieldDescription->getFieldName(), $fieldDescription->getType()));
}
return $typeName;
}
示例6: fixFieldDescription
/**
* {@inheritdoc}
*/
public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription)
{
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'));
if (in_array($fieldDescription->getMappingType(), array(ClassMetadataInfo::ONE_TO_MANY, ClassMetadataInfo::MANY_TO_MANY, ClassMetadataInfo::MANY_TO_ONE, ClassMetadataInfo::ONE_TO_ONE))) {
$admin->attachAdminClass($fieldDescription);
}
}
示例7: getDefaultOptions
/**
* @param $type
* @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
* @return array
*/
public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescription)
{
$options = array();
$options['sonata_field_description'] = $fieldDescription;
if ($type == 'doctrine_phpcr_type_tree_model') {
$options['class'] = $fieldDescription->getTargetEntity();
$options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();
}
if ($type == 'sonata_type_model') {
$options['class'] = $fieldDescription->getTargetEntity();
$options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();
switch ($fieldDescription->getMappingType()) {
case ClassMetadata::ONE_TO_MANY:
case ClassMetadata::MANY_TO_MANY:
$options['multiple'] = true;
$options['parent'] = 'choice';
break;
case ClassMetadata::MANY_TO_ONE:
case ClassMetadata::ONE_TO_ONE:
break;
}
if ($fieldDescription->getOption('edit') == 'list') {
$options['parent'] = 'text';
if (!array_key_exists('required', $options)) {
$options['required'] = false;
}
}
} else {
if ($type == 'sonata_type_admin') {
// nothing here ...
$options['edit'] = 'inline';
} else {
if ($type == 'sonata_type_collection') {
$options['type'] = 'sonata_type_admin';
$options['modifiable'] = true;
$options['type_options'] = array('sonata_field_description' => $fieldDescription, 'data_class' => $fieldDescription->getAssociationAdmin()->getClass());
}
}
}
return $options;
}
示例8: fixFieldDescription
/**
* The method defines the correct default settings for the provided FieldDescription
*
* @param \Sonata\AdminBundle\Admin\AdminInterface $admin
* @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
*
* @return void
*/
public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription)
{
$fieldDescription->setAdmin($admin);
if ($admin->getModelManager()->hasMetadata($admin->getClass())) {
list($metadata, $lastPropertyName, $parentAssociationMappings) = $admin->getModelManager()->getParentMetadataForProperty($admin->getClass(), $fieldDescription->getName());
$fieldDescription->setParentAssociationMappings($parentAssociationMappings);
// set the default field mapping
if (isset($metadata->fieldMappings[$lastPropertyName])) {
$fieldDescription->setFieldMapping($metadata->fieldMappings[$lastPropertyName]);
}
// set the default association mapping
if (isset($metadata->associationMappings[$lastPropertyName])) {
$fieldDescription->setAssociationMapping($metadata->associationMappings[$lastPropertyName]);
}
}
if (!$fieldDescription->getType()) {
throw new \RuntimeException(sprintf('Please define a type for field `%s` in `%s`', $fieldDescription->getName(), get_class($admin)));
}
$fieldDescription->setOption('code', $fieldDescription->getOption('code', $fieldDescription->getName()));
$fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName()));
if (!$fieldDescription->getTemplate()) {
$fieldDescription->setTemplate($this->getTemplate($fieldDescription->getType()));
if (!$fieldDescription->getTemplate()) {
switch ($fieldDescription->getMappingType()) {
case ClassMetadataInfo::MANY_TO_ONE:
$fieldDescription->setTemplate('SonataDoctrineORMAdminBundle:CRUD:show_orm_many_to_one.html.twig');
break;
case ClassMetadataInfo::ONE_TO_ONE:
$fieldDescription->setTemplate('SonataDoctrineORMAdminBundle:CRUD:show_orm_one_to_one.html.twig');
break;
case ClassMetadataInfo::ONE_TO_MANY:
$fieldDescription->setTemplate('SonataDoctrineORMAdminBundle:CRUD:show_orm_one_to_many.html.twig');
break;
case ClassMetadataInfo::MANY_TO_MANY:
$fieldDescription->setTemplate('SonataDoctrineORMAdminBundle:CRUD:show_orm_many_to_many.html.twig');
break;
}
}
}
switch ($fieldDescription->getMappingType()) {
case ClassMetadataInfo::MANY_TO_ONE:
case ClassMetadataInfo::ONE_TO_ONE:
case ClassMetadataInfo::ONE_TO_MANY:
case ClassMetadataInfo::MANY_TO_MANY:
$admin->attachAdminClass($fieldDescription);
break;
}
}
示例9: fixFieldDescription
/**
* @throws \RuntimeException
* @param \Sonata\AdminBundle\Admin\AdminInterface $admin
* @param \Sonata\AdminBundle\Admin\FieldDescription $fieldDescription
* @return void
*/
public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription)
{
// set default values
$fieldDescription->setAdmin($admin);
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()]);
}
}
$fieldDescription->setOption('code', $fieldDescription->getOption('code', $fieldDescription->getName()));
$fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName()));
$fieldDescription->setOption('filter_value', $fieldDescription->getOption('filter_value', null));
$fieldDescription->setOption('filter_options', $fieldDescription->getOption('filter_options', null));
$fieldDescription->setOption('filter_field_options', $fieldDescription->getOption('filter_field_options', null));
$fieldDescription->setOption('name', $fieldDescription->getOption('name', $fieldDescription->getName()));
if (!$fieldDescription->getTemplate()) {
$fieldDescription->setTemplate(sprintf('SonataAdminBundle:CRUD:filter_%s.html.twig', $fieldDescription->getType()));
if ($fieldDescription->getMappingType() == ClassMetadataInfo::MANY_TO_ONE) {
$fieldDescription->setTemplate('SonataAdminBundle:CRUD:filter_many_to_one.html.twig');
}
if ($fieldDescription->getMappingType() == ClassMetadataInfo::MANY_TO_MANY) {
$fieldDescription->setTemplate('SonataAdminBundle:CRUD:filter_many_to_many.html.twig');
}
}
}
示例10: fixFieldDescription
/**
* The method defines the correct default settings for the provided FieldDescription
*
* @param \Sonata\AdminBundle\Admin\AdminInterface $admin
* @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
*
* @return void
*/
public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription)
{
$fieldDescription->setAdmin($admin);
if ($admin->getModelManager()->hasMetadata($admin->getClass())) {
list($metadata, $lastPropertyName, $parentAssociationMappings) = $admin->getModelManager()->getParentMetadataForProperty($admin->getClass(), $fieldDescription->getName());
$fieldDescription->setParentAssociationMappings($parentAssociationMappings);
// set the default field mapping
if (isset($metadata->fieldMappings[$lastPropertyName])) {
$fieldDescription->setFieldMapping($metadata->fieldMappings[$lastPropertyName]);
}
// set the default association mapping
if (isset($metadata->associationMappings[$lastPropertyName])) {
$fieldDescription->setAssociationMapping($metadata->associationMappings[$lastPropertyName]);
}
}
if (!$fieldDescription->getType()) {
throw new \RuntimeException(sprintf('Please define a type for field `%s` in `%s`', $fieldDescription->getName(), get_class($admin)));
}
$fieldDescription->setOption('code', $fieldDescription->getOption('code', $fieldDescription->getName()));
$fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName()));
if (!$fieldDescription->getTemplate()) {
if ($fieldDescription->getType() == 'id') {
$fieldDescription->setType('string');
}
if ($fieldDescription->getType() == 'int') {
$fieldDescription->setType('integer');
}
$template = $this->getTemplate($fieldDescription->getType());
if ($template === null) {
if ($fieldDescription->getMappingType() == ClassMetadataInfo::ONE) {
$template = 'SonataDoctrineMongoDBAdminBundle:CRUD:show_mongo_one.html.twig';
} elseif ($fieldDescription->getMappingType() == ClassMetadataInfo::MANY) {
$template = 'SonataDoctrineMongoDBAdminBundle:CRUD:show_mongo_many.html.twig';
}
}
$fieldDescription->setTemplate($template);
}
if (in_array($fieldDescription->getMappingType(), array(ClassMetadataInfo::ONE, ClassMetadataInfo::MANY))) {
$admin->attachAdminClass($fieldDescription);
}
}
示例11: getAssociationAdminException
/**
* @param FieldDescriptionInterface $fieldDescription
*
* @return \LogicException
*/
protected function getAssociationAdminException(FieldDescriptionInterface $fieldDescription)
{
$msg = sprintf('The current field `%s` is not linked to an admin. Please create one', $fieldDescription->getName());
if (in_array($fieldDescription->getMappingType(), array(ClassMetadata::MANY_TO_ONE, ClassMetadata::MANY_TO_MANY, 'referrers'))) {
if ($fieldDescription->getTargetEntity()) {
$msg .= " for the target document: `{$fieldDescription->getTargetEntity()}`";
}
$msg .= ', specify the `targetDocument` in the Reference, or the `referringDocument` in the Referrers or use the option `admin_code` to link it.';
} else {
$msg .= ' and use the option `admin_code` to link it.';
}
return new \LogicException($msg);
}
示例12: getDefaultOptions
/**
* @param $type
* @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
* @param array $options
* @return array
*/
public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescription)
{
$options = array();
$options['sonata_field_description'] = $fieldDescription;
if ($type == 'sonata_type_model') {
$options['class'] = $fieldDescription->getTargetEntity();
$options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();
switch ($fieldDescription->getMappingType()) {
case ClassMetadataInfo::ONE_TO_MANY:
case ClassMetadataInfo::MANY_TO_MANY:
$options['multiple'] = true;
$options['parent'] = 'choice';
break;
case ClassMetadataInfo::MANY_TO_ONE:
case ClassMetadataInfo::ONE_TO_ONE:
break;
}
} else if ($type == 'sonata_type_admin') {
// nothing here ...
$options['edit'] = 'inline';
} else if ($type == 'sonata_type_collection') {
$options['type'] = 'sonata_type_admin';
$options['modifiable'] = true;
$options['type_options'] = array(
'sonata_field_description' => $fieldDescription,
'data_class' => $fieldDescription->getAssociationAdmin()->getClass()
);
}
return $options;
}