Add an entity to the form. The entities values will be used to fill the form and the forms data
will be assigned to the entity when saveToEntities is called

@param $entity
@param null $fields
@param bool $validatable
@throws \Exception
333884
public function bindEntity($entity, $fields = null, $validatable = true)
    {
        if ($this->submitted) {
            throw new BadMethodCallException("Entities cannot be assigned after FormHandler::handleRequest has been called");
        }

        $this->entities[] = array('entity' => $entity, 'fields' => $fields, 'validatable' => $validatable);

        if ($entity instanceof EntityInterface) {
            $entityData = $entity->getFormData(array_keys($this->fields), $fields);
        } else {
            $entityData = $this->entityProcessor->getFromEntity($entity, array_keys($this->fields), $fields);
        }

        $entityData = $this->transformToFormData($entityData);

        $this->data = array_replace_recursive($this->data, $entityData);
    }
210048
public function addField(Field $field)
    {
        $tmp               = $this->fields->getValue($this->entity);
        $tmp[$field->name] = $field;
        $this->fields->setValue($this->entity, $tmp);

        if ($field->role == 'id') {
            $key = new \ReflectionProperty(Entity::class, 'key');
            $key->setAccessible(true);
            $key->setValue($this->entity, $field->name);
        }
    }
1315428
public function push(Entity $entity) {
		$entity->setEntityManager($this->entityManager);
		if ($entity->toRow()) {
			$this->rows[$entity->getPrimary()] = $entity;
		} else {
			$this->rows[] = $entity;
		}
	}
609572
public function setEntity($entity, $prepare = true)
	{
		if($entity instanceof EntityInterface)
		{
			$this->entity = $entity;
		}
		elseif(is_resource($entity) || $entity instanceof StreamInterface)
		{
			$this->entity = new StreamEntity($entity);
		}
		elseif((is_array($entity) || is_object($entity)) && is_callable($entity))
		{
			$this->entity = new CallbackEntity($entity);
		}
		else
		{
			$this->entity = new StringEntity($entity);
		}
		
		if($prepare)
		{
			$this->entity->prepare($this);
		}
		
		return $this;
	}
511527
public function validate($entity, Constraint $constraint): void
    {
        /** @var UniqueEntity $constraint */
        $em = Util::getObjectManager($this->registry, $entity, $constraint);
        $fields = (array) $constraint->fields;
        $criteria = $this->getCriteria($entity, $constraint, $em);

        if (null === $criteria) {
            return;
        }

        $result = $this->getResult($entity, $constraint, $criteria, $em);

        if (!$this->isValidResult($result, $entity)) {
            $errorPath = null !== $constraint->errorPath ? $constraint->errorPath : $fields[0];
            $invalidValue = $criteria[$errorPath] ?? $criteria[$fields[0]];

            $this->context->buildViolation($constraint->message)
                ->atPath($errorPath)
                ->setInvalidValue($invalidValue)
                ->addViolation()
            ;
        }
    }
286809
public function validate(EntityInterface $entity)
    {
        if (!$entity instanceof Attribution) {
            throw new Exception(
                sprintf('The Entity to validate must be an instance of %s', Attribution::class)
            );
        }

        $this->validateSource($entity->getSource());
        $this->validateTarget($entity->getTarget());
        $this->validateRole($entity->getRole());
        $errors = $this->getErrors();

        return empty($errors);
    }
456284
private function setFieldValue($entity, \ReflectionProperty $reflectionProperty, $value)
    {
        if ($reflectionProperty) {
            $reflectionProperty->setAccessible(true);
            $value = $reflectionProperty->setValue($entity, $value);
        }
    }
48302
public function registerReconstitutedEntity($entity, array $entityData)
    {
        $this->reconstitutedEntities->attach($entity);
        $this->reconstitutedEntitiesData[$entityData['identifier']] = $entityData;
    }
