Creates and returns an Entity or null if invalid

@return mixed
498325
protected function getEntity() {
		if (! $this->_entity) {
			if ($this->getDataTable()) {
				$this->_entity = $this->getDataTable()->getEntity();
			}
		}
		return $this->_entity;
	}
293562
protected function crudCreate(Request $request = null)
    {
        try{
            
            $entity = $this->getEntity();
            $form = $this->createAndBindForm($request, $this->getEntityType() , $entity);
            $page = static::NEW_VIEW;
            
            if ($form->isValid()) {
                $this->saveEntity($entity);                
                if($request->get('_loop_create')){
                    $form = $this->createForm($this->getEntityType(), $this->getEntity());
                }else{
                    $page = static::SHOW_VIEW;
                    $form = $this->createDeleteForm($entity->getId());
                }
                $form = $form->createView();
                return $this->render($page, $this->commonsResponseVars(compact('entity','form')));
            }
            $form = $form->createView();
            return $this->success($page, $this->commonsResponseVars(compact('entity','form')));
            
        }catch(\Exception $e){
          return $this->failure($e);
        }
    }
102551
public function createAction()
    {
        $success    = null;
        $params     = $this->params();
        $request    = $this->getRequest();
        $type       = $params->fromRoute( 'type' );
        $parent     = $params->fromRoute( 'parentId', null );
        $menu       = $this->getModel()
                           ->create( array(
                                'type' => $type,
                            ) );

        $form = $this->getForm( $menu );

        if ( $request->isPost() )
        {
            $form->setData( $request->getPost() );

            if ( $form->isValid() && $menu->save() &&
                 ( empty( $parent ) || $this->getModel()
                                            ->appendTo( $menu->id, $parent ) ) )
            {
                $success = true;

                $this->messenger()
                     ->add( 'menu.form.success',
                            'menu', Message::LEVEL_INFO );
            }
            else
            {
                $success = false;

                $this->messenger()
                     ->add( 'menu.form.failed',
                            'menu', Message::LEVEL_ERROR );
            }
        }

        return array(
            'success'   => $success,
            'form'      => $form,
            'menu'      => $menu,
        );
    }
655485
public function getCreatedBy()
    {
        $createdByAttribute = $this->createdByAttribute;
        return (!is_string($createdByAttribute) || empty($createdByAttribute)) ? null : $this->$createdByAttribute->getData();
    }
423041
public function create()
    {
        // Is this user allowed to do this?
        if (!$this->repository->isUserAllowed('create'))
        {
            Session::flash('status_code', 400 );
            $message = "You are not allowed to create ".$this->table_type_plural;
            Session::flash('message', $message);
            return view('formhandling::warnings/' . config('lasallecmsadmin.admin_template_name') . '/user_not_allowed', [
                'package_title'        => $this->package_title,
                'table_type_plural'    => $this->table_type_plural,
                'table_type_singular'  => $this->table_type_singular,
                'resource_route_name'  => $this->resource_route_name,
                'HTMLHelper'           => HTMLHelper::class,
            ]);
        }

        return view('formhandling::lookuptables/' . config('lasallecmsadmin.admin_template_name') . '/create', [
            'package_title'        => $this->package_title,
            'table_type_plural'    => $this->table_type_plural,
            'table_type_singular'  => $this->table_type_singular,
            'resource_route_name'  => $this->resource_route_name,
            'DatesHelper'          => DatesHelper::class,
            'HTMLHelper'           => HTMLHelper::class,
        ]);
    }
192057
private function createEntity()
    {
        $entity = new CacheEntity();
        $entity->setAddress1(trim(ucwords($this->contact->getAddress1())));
        $entity->setAddress2(trim(ucwords($this->contact->getAddress2())));
        $category = $this->contactClient->getCategory();
        if ($category) {
            $entity->setCategory($category->getId());
        }
        $entity->setCity(trim(ucwords($this->contact->getCity())));
        $entity->setContact($this->contact->getId());
        $entity->setContactClient($this->contactClient->getId());
        $entity->setState(trim(ucwords($this->contact->getStage())));
        $entity->setCountry(trim(ucwords($this->contact->getCountry())));
        $entity->setZipcode(trim($this->contact->getZipcode()));
        $entity->setEmail(trim($this->contact->getEmail()));
        $phone = $this->phoneValidate($this->contact->getPhone());
        if (!empty($phone)) {
            $entity->setPhone($phone);
        }
        $mobile = $this->phoneValidate($this->contact->getMobile());
        if (!empty($mobile)) {
            $entity->setMobile($mobile);
        }
        $utmSource = $this->getUtmSource();
        if (!empty($utmSource)) {
            $entity->setUtmSource($utmSource);
        }
        if ($this->dateSend) {
            $entity->setDateAdded($this->dateSend);
        }

        return $entity;
    }
271072
public function create($data)
	{
		// @todo: Implement processing
		$processPayload = new Payload($data, Payload::STATUS_VALID); // @todo: Super temporary WIP

		// // Process data given.
		// $processPayload = $this->process(__FUNCTION__, $data);

		// if( ! $processPayload->isStatus(Payload::STATUS_VALID))
		// {
		// 	return $processPayload;
		// }

		// Create the entity with the given data.
		$aggregatePayload = $this->aggregate[self::getEntityType()]->create($processPayload->getData());

		// No need to procede if dynamic content was not created.
		if( ! $aggregatePayload->isStatus(Payload::STATUS_CREATED))
		{
			return $aggregatePayload;
		}

		// Create the newly created entity's EntityIdentifier.
		$identifierPayload = $this->createIdentifier($aggregatePayload->getData());

		if( ! $identifierPayload->isStatus(Payload::STATUS_CREATED))
		{
			return $identifierPayload;
		}

		// @todo: The following currently adds an additional query just for the ease of getting the full entity to return.
		$createdEntityPayload = $this->getOneByUuid($aggregatePayload->getData()->getUuid());

		if( ! $createdEntityPayload->isStatus(Payload::STATUS_FOUND))
		{
			return $createdEntityPayload;
		}

		return new Payload($createdEntityPayload->getData(), $aggregatePayload->getStatus());
	}
