Core/Orm/Validation/Element/Element.php
protected function _getField() {
        //We can access to a field of the current Entity or a linked Entity (foreign key)
        //If the field name contain a "." it's the second case
        $fields = [];
        $fieldsData = $this->_entity->fields();

        //We have to analyze a classic field without linked Entity
        if (!preg_match('#\.#isU', $this->_field)) {
            if (isset($fieldsData[$this->_field])) {
                $fields = [$fieldsData[$this->_field]->value];
            }
            else {
                throw new MissingEntityException('The field "' . $this->_field . '" in the Entity "' . $this->_entity->name() . '" does\'nt exist');
            }
        }
        else {
            //Here it's sure that we have a linked Entity. But we don't compute "One to One and One to Many" in the same way than the 2 other
            //because in the two first the field value is an Entity object and in the two other, the field value is a Collection
            //To know which type of linked Entity it's, we just split the name on the "." and we take the index 0 of the generated array

            $entityName = explode('.', $this->_field);

            if (array_key_exists($entityName[0], $fieldsData) && $fieldsData[$entityName[0]]->foreign != null) {
                /** @var int $foreignType : the type of the foreign key */
                $foreignType = $fieldsData[$entityName[0]]->foreign->type();
                /** @var mixed $fieldValue : the value of the sub-field from the Entity (post.article.content->value) */
                $fieldValue = $fieldsData[$entityName[0]]->value->fields()[$entityName[1]];

                if ($foreignType == ForeignKey::ONE_TO_MANY || $foreignType == ForeignKey::MANY_TO_ONE) {
                    $fields = $this->_getForeignKeyFieldValue($fieldValue);
                }
                else { //We must get all the sub entities as an array an then loop through this array to get the field values
                    foreach ($fieldValue->data() as $fieldValueCollection) {
                        $fields = array_merge($fields, $this->_getForeignKeyFieldValue($fieldValueCollection));
                    }
                }
            }
            else {
                throw new MissingEntityException('The field "' . $this->_field . '" in the Entity "' . $this->_entity->name() . '" does\'nt exist');
            }
        }

        return $fields;
    }
protected function _getField() {
        //We can access to a field of the current Entity or a linked Entity (foreign key)
        //If the field name contain a "." it's the second case
        $fields = [];
        $fieldsData = $this->_entity->fields();

        //We have to analyze a classic field without linked Entity
        if (!preg_match('#\.#isU', $this->_field)) {
            if (isset($fieldsData[$this->_field])) {
                $fields = [$fieldsData[$this->_field]->value];
            }
            else {
                throw new MissingEntityException('The field "' . $this->_field . '" in the Entity "' . $this->_entity->name() . '" does\'nt exist');
            }
        }
        else {
            //Here it's sure that we have a linked Entity. But we don't compute "One to One and One to Many" in the same way than the 2 other
            //because in the two first the field value is an Entity object and in the two other, the field value is a Collection
            //To know which type of linked Entity it's, we just split the name on the "." and we take the index 0 of the generated array

            $entityName = explode('.', $this->_field);

            if (array_key_exists($entityName[0], $fieldsData) && $fieldsData[$entityName[0]]->foreign != null) {
                /** @var int $foreignType : the type of the foreign key */
                $foreignType = $fieldsData[$entityName[0]]->foreign->type();
                /** @var mixed $fieldValue : the value of the sub-field from the Entity (post.article.content->value) */
                $fieldValue = $fieldsData[$entityName[0]]->value->fields()[$entityName[1]];

                if ($foreignType == ForeignKey::ONE_TO_MANY || $foreignType == ForeignKey::MANY_TO_ONE) {
                    $fields = $this->_getForeignKeyFieldValue($fieldValue);
                }
                else { //We must get all the sub entities as an array an then loop through this array to get the field values
                    foreach ($fieldValue->data() as $fieldValueCollection) {
                        $fields = array_merge($fields, $this->_getForeignKeyFieldValue($fieldValueCollection));
                    }
                }
            }
            else {
                throw new MissingEntityException('The field "' . $this->_field . '" in the Entity "' . $this->_entity->name() . '" does\'nt exist');
            }
        }

        return $fields;
    }
protected function _getField ( ) { //We can access to a field of the current Entity or a linked Entity (foreign key) //If the field name contain a "." it's the second case $ fields = [ ] ; $ fieldsData = $ this -> _entity -> fields ( ) ; //We have to analyze a classic field without linked Entity if ( ! preg_match ( '#\.#isU' , $ this -> _field ) ) { if ( isset ( $ fieldsData [ $ this -> _field ] ) ) { $ fields = [ $ fieldsData [ $ this -> _field ] -> value ] ; } else { throw new MissingEntityException ( 'The field "' . $ this -> _field . '" in the Entity "' . $ this -> _entity -> name ( ) . '" does\'nt exist' ) ; } } else { //Here it's sure that we have a linked Entity. But we don't compute "One to One and One to Many" in the same way than the 2 other //because in the two first the field value is an Entity object and in the two other, the field value is a Collection //To know which type of linked Entity it's, we just split the name on the "." and we take the index 0 of the generated array $ entityName = explode ( '.' , $ this -> _field ) ; if ( array_key_exists ( $ entityName [ 0 ] , $ fieldsData ) && $ fieldsData [ $ entityName [ 0 ] ] -> foreign != null ) { /** @var int $foreignType : the type of the foreign key */ $ foreignType = $ fieldsData [ $ entityName [ 0 ] ] -> foreign -> type ( ) ; /** @var mixed $fieldValue : the value of the sub-field from the Entity (post.article.content->value) */ $ fieldValue = $ fieldsData [ $ entityName [ 0 ] ] -> value -> fields ( ) [ $ entityName [ 1 ] ] ; if ( $ foreignType == ForeignKey :: ONE_TO_MANY || $ foreignType == ForeignKey :: MANY_TO_ONE ) { $ fields = $ this -> _getForeignKeyFieldValue ( $ fieldValue ) ; } else { //We must get all the sub entities as an array an then loop through this array to get the field values foreach ( $ fieldValue -> data ( ) as $ fieldValueCollection ) { $ fields = array_merge ( $ fields , $ this -> _getForeignKeyFieldValue ( $ fieldValueCollection ) ) ; } } } else { throw new MissingEntityException ( 'The field "' . $ this -> _field . '" in the Entity "' . $ this -> _entity -> name ( ) . '" does\'nt exist' ) ; } } return $ fields ; }
Before validating the field, we need to get the correct field from the current Entity or a linked Entity
@access public
@throws MissingEntityException
@return mixed array
@since 3.0
@package Gcs\Framework\Core\Form\Validation\Element
Before validating the field we need to get the correct field from the current Entity or a linked Entity