* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Sonata\DoctrineORMAdminBundle\Admin; use Sonata\AdminBundle\Admin\BaseFieldDescription; class FieldDescription extends BaseFieldDescription { /** * Define the association mapping definition * * @param array $associationMapping * @return void */ public function setAssociationMapping($associationMapping) { if (!is_array($associationMapping)) { throw new \RuntimeException('The association mapping must be an array'); } $this->associationMapping = $associationMapping; $this->type = $this->type ?: $associationMapping['type']; $this->mappingType = $this->mappingType ?: $associationMapping['type']; $this->fieldName = $associationMapping['fieldName']; } /** * return the related Target Entity * * @return string|null */ public function getTargetEntity() { if ($this->associationMapping) { return $this->associationMapping['targetEntity']; } return null; } /** * set the field mapping information * * @param array $fieldMapping * @return void */ public function setFieldMapping($fieldMapping) { if (!is_array($fieldMapping)) { throw new \RuntimeException('The field mapping must be an array'); } $this->fieldMapping = $fieldMapping; $this->type = $this->type ?: $fieldMapping['type']; $this->mappingType = $this->mappingType ?: $fieldMapping['type']; $this->fieldName = $this->fieldName ?: $fieldMapping['fieldName']; } /** * return true if the FieldDescription is linked to an identifier field * * @return bool */ public function isIdentifier() { return isset($this->fieldMapping['id']) ? $this->fieldMapping['id'] : false; } }