Create or Update an entry

@param  integer $entityId
@param  string $entityType
@param  string $lang
@param  array $payload

@return boolean
176493
public function createOrUpdate($entityId, $entityType, $lang, $payload)
    {
        $translation = $this->model->firstOrCreate([
            'entity_id' => $entityId,
            'entity_type' => $entityType,
            'language' => $lang,
        ]);

        unset($payload['_method']);
        unset($payload['_token']);

        $translation->entity_data = json_encode($payload);

        return $translation->save();
    }
456740
public function afterCreate($payload)
    {
        if (config('cms.auto-translate', false)) {
            $entry = $payload->toArray();

            unset($entry['created_at']);
            unset($entry['updated_at']);
            unset($entry['translations']);
            unset($entry['is_published']);
            unset($entry['published_at']);
            unset($entry['id']);

            foreach (config('cms.languages') as $code => $language) {
                if ($code != config('cms.default-language')) {
                    $translateClient = new TranslateClient(config('cms.default-language'), $code);
                    $translation = [
                        'lang' => $code,
                        'template' => 'show',
                    ];

                    foreach ($entry as $key => $value) {
                        $translation[$key] = $value;

                        if (!empty($value)) {
                            $translation[$key] = json_decode(json_encode($translateClient->translate(strip_tags($value))));
                        }
                    }

                    // not the biggest fan of this but it works
                    if (empty($translation['blocks'])) {
                        $translation['blocks'] = "{}";
                    }

                    if (isset($translation['url'])) {
                        $translation['url'] = app(CmsService::class)->convertToURL($translation['url']);
                    }

                    $entityId = $payload->id;
                    $entityType = get_class($payload);
                    app(TranslationRepository::class)->createOrUpdate($entityId, $entityType, $code, $translation);
                }
            }
        }
    }
1074352
public function bind(array $payload=null)
    {
        $bound = false;
        $this->_boundEntities = array();

        if (!is_null($payload)
            && isset($payload[$this->getName()])
            && $this->validateSynchronizerToken($payload)
        ) {
            $this->logger->debug('start binding form', array('name' => $this->getName(), 'payload' => $payload));

            $propertyMapper = new PropertyMapper();

            $formOptions = $this->buildFormOptions($payload);

            if ($this->getEntityContainerMap()->count() > 0) {
                $entityContainers = $this->getEntityContainerMap()->getAll();

                /**
                 * @var $entityContainer    \Naucon\Form\Mapper\EntityContainerInterface
                 */
                foreach ($entityContainers as $entityContainer) {
                    $name = $entityContainer->getName();

                    if (is_null($formOptions) || in_array($name, $formOptions)) {
                        $this->_formOptionValues[] = $name;
                        if (isset($payload[$this->getName()][$name])) {
                            $formData = $payload[$this->getName()][$name];

                            $propertyMapper->mapFormToData($entityContainer->getEntity(), $formData);
                            $this->addBoundEntity($entityContainer->getEntity());

                            // postbind hook
                            $this->logger->debug('invoke form postbind hook', array('name' => $this->getName(), 'entity' => $entityContainer->getName()));
                            $entityContainer->invokeHook('postbindHook');

                        }
                    } elseif (!is_null($formOptions) && !in_array($name, $formOptions)) {
                        $entityContainer->setValidate(false);
                    }
                }
            }

            switch($this->configuration->get('collection_type'))
            {
                case self::COLLECTION_TYPE_ONE:
                    if (count($this->getBoundEntities())==1) {
                        $bound = true;
                    }
                    break;
                case self::COLLECTION_TYPE_MANY:
                    if (count($this->getBoundEntities()) == count($this->_formOptionValues)) {
                        $bound = true;
                    }
                    break;
                case self::COLLECTION_TYPE_ALL:
                    if ($this->getEntityContainerMap()->count() == count($this->getBoundEntities())) {
                        $bound = true;
                    }
                    break;
                case self::COLLECTION_TYPE_ANY:
                    if ($this->getEntityContainerMap()->count() > 0) {
                        $bound = true;
                    }
                    break;
            }

        }

        $this->setBound($bound);

        $this->logger->debug('execute post binding form', array('name' => $this->getName()));
        $this->postBind();

        if ($this->isBound()) {
            $this->logger->debug('finished binding form successful', array('name' => $this->getName()));
        } else {
            $this->logger->debug('finished binding form failed', array('name' => $this->getName()));
        }
        return $this->isBound();
    }
