12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- /*
- * This file is part of the Sonata package.
- *
- * (c) 2010-2011 Thomas Rabaix <thomas.rabaix@sonata-project.org>
- *
- * 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;
- }
- }
|