Sets up hashid for model.

@param \Cake\Datasource\EntityInterface $entity The entity that is going to be saved
@return bool True if save should proceed, false otherwise
542825
public function encode(EntityInterface $entity) {
		$idField = $this->_primaryKey;
		$id = $entity->get($idField);
		if (!$id) {
			return false;
		}

		$field = $this->_config['field'];
		if (!$field) {
			return false;
		}

		$hashid = $this->encodeId($id);

		$entity->set($field, $hashid);
		$entity->setDirty($field, false);

		return true;
	}
594296
public function afterSave(Event $event, EntityInterface $entity) {
		if ($this->_checkEvent($event) && $entity->isNew()) {
			$fileField = $this->getConfig('fileField');

			$hash = StorageUtils::getFileHash($entity->get($fileField)['tmp_name']);
			$path = $this->pathBuilder()->fullPath($entity);

			$entity->set('hash', $hash);
			$entity->set('path', $path);

			if (!$this->_storeFile($event)) {
				return;
			}

			$event->result = true;
			$event->stopPropagation();
		}
	}
310461
public function saveEntity(EntityInterface $entity)
    {
        $check = $this->storage->fetchEntityById($entity->getIdentifier());

        if ($check) {
            return $this->storage->updateEntity($entity);
        } else {
            return $this->storage->insertEntity($entity);
        }
    }
1042039
public function validate(EntityInterface $entity)
    {
        if (!$entity instanceof ApplicationGroup) {
            throw new Exception(
                sprintf('The Entity to validate must be an instance of %s', Role::class)
            );
        }

        $this->validateName($entity->getName());
        $errors = $this->getErrors();

        return empty($errors);
    }
379026
public function post(EntityInterface $entity)
    {
        $pk = (string)TableRegistry::get($entity->source())->primaryKey();
        if (empty($this->_controller->request->data['comment']) ||
            $this->config('settings.visibility') !== 1 ||
            !$entity->has($pk)
        ) {
            return false;
        }

        $this->_controller->loadModel('Comment.Comments');
        $data = $this->_getRequestData($entity);
        $this->_controller->Comments->validator('commentValidation', $this->_createValidator());
        $comment = $this->_controller->Comments->newEntity($data, ['validate' => 'commentValidation']);
        $errors = $comment->errors();
        $errors = !empty($errors);

        if (!$errors) {
            $persist = true;
            $saved = true;
            $this->_controller->Comments->addBehavior('Tree', [
                'scope' => [
                    'entity_id' => $data['entity_id'],
                    'table_alias' => $data['table_alias'],
                ]
            ]);

            if ($this->config('settings.use_akismet')) {
                $newStatus = $this->_akismetStatus($data);
                $comment->set('status', $newStatus);

                if ($newStatus == 'spam' &&
                    $this->config('settings.akismet_action') != 'mark'
                ) {
                    $persist = false;
                }
            }

            if ($persist) {
                $saved = $this->_controller->Comments->save($comment);
            }

            if ($saved) {
                $this->_afterSave($comment);

                return true; // all OK
            } else {
                $errors = true;
            }
        }

        if ($errors) {
            $this->_setErrors($comment);
            $errorMessage = $this->config('errorMessage');
            if (is_callable($errorMessage)) {
                $errorMessage = $errorMessage($comment, $this->_controller);
            }
            $this->_controller->Flash->danger($errorMessage, ['key' => 'commentsForm']);
        }

        return false;
    }
138626
public function createDtoFromEntity(EntityInterface $entity)
    {
        $this->resetCreationTransaction();
        $dsm     = $entity::getDoctrineStaticMeta();
        $dtoFqn  = $this->namespaceHelper->getEntityDtoFqnFromEntityFqn($dsm->getReflectionClass()->getName());
        $dto     = new $dtoFqn();
        $setters = $dsm->getSetters();
        foreach ($setters as $getterName => $setterName) {
            $dto->$setterName($entity->$getterName());
        }

        return $dto;
    }