427142
public function createWidget($mode, $type, $slotId, View $view, $entity, $position, $widgetReference, $quantum)
    {
        //services
        $formErrorHelper = $this->formErrorHelper;
        $request = $this->getRequest();

        if ($view instanceof VirtualBusinessPage) {
            $this->virtualToBpTransformer->transform($view);
        }
        //create a new widget
        $widget = $this->widgetHelper->newWidgetInstance($type, $view, $slotId, $mode);

        $form = $this->widgetFormBuilder->callBuildFormSwitchParameters($widget, $view, $entity, $position, $widgetReference, $slotId, $quantum);

        $noValidate = $request->query->get('novalidate', false);

        $form->handleRequest($request);
        if ($noValidate === false && $form->isValid()) {
            if (!$view->getId()) {
                //create a view for the business entity instance if we are currently on a virtual one
                $this->entityManager->persist($view);
            }

            //get the widget from the form
            $widget = $form->getData();

            //update fields of the widget
            $widget->setBusinessEntityId($entity);

            //persist the widget
            $this->entityManager->persist($widget);
            $this->entityManager->flush();

            $this->widgetMapManager->insert($widget, $view, $slotId, $position, $widgetReference);

            $this->entityManager->persist($view);
            $this->entityManager->flush();

            $widget->setCurrentView($view);

            $event = new WidgetFlushedEvent($widget);
            $this->eventDispatcher->dispatch(VictoireCmsEvents::WIDGET_POST_FLUSH, $event);
            $this->eventDispatcher->dispatch(VictoireCmsEvents::WIDGET_POST_FLUSH.'_'.strtoupper($type), $event);

            $this->widgetMapBuilder->build($view);

            //get the html for the widget
            $htmlWidget = $this->widgetRenderer->renderContainer($widget, $view);

            $response = [
                'success'  => true,
                'widgetId' => $widget->getId(),
                'html'     => $htmlWidget,
            ];
        } else {
            //get the errors as a string
            $response = [
                'success' => false,
                'message' => $noValidate === false ? $formErrorHelper->getRecursiveReadableErrors($form) : null,
                'html'    => $this->widgetFormBuilder->renderNewForm($form, $widget, $slotId, $view, $quantum, $entity),
            ];
        }

        return $response;
    }
960066
async function createEntity(projectId, entityTypeId, entityValue, synonyms) {
  // [START dialogflow_create_entity]
  // Imports the Dialogflow library
  const dialogflow = require('dialogflow');

  // Instantiates clients
  const entityTypesClient = new dialogflow.EntityTypesClient();

  // The path to the agent the created entity belongs to.
  const agentPath = entityTypesClient.entityTypePath(projectId, entityTypeId);

  const entity = {
    value: entityValue,
    synonyms: synonyms,
  };

  const createEntitiesRequest = {
    parent: agentPath,
    entities: [entity],
  };

  const [response] = await entityTypesClient.batchCreateEntities(
    createEntitiesRequest
  );
  console.log('Created entity type:');
  console.log(response);
  // [END dialogflow_create_entity]
}
98583
protected function buildKey(
        $entityType,
        $entityId,
        $entityField,
        $locale
    ) {
        return $this->cachePrefix . '_' .
        $entityType . '_' .
        $entityId . '_' .
        $entityField . '_' .
        $locale;
    }
