Extracts the string to be saved to the model field from an entity

@param EntityInterface $entity Entity
@return string
161491
public function getEntityModel(EntityInterface $entity): string
    {
        $source = $entity->source();
        if (substr($source, -5) == 'Table') {
            $source = substr($source, 0, -5);
        }

        return $source;
    }
17009
public static function getStringId(ResourceEntityInterface $entity = NULL)
    {
        return is_null($entity)
            ? NULL
            : (string) $entity->getId();
    }
24317
protected function getConditions(EntityInterface $entity)
    {
        $parts = explode('\\', $this->getEntityDescriptor()->className());
        $property = lcfirst(array_pop($parts));
        return [
            "rel.{$this->getForeignKey()} = :{$property}" => [
                ":{$property}" => $entity->getId()
            ]
        ];
    }
921102
public function editButton(EntityInterface $entity, array $options = []): string
    {
        $options = Hash::merge([
            'url' => null,
            'title' => __d('ck_tools', 'edit'),
            'icon' => 'fa fa-pencil',
            'escape' => false,
            'class' => 'btn btn-default btn-xs btn-edit',
        ], $options);

        $url = $options['url'];
        $title = $options['title'];
        $icon = $options['icon'];
        unset($options['url'], $options['title'], $options['icon']);
        if (!$url) {
            // phpcs:ignore
            list($plugin, $controller) = pluginSplit($entity->source());
            $url = [
                'plugin' => $this->_View->request->plugin,
                'controller' => $controller,
                'action' => 'edit',
                $entity->id,
            ];
            $url = $this->augmentUrlByBackParam($url);
        }
        if ($icon) {
            $title = '<i class="' . $icon . '"></i> ' . '<span class="button-text">' . $title . '</span>';
            $options['escape'] = false;
        }

        return $this->Html->link($title, $url, $options);
    }
878442
public function encryptEntity(EntityInterface $entity): EntityInterface
    {
        if (!$this->isEncryptable($entity)) {
            return $entity;
        }

        $fields = $this->getFields();
        $encryptionKey = $this->getConfig('encryptionKey');
        $base64 = $this->getConfig('base64');
        $table = $this->getTable();

        $patch = [];
        foreach ($fields as $name => $field) {
            if (!$table->hasField($name)) {
                continue;
            }
            $value = $entity->get($name);
            if ($value === null || is_resource($value)) {
                continue;
            }
            $encrypted = Security::encrypt($value, $encryptionKey);
            if ($base64 === true) {
                $encrypted = base64_encode($encrypted);
            }
            $patch[$name] = $encrypted;
        }

        if (!empty($patch)) {
            $accessible = array_fill_keys(array_keys($patch), true);
            $entity = $table->patchEntity($entity, $patch, [
                'accessibleFields' => $accessible,
            ]);
        }

        return $entity;
    }
171179
public function validate(EntityInterface $entity)
    {
        if (!$entity instanceof Notification) {
            throw new Exception('Entity to validate must be an instance of "Notification"');
        }

        $this->validateMessage($entity->getMessage());
        $this->validateLevel($entity->getLevel());
        $this->validateNamespace($entity->getNamespace());
        $this->validateOrigin($entity->getOrigin());
        $this->validateReportedAt($entity->getReportedAt());

        $errors = $this->getErrors();
        return empty($errors);
    }
144114
public function getEntityLabel(EntityInterface $entity) {
    $profiles = $this->entityTypeManager->getStorage('profile')
      ->loadByProperties([
        'uid' => $entity->field_account->target_id,
      ]);

    /** @var \Drupal\profile\Entity\ProfileInterface $profile */
    $profile = reset($profiles);

    // It must be a Guest so we pick the name values we can get.
    if (!$profile) {
      $name = '';
      $first_name = $entity->get('field_first_name')->getValue()[0]['value'];
      $last_name = $entity->get('field_last_name')->getValue()[0]['value'];
      if (!empty($first_name)) {
        $name .= $first_name;
        $name .= ' ';
      }
      if (!empty($last_name)) {
        $name .= $last_name;
      }

      return $name;
    }

    /** @var \Drupal\Core\StringTranslation\TranslatableMarkup $label */
    $label = $profile->label();

    return $label->getArguments()['@name'];
  }