1261232
public function createEvent() {
        $event = new Event($this->getContext(),null);
        $this->addChild($event);
        $qry = new CreateEntityQuery($event);
        $this->getContext()->addQuery($qry, $event);
        return $event;
    }
813420
private function createActionProcess() {
        /** @var CreateObject[] $createObjects */
        $createObjects = [];
        try {
            $params = new Params($this->request);
        } catch(Exception $e) {
            $this->handleError($e);
            return $createObjects;
        }
        $postParams = $params->getParams();
        if(!is_array($postParams)) {
            $postParams = [$postParams];
        }
        foreach($postParams as $postParam) {
            $createObject = new CreateObject($postParam);
            try {
                $entity = $this->createActionInternal($postParam);
                $createObject->setEntity($entity);

            } catch(Exception $e) {
                $this->handleError($e);
            } catch(ValidationException $e) {
                $this->handleValidationError($e);
            } catch(AclException $e) {
                $this->handleAclError($e);
            } catch(CatchableException $e) {
                $this->handleCatchableError($e);
            }
            $createObject->setStatusCode($this->getStatusCode());
            $createObject->setErrors($this->getErrors());
            $this->setErrors([]);
            $createObjects[] = $createObject;
        }
        return $createObjects;
    }
1125257
final public function create() {
        global $DB, $USER;

        if ($this->raw_get('id')) {
            // The validation methods rely on the ID to know if we're updating or not, the ID should be
            // falsy whenever we are creating an object.
            throw new coding_exception('Cannot create an object that has an ID defined.');
        }

        if (!$this->is_valid()) {
            throw new invalid_persistent_exception($this->get_errors());
        }

        // Before create hook.
        $this->before_create();

        // We can safely set those values bypassing the validation because we know what we're doing.
        $now = time();
        $this->raw_set('timecreated', $now);
        $this->raw_set('timemodified', $now);
        $this->raw_set('usermodified', $USER->id);

        $record = $this->to_record();
        unset($record->id);

        $id = $DB->insert_record(static::TABLE, $record);
        $this->raw_set('id', $id);

        // We ensure that this is flagged as validated.
        $this->validated = true;

        // After create hook.
        $this->after_create();

        return $this;
    }
759547
public function getRandom()
    {
        return empty($this->entities) ? null : $this->entities[array_rand($this->entities)];
    }
964827
protected function storeEntity()
    {
        $request = $this->getRequest();
        $id = $request->getParameter('id');
        // Try to find an existing instance of the entity.
        $entity = NULL;
        try {
            $entity = $this->getFactory()->findEntity($id);
        } catch (NotFoundException $exception) {
            // Not found? Create it.
            $className = $this->getFactory()->getEntitiesClassName();
            $entity = new $className(array(
                'id' => $id,
            ));
        }


        // Get the data from the request.
        $dataFromRequest = $this->getEntityDataFromRequest();
        if ($this->nullsIgnoredOnStore) {
            // Remove unspecified values, so that they are not modified.
            $dataFromRequest = array_filter(
                $dataFromRequest,
                function ($value) {
                    return !is_null($value);
                }
            );
        }
        // Update the product from the request data.
        $entity->update($dataFromRequest);
        // Store the entity.
        $entity->store();

        return $entity;
    }
1088115
public function create()
    {
        $serviceId = $this->container->getParameter('graviton.security.authentication.provider.model');
        $service = $this->container->get('graviton.security.authentication.provider.model.noop');

        if (!empty($serviceId) && $this->container->has($serviceId)) {
            $service = $this->container->get($serviceId);
        }

        return $service;
    }
1155709
public final function createEntity($arr_data = null)
    {
        $obj_entity = $this->obj_schema->createEntity();
        if(null !== $arr_data) {
            foreach ($arr_data as $str_property => $mix_value) {
                $obj_entity->__set($str_property, $mix_value);
            }
        }
        return $obj_entity;
    }
749880
private function entityFactory()
    {
        // this is a little tortuous but some constructor flows require the EntityManager
        // as this point in the refactor I'm unwilling to modify the constructor of the Entity
        // TODO. Fix this. Constructor injection
        $entity = $this->reflEntityClass->newInstanceWithoutConstructor();
        // add the entityManager
        if( $this->reflEntityManagerPropertyOfEntity ) {
            $this->reflEntityManagerPropertyOfEntity->setValue($entity, $this->entityManager);
        }
        // call the original constructor
        call_user_func_array( [$entity, '__construct'], func_get_args() );
        return $entity;
    }
341642
public function createQuery()
    {
        $query = $this->persistenceManager->createQueryForType($this->entityClassName);
        if ($this->defaultOrderings !== []) {
            $query->setOrderings($this->defaultOrderings);
        }
        return $query;
    }
748825
public function create()
    {
        $entityClass = $this->getEntityName();

        $reflection = new \ReflectionClass($entityClass);

        if ($reflection->isAbstract()) {
            throw RuntimeException::createAbstract($entityClass);
        }

        return new $entityClass();
    }