218310
public function validate(EntityInterface $entity)
    {
        if (!$entity instanceof EmailConfiguration) {
            throw new Exception(
                sprintf('The Entity to validate must be an instance of %s', EmailConfiguration::class)
            );
        }

        $this->validateEmailSender($entity->getEmailSender());
        $this->validateEmailSenderName($entity->getEmailSenderName());
        $this->validateEmailSubjectPrefix($entity->getEmailSubjectPrefix());
        $this->validateEmailBodySignature($entity->getEmailBodySignature());

        $errors = $this->getErrors();

        return empty($errors);
    }
364316
protected function validate($entity, array &$options)
    {
        $allowedEntityClasses = $this->getAllowedEntityClasses();

        if (!empty($allowedEntityClasses)) {
            $entityClassAllowed = false;

            foreach ($allowedEntityClasses as $allowedEntityClass) {
                if ($entity instanceof $allowedEntityClass) {
                    $entityClassAllowed = true;

                    break;
                }
            }
            if (!$entityClassAllowed) {
                $message = sprintf(
                    'View widget "%s" requires entity to be instance of one of "%s" classes.',
                    $this->getAlias(),
                    implode('", "', $allowedEntityClasses)
                );

                throw new WidgetException($message);
            }
        }
        try {
            $options = $this->optionsResolver->resolve($options);
        } catch (ExceptionInterface $ex) {
            throw new WidgetException(
                sprintf('View widget "%s" options are invalid: "%s".', $this->getAlias(), $ex->getMessage())
            );
        }
    }
1644
public function createForm($entity)
    {
        $formSpec = ArrayUtils::iteratorToArray($this->getFormSpecification($entity));
        if (!isset($formSpec['options']['merge_input_filter'])) {
            $formSpec['options']['merge_input_filter'] = true;
        }

        return $this->getFormFactory()->createForm($formSpec);
    }
599094
public function insert($entity)
    {
        $persistor = new CsvPersistor(
            $this->gateway,
            $this->table,
            $this->entityRegistry->getEntityBuilder(),
            $this->entityRegistry
        );
        $persistor->insert($entity);
    }
974706
protected function _ensureFields($entity)
    {
        $config = $this->getConfig();
        $fields = [$config['left'], $config['right']];
        $values = array_filter($entity->extract($fields));
        if (count($values) === count($fields)) {
            return;
        }

        $fresh = $this->_table->get($entity->get($this->_getPrimaryKey()), $fields);
        $entity->set($fresh->extract($fields), ['guard' => false]);

        foreach ($fields as $field) {
            $entity->setDirty($field, false);
        }
    }
275928
public function saveToEntity($entity, $formData, $limitFields = null)
    {
        foreach($formData as $field => $value) {
            $setter_name = "set".$this->dashesToCamelCase($field);

            if (($limitFields === null || in_array($field, $limitFields)) && method_exists($entity, $setter_name)) {
                $entity->$setter_name($value);
            }
        }
    }
1100215
public function insert($entity)
    {
        $entityId = $this->entityRegistry->getEntityId($entity);

        if (empty($entityId)) {
            $id = 0;

            foreach ($this->gateway->getAll($this->tableName) as $row) {
                $id = max($id, $row['id']);
            }

            $this->entityRegistry->setEntityId($entity, $id + 1);
        }

        $this->gateway->insert($this->tableName, $this->builder->reduce($entity));
        $this->builder->resolve($entity);
    }
697722
protected function add(string $field, ValidatorInterface $validator)
    {
        $this->data[$field] = null;
        $this->validation->add($field, $validator);
        return $this;
    }
85546
public function validate() {
		parent::validate();

		if ($this->getEntity() === null) {
			throw new ValidationException("'entity' can't be null", 'entity', $this);
		}
		if ($this->getEntityStates() === null) {
			throw new ValidationException("'entityStates' can't be null", 'entityStates', $this);
		}
		if ($this->getUrl() === null) {
			throw new ValidationException("'url' can't be null", 'url', $this);
		}
	}