vendor/sonata-project/doctrine-orm-admin-bundle/src/FieldDescription/FieldDescription.php line 19

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of the Sonata Project package.
  5.  *
  6.  * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace Sonata\DoctrineORMAdminBundle\FieldDescription;
  12. use Doctrine\ORM\Mapping\ClassMetadata;
  13. use Sonata\AdminBundle\FieldDescription\BaseFieldDescription;
  14. final class FieldDescription extends BaseFieldDescription
  15. {
  16.     public function getTargetModel(): ?string
  17.     {
  18.         return $this->associationMapping['targetEntity'] ?? null;
  19.     }
  20.     public function isIdentifier(): bool
  21.     {
  22.         return $this->fieldMapping['id'] ?? false;
  23.     }
  24.     public function getValue(object $object)
  25.     {
  26.         foreach ($this->parentAssociationMappings as $parentAssociationMapping) {
  27.             $object $this->getFieldValue($object$parentAssociationMapping['fieldName']);
  28.         }
  29.         return $this->getFieldValue($object$this->getFieldName());
  30.     }
  31.     public function describesSingleValuedAssociation(): bool
  32.     {
  33.         return \is_int($this->mappingType) && $this->mappingType === ($this->mappingType ClassMetadata::TO_ONE);
  34.     }
  35.     public function describesCollectionValuedAssociation(): bool
  36.     {
  37.         return \is_int($this->mappingType) && $this->mappingType === ($this->mappingType ClassMetadata::TO_MANY);
  38.     }
  39.     protected function setFieldMapping(array $fieldMapping): void
  40.     {
  41.         $this->fieldMapping $fieldMapping;
  42.         $this->type ??= (string) $fieldMapping['type'];
  43.         $this->mappingType ??= $fieldMapping['type'];
  44.     }
  45.     protected function setAssociationMapping(array $associationMapping): void
  46.     {
  47.         $this->associationMapping $associationMapping;
  48.         $this->type ??= (string) $associationMapping['type'];
  49.         $this->mappingType ??= $associationMapping['type'];
  50.     }
  51.     protected function setParentAssociationMappings(array $parentAssociationMappings): void
  52.     {
  53.         foreach ($parentAssociationMappings as $parentAssociationMapping) {
  54.             if (!\is_array($parentAssociationMapping)) {
  55.                 throw new \InvalidArgumentException('An association mapping must be an array');
  56.             }
  57.         }
  58.         $this->parentAssociationMappings $parentAssociationMappings;
  59.     }
  60. }