public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription)
    {
        $fieldDescription->setAdmin($admin);

        $metadata = null;
        if ($admin->getModelManager()->hasMetadata($admin->getClass())) {
            /** @var ClassMetadata $metadata */
            $metadata = $admin->getModelManager()->getMetadata($admin->getClass());

            // set the default field mapping
            if (isset($metadata->mappings[$fieldDescription->getName()])) {
                $fieldDescription->setFieldMapping($metadata->mappings[$fieldDescription->getName()]);
            }

            // set the default association mapping
            if ($metadata->hasAssociation($fieldDescription->getName())) {
                $fieldDescription->setAssociationMapping($metadata->getAssociation($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($this->getTemplate($fieldDescription->getType()));

            if (ClassMetadata::MANY_TO_ONE == $fieldDescription->getMappingType()) {
                $fieldDescription->setTemplate('@SonataAdmin/CRUD/Association/show_many_to_one.html.twig');
            }

            if (ClassMetadata::MANY_TO_MANY == $fieldDescription->getMappingType()) {
                $fieldDescription->setTemplate('@SonataAdmin/CRUD/Association/show_many_to_many.html.twig');
            }
        }

        $mappingTypes = [
            ClassMetadata::MANY_TO_ONE,
            ClassMetadata::MANY_TO_MANY,
            'children',
            'child',
            'parent',
            'referrers',
        ];

        if ($metadata && $metadata->hasAssociation($fieldDescription->getName()) && \in_array($fieldDescription->getMappingType(), $mappingTypes, true)) {
            $admin->attachAdminClass($fieldDescription);
        }
    }
public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription)
    {
        $fieldDescription->setAdmin($admin);

        $metadata = null;
        if ($admin->getModelManager()->hasMetadata($admin->getClass())) {
            /** @var ClassMetadata $metadata */
            $metadata = $admin->getModelManager()->getMetadata($admin->getClass());

            // set the default field mapping
            if (isset($metadata->mappings[$fieldDescription->getName()])) {
                $fieldDescription->setFieldMapping($metadata->mappings[$fieldDescription->getName()]);
            }

            // set the default association mapping
            if ($metadata->hasAssociation($fieldDescription->getName())) {
                $fieldDescription->setAssociationMapping($metadata->getAssociation($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($this->getTemplate($fieldDescription->getType()));

            if (ClassMetadata::MANY_TO_ONE == $fieldDescription->getMappingType()) {
                $fieldDescription->setTemplate('@SonataAdmin/CRUD/Association/show_many_to_one.html.twig');
            }

            if (ClassMetadata::MANY_TO_MANY == $fieldDescription->getMappingType()) {
                $fieldDescription->setTemplate('@SonataAdmin/CRUD/Association/show_many_to_many.html.twig');
            }
        }

        $mappingTypes = [
            ClassMetadata::MANY_TO_ONE,
            ClassMetadata::MANY_TO_MANY,
            'children',
            'child',
            'parent',
            'referrers',
        ];

        if ($metadata && $metadata->hasAssociation($fieldDescription->getName()) && \in_array($fieldDescription->getMappingType(), $mappingTypes, true)) {
            $admin->attachAdminClass($fieldDescription);
        }
    }
public function fixFieldDescription ( AdminInterface $ admin , FieldDescriptionInterface $ fieldDescription ) { $ fieldDescription -> setAdmin ( $ admin ) ; $ metadata = null ; if ( $ admin -> getModelManager ( ) -> hasMetadata ( $ admin -> getClass ( ) ) ) { /** @var ClassMetadata $metadata */ $ metadata = $ admin -> getModelManager ( ) -> getMetadata ( $ admin -> getClass ( ) ) ; // set the default field mapping if ( isset ( $ metadata -> mappings [ $ fieldDescription -> getName ( ) ] ) ) { $ fieldDescription -> setFieldMapping ( $ metadata -> mappings [ $ fieldDescription -> getName ( ) ] ) ; } // set the default association mapping if ( $ metadata -> hasAssociation ( $ fieldDescription -> getName ( ) ) ) { $ fieldDescription -> setAssociationMapping ( $ metadata -> getAssociation ( $ 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 ( $ this -> getTemplate ( $ fieldDescription -> getType ( ) ) ) ; if ( ClassMetadata :: MANY_TO_ONE == $ fieldDescription -> getMappingType ( ) ) { $ fieldDescription -> setTemplate ( '@SonataAdmin/CRUD/Association/show_many_to_one.html.twig' ) ; } if ( ClassMetadata :: MANY_TO_MANY == $ fieldDescription -> getMappingType ( ) ) { $ fieldDescription -> setTemplate ( '@SonataAdmin/CRUD/Association/show_many_to_many.html.twig' ) ; } } $ mappingTypes = [ ClassMetadata :: MANY_TO_ONE , ClassMetadata :: MANY_TO_MANY , 'children' , 'child' , 'parent' , 'referrers' , ] ; if ( $ metadata && $ metadata -> hasAssociation ( $ fieldDescription -> getName ( ) ) && \ in_array ( $ fieldDescription -> getMappingType ( ) , $ mappingTypes , true ) ) { $ admin -> attachAdminClass ( $ fieldDescription ) ; } }
The method defines the correct default settings for the provided FieldDescription.

{@inheritdoc}

@throws \RuntimeException if the $fieldDescription does not have a type
The method defines the correct default settings for the provided FieldDescription .