840021
public function add(IEntity $entity) : bool
    {
        $class = $this->entityType;

        if(!($entity instanceof $class)) {
            throw TypeMismatchException::argument(__METHOD__, 'entity', $class, $entity);
        }

        if ($entity->getId() === null) {
            $this->nullIdEntities[] = $entity;
            return true;
        }

        $id = $entity->getId();

        if ($this->has($id)) {
            return false;
        }

        $this->entities[$id] = $entity;

        return true;
    }
1136751
public function delete(EntityInterface $entity)
    {
        return $this->infakt->delete($this->getServiceName().'/'.$entity->getId().'.json');
    }
1223725
protected function afterSave(EntityInterface $entity): void
    {
        $argv = compact('entity');
        $argv = $this->getEventManager()->prepareArgs($argv);

        $this->getEventManager()->trigger("{$this->event_prefix}_save_after", $this, $argv);
        if ($this->entity_event_prefix) {
            $this->getEventManager()->trigger("{$this->entity_event_prefix}_save_after", $this, $argv);
        }
    }
507803
protected function prepareEntityForPersist(AbstractEntity $entity): bool
    {
        if ($entity instanceof TimestampableInterface) {
            $entity->setEditionDate(new DateTime());
        }

        return true;
    }
985453
protected function insertIntoDatabase(Entity $entity)
    {
        $primaryKey = $this->mapper->getPrimaryKey($this->getTable());
        $values = $entity->getModifiedRowData();
        $this->connection->query(
            'INSERT INTO %n %v',
            $this->getTable(),
            $values
        );
        return isset($values[$primaryKey]) ? $values[$primaryKey] : $this->connection->getInsertId();
    }
313830
public function supportsEntity(EntityInterface $entity): bool
    {
        foreach ($this->mappers as $mapper) {
            if ($mapper->supportsEntity($entity)) {
                return true;
            }
        }

        return false;
    }
700607
public function save($entity) {
        $this->load();
        $mapper = MapperBuilder::buildFromClassName($this->mapping, get_class($entity));
        if (is_null($entity->getId())) {
            $affectedRows = $this->insertEntity($entity, $mapper);
        } else {
            $affectedRows = $this->updateEntity($entity, $mapper);
        }
        if (0 < $affectedRows) {
            return true;
        } else {
            return false;
        }
    }
441651
public function getVersionId(EntityInterface $entity)
    {
        $table = TableRegistry::get($this->_config['versionTable']);
        $preexistent = $table->find()
            ->select(['version_id'])
            ->where([
                    'model' => $this->_config['referenceName']
                ] + $this->_extractForeignKey($entity))
            ->order(['id desc'])
            ->limit(1)
            ->enableHydration(false)
            ->toArray();

        return Hash::get($preexistent, '0.version_id', 0);
    }
263484
protected function removeFromOthers(EntityInterface $entity) {
		$field = $this->getConfig('field');
		$id = $entity->get('id');
		$conditions = $this->buildConditions($entity);
		$this->_table->updateAll([$field => false], ['id !=' => $id] + $conditions);
	}
943935
public function afterSave(Event $event, EntityInterface $entity, ArrayObject $options)
    {
        if (!$this->config('status')) {
            return true;
        }

        // as we don't know entity's ID on beforeSave, we must delay values storage;
        // all this occurs inside a transaction so we are safe
        if (!empty($this->_cache['createValues'])) {
            foreach ($this->_cache['createValues'] as $valueEntity) {
                $valueEntity->set('entity_id', $this->_toolbox->getEntityId($entity));
                $valueEntity->unsetProperty('id');
                TableRegistry::get('Eav.EavValues')->save($valueEntity);
            }
            $this->_cache['createValues'] = [];
        }

        foreach ($this->_attributesForEntity($entity) as $attr) {
            $field = $this->_prepareMockField($entity, $attr);
            $field->afterSave();
        }

        if ($this->config('cacheMap')) {
            $this->updateEavCache($entity);
        }

        return true;
    }
701977
public function indexEntity(SearchableEntityInterface $entity)
    {
        foreach ($this->locales as $locale) {
            $this->addEntityToIndex($entity, $locale);
        }

        if (!empty($this->documents)) {
            $response = $this->searchProvider->addDocuments($this->documents);
            $this->documents = [];
        }
    }