612004
@Transactional
  @PostMapping(value = "/{entityTypeId}/{id}", params = "_method=PUT")
  @ResponseStatus(OK)
  public void updatePost(
      @PathVariable("entityTypeId") String entityTypeId,
      @PathVariable("id") String untypedId,
      @RequestBody Map<String, Object> entityMap) {
    updateInternal(entityTypeId, untypedId, entityMap);
  }
616531
public function addUserTypeEntitiesIfNotExists($entityId, array $fields) {
        foreach ($fields as $field) {
            $this->addUserTypeEntityIfNotExists($entityId, $field["FIELD_NAME"], $field);
        }
    }
1008660
def create_entity_type(project_id, display_name, kind):
    """"""
    import dialogflow_v2 as dialogflow
    entity_types_client = dialogflow.EntityTypesClient()

    parent = entity_types_client.project_agent_path(project_id)
    entity_type = dialogflow.types.EntityType(
        display_name=display_name, kind=kind)

    response = entity_types_client.create_entity_type(parent, entity_type)

    print('Entity type created: \n{}'.format(response))
480539
protected function __create(array $data, $index, $type, $id = null, array $parameters = []) {
        $parameters+=["api" => "create"];
        $api = strtolower($parameters["api"]) == "index" ? "index" : "create";
        unset($parameters["api"]);
        $result = $this->client->$api([
            'index' => $index,
            'type' => $type,
            'body' => $data] + ($id ? ['id' => $id] : []) + $parameters);
        if (array_key_exists('_shards', $result) && array_key_exists('failed', $result['_shards']) && $result['_shards']['failed'] > 0) {
            throw new Exception('Failed to create the document. Serialized results: ' + json_encode($result));
        } else {
            $result = $this->__find($result['_index'], $result['_type'], $result['_id']);
        }
        return $result;
    }
1355019
public function setIndex($text, $entity, $entity_id, $language)
    {
        $this->deleteIndex($entity, $entity_id, $language);

        if (empty($text)) {
            return false;
        }

        return $this->addIndex($text, $entity, $entity_id, $language);
    }
991827
public function entity($entityType, $id, $timestamp)
	{
		$params = array(
			'type_name' => $entityType,
			'id'        => $id,
			'timestamp' => $timestamp,
		);

		return $this->post('versions/entity', $params);
	}
1347765
protected function performInsert($sessionId, $payload)
    {
        try {
            return $this->getQuery()->insert(Arr::set($payload, 'id', $sessionId));
        } catch (QueryException $e) {
            $this->performUpdate($sessionId, $payload);
        }
    }
1007184
public function getById($entityType, $id, array $params = [], $version = null)
    {
        if (empty($id)) {
            throw new Exception('Id is empty');
        }

        if (!static::isIdValid($id)) {
            throw new Exception('Id is invalid, please use a correctly formatted id');
        }

        return ($version === null)
            ? $this->doGet($entityType . '.json/crud/' . $id, $params)
            : $this->doGet($entityType . '.json/history/' . $id . '/' . $version, $params);
    }
399291
public function update($widget, $payload)
    {
        $payload['name'] = htmlentities($payload['name']);

        if (!empty($payload['lang']) && $payload['lang'] !== config('cms.default-language', 'en')) {
            return $this->translationRepo->createOrUpdate($widget->id, 'Grafite\Cms\Models\Widget', $payload['lang'], $payload);
        } else {
            unset($payload['lang']);

            return $widget->update($payload);
        }
    }
1334477
public function deleteTranslation($language, Entity $entity = null, Repository $repository = null)
    {
        if (!$entity) {
            $entity = $this->getEntity();
        }

        if (!$repository) {
            $repository = $entity->getRepository();
        }

        $repository = $repository->aliased('write');

        $deleted = $repository->deleteTranslation($this, $entity, $language);

        return $deleted;
    }
1220839
public function createEntity(string $entity_id, array $parents)
    {
        $entity = new Entity($this, $entity_id, $parents);
        return $entity;
    }