public function create($data, $entity = null)
    {
        $entity = $this->getEntity($entity);
        $fields = $this->getFields();

        // set fields
        foreach ($fields as $key => $mapping) {
            $fieldType = $this->fieldManager->get($mapping['fieldtype'], $mapping);

            // If we have a transformer setup then this takes precedence
            $mappedType = $mapping['fieldtype'];
            $handler = isset($this->transformers[$mappedType]) ? $this->transformers[$mappedType] : null;

            if ($handler) {
                $handler($entity, $data[$key]);
            } else {
                $val = isset($data[$key]) ? $data[$key] : null;
                if ($fieldType instanceof FieldTypeInterface) {
                    $fieldType->set($entity, $val);
                }
            }
        }

        return $entity;
    }
public function create($data, $entity = null)
    {
        $entity = $this->getEntity($entity);
        $fields = $this->getFields();

        // set fields
        foreach ($fields as $key => $mapping) {
            $fieldType = $this->fieldManager->get($mapping['fieldtype'], $mapping);

            // If we have a transformer setup then this takes precedence
            $mappedType = $mapping['fieldtype'];
            $handler = isset($this->transformers[$mappedType]) ? $this->transformers[$mappedType] : null;

            if ($handler) {
                $handler($entity, $data[$key]);
            } else {
                $val = isset($data[$key]) ? $data[$key] : null;
                if ($fieldType instanceof FieldTypeInterface) {
                    $fieldType->set($entity, $val);
                }
            }
        }

        return $entity;
    }
public function create ( $ data , $ entity = null ) { $ entity = $ this -> getEntity ( $ entity ) ; $ fields = $ this -> getFields ( ) ; // set fields foreach ( $ fields as $ key => $ mapping ) { $ fieldType = $ this -> fieldManager -> get ( $ mapping [ 'fieldtype' ] , $ mapping ) ; // If we have a transformer setup then this takes precedence $ mappedType = $ mapping [ 'fieldtype' ] ; $ handler = isset ( $ this -> transformers [ $ mappedType ] ) ? $ this -> transformers [ $ mappedType ] : null ; if ( $ handler ) { $ handler ( $ entity , $ data [ $ key ] ) ; } else { $ val = isset ( $ data [ $ key ] ) ? $ data [ $ key ] : null ; if ( $ fieldType instanceof FieldTypeInterface ) { $ fieldType -> set ( $ entity , $ val ) ; } } } return $ entity ; }
Creates a new entity object.

@param array|object $data   data to load into the entity
@param object|null  $entity

@throws \Bolt\Exception\StorageException

@return object $entity
Creates a new entity object .