177492
protected function _validation(EntityInterface $entity)
    {
        $validator = new Validator();
        $hasErrors = false;

        foreach ($this->_attributesForEntity($entity) as $attr) {
            $field = $this->_prepareMockField($entity, $attr);
            $result = $field->validate($validator);

            if ($result === false) {
                $this->attachEntityFields($entity);

                return false;
            }

            $errors = $validator->errors($entity->toArray(), $entity->isNew());
            $entity->errors($errors);

            if (!empty($errors)) {
                $hasErrors = true;
                if ($entity->has('_fields')) {
                    $entityErrors = $entity->errors();
                    foreach ($entity->get('_fields') as $field) {
                        $postData = $entity->get($field->name);
                        if (!empty($entityErrors[$field->name])) {
                            $field->set('value', $postData);
                            $field->metadata->set('errors', (array)$entityErrors[$field->name]);
                        }
                    }
                }
            }
        }

        return !$hasErrors;
    }
1222239
public static function fetchArray(EntityInterface $entity): array
    {
        if(!defined(get_class($entity)."::FIELDS"))
            return [];
        elseif(is_array($entity::FIELDS))
            $fields = $entity::FIELDS;
        else
            $fields = json_decode($entity::FIELDS, true);

        $ret = [];
        foreach($fields as $key=>$value) {
            $ret[
                \Stringy\StaticStringy::upperCamelize($key)
            ] = $value;
        }
        
        return $ret;
    }
674219
public function decode(EntityInterface $entity) {
		$idField = $this->_primaryKey;
		$hashid = $entity->get($idField);
		if (!$hashid) {
			return false;
		}

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

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

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

		return true;
	}
1324198
public function extract($entity)
    {
        //if entity is required then delete the entity
        $property = $this->getRepository()
                         ->getDescription()
                         ->getProperty($this->_property);
                         
        if ($property->isRequired()) {
            $entity->delete();
        } else {
            $entity->set($this->_property, null);
        }
    }
288064
public function extract($entity)
    {
        if ($entity->persisted()) {
            $entity->delete()->save();
        }

        $this->_space->extractEntity($entity);
    }
216686
private function __getFileName($fileInfo, EntityInterface $entity, $id = 0)
    {
        if (!file_exists(Configure::read('Attachments.path') . $entity->source() . '/' . $entity->id . '/' . $fileInfo['basename'])) {
            return $fileInfo;
        }
        $fileInfo['basename'] = $fileInfo['filename'] . ' (' . ++$id . ').' . $fileInfo['extension'];
        return $this->__getFileName($fileInfo, $entity, $id);
    }
215869
public function getSaverForEntity(
        EntityInterface $entity
    ): EntitySaverInterface {
        $fqn = $this->getEntityNamespace($entity);

        return $this->getSaverForEntityFqn($fqn);
    }
618642
public static function getPHPFormat(EntityInterface $field)
    {
        $settings = $field->metadata->settings;
        $format = empty($settings['format']) ? 'yy-mm-dd' : $settings['format'];
        if ($settings['timepicker']) {
            $format .= ' ';
            if (empty($settings['time_format'])) {
                $format .= 'H:mm';
                $format .= empty($settings['time_seconds']) ?: ':ss';
            } else {
                $format .= $settings['time_format'];
            }
        }

        return static::normalizeFormat($format);
    }
1309042
protected function getCurrent(EntityInterface $entity) {
		$conditions = $this->buildConditions($entity);

		return $this->_table->find()
			->where($conditions)
			->first();
	}
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);
    }