Generates image version path / url / filename, etc.

@param \Cake\Datasource\EntityInterface $entity Image entity.
@param string $version Version name
@param string $type Path type
@param array $options PathBuilder options
@return string
518548
public function imageVersionPath(EntityInterface $entity, $version, $type = 'fullPath', $options = []) {
		if (empty($version)) {
			// Temporary fix for GH #116, this should be fixed in the helper and by
			// introducing getting an URL by event as well in the long run.
			return $this->pathBuilder()->url($entity, $options);
		}

		$hash = $this->getImageVersionHash($entity->model, $version);

		$output = $this->_defaultOutput + ['format' => $entity->extension];
		$operations = $this->_imageVersions[$entity->model][$version];
		if (isset($operations['_output'])) {
			$output = $operations['_output'] + $output;
		}

		$options += [
			'preserveExtension' => false,
			'fileSuffix' => '.' . $hash . '.' . $output['format']
		];

		return $this->pathBuilder()->{$type}($entity, $options);
	}
266086
public static function path(string $dirname, string $filename, string $extension, string $version = ''): string
    {
        $path = self::normalizeDirname($dirname);
        $path .= '/' . $filename . '.' . $extension;
        $path .= !empty($version) ? self::VERSION_SEPARATOR . $version : '';

        return ltrim($path, '/');
    }
394279
public function modelHistoryArea(EntityInterface $entity, array $options = []): string
    {
        $options = Hash::merge([
            'showCommentBox' => false,
            'showFilterBox' => false,
            'columnClass' => 'col-md-12',
            'includeAssociated' => false
        ], $options);

        $page = 1;
        $limit = TableRegistry::get($entity->source())->getEntriesLimit();

        $modelHistory = TableRegistry::get('ModelHistory.ModelHistory')->getModelHistory($entity->source(), $entity->id, $limit, $page, [], $options);

        $entries = TableRegistry::get('ModelHistory.ModelHistory')->getModelHistoryCount($entity->source(), $entity->id, [], $options);
        $showNextEntriesButton = $entries > 0 && $limit * $page < $entries;
        $showPrevEntriesButton = $page > 1;

        $contexts = [];
        if (method_exists($entity, 'getContexts')) {
            $contexts = $entity::getContexts();
        }

        return $this->_View->element('ModelHistory.model_history_area', [
            'modelHistory' => $modelHistory,
            'showNextEntriesButton' => $showNextEntriesButton,
            'showPrevEntriesButton' => $showPrevEntriesButton,
            'page' => $page,
            'model' => $entity->source(),
            'foreignKey' => $entity->id,
            'limit' => $limit,
            'searchableFields' => TableRegistry::get($entity->source())->getTranslatedFields(),
            'showCommentBox' => $options['showCommentBox'],
            'showFilterBox' => $options['showFilterBox'],
            'columnClass' => $options['columnClass'],
            'includeAssociated' => $options['includeAssociated'],
            'contexts' => $contexts
        ]);
    }
777495
public function path(EntityInterface $entity, array $options = []) {
		$config = array_merge($this->getConfig(), $options);
		$path = '';
		$path = $this->_pathPrefix($entity, $path, $config);
		$path = $this->_path($entity, $path, $config);
		$path = $this->_pathSuffix($entity, $path, $config);

		return $this->ensureSlash($path, 'after');
	}
616872
public function getImageVersionHash($model, $version) {
		if (empty($this->_imageVersionHashes[$model][$version])) {
			throw new RuntimeException(sprintf('Version "%s" for identifier "%s" does not exist!', $version, $model));
		}

		return $this->_imageVersionHashes[$model][$version];
	}
14277
protected function _pathPrefix(EntityInterface $entity, $path, array $config) {
		return $this->_pathPreAndSuffix($entity, $path, $config, 'prefix');
	}
205836
protected function _getFileName($entity, $field, $options = [])
    {
        $_options = [
        ];

        $options = Hash::merge($_options, $options);

        $config = $this->config($field);

        $_upload = $this->_uploads[$field];

        $fileInfo = explode('.', $_upload['name']);
        $extension = end($fileInfo);

        $fileName = $config['fileName'];

        $replacements = [
            '{ORIGINAL}' => $_upload['name'],
            '{field}' => $entity->get($config['field']),
            '{extension}' => $extension,
            '{DS}' => DIRECTORY_SEPARATOR,
            '//' => DIRECTORY_SEPARATOR,
            '/' => DIRECTORY_SEPARATOR,
            '\\' => DIRECTORY_SEPARATOR,
        ];

        $builtFileName = str_replace(array_keys($replacements), array_values($replacements), $fileName);

        return $builtFileName;
    }
878560
protected function _afterRegister(EntityInterface $entity, $options) {
		if ($entity) {
			if ($options['emailVerification'] === true) {
				$this->sendVerificationEmail($entity, [
					'to' => $entity->get($this->_field('email'))
				]);
			}
		}

		return $entity;
	}
258058
public function slug(EntityInterface $entity, array $options = []) {
		$overwrite = isset($options['overwrite']) ? $options['overwrite'] : $this->_config['overwrite'];
		if (!$overwrite && $entity->get($this->_config['overwriteField'])) {
			$overwrite = true;
		}
		if ($overwrite || $entity->isNew() || !$entity->get($this->_config['field'])) {
			$slug = [];
			foreach ((array)$this->_config['label'] as $v) {
				$v = $entity->get($v);
				if ($v !== null && $v !== '') {
					$slug[] = $v;
				}
			}
			$slug = implode($slug, $this->_config['separator']);
			$slug = $this->generateSlug($slug, $entity);
			$entity->set($this->_config['field'], $slug);
		}
	}
1324053
public function removeImageVersions(EntityInterface $entity, array $versions, array $options = []) {
		$this->_checkImageVersions($entity->model, $versions);

		$result = [];
		foreach ($versions as $version) {
			$hash = $this->getImageVersionHash($entity->model, $version);
			$path = $this->pathBuilder()->fullPath($entity, ['fileSuffix' => '.' . $hash]);
			$result[$version] = [
				'status' => 'success',
				'hash' => $hash,
				'path' => $path
			];
			try {
				$this->getStorageAdapter($entity->adapter)->delete($path);
			} catch (\Exception $e) {
				$result[$version]['status'] = 'error';
				$result[$version]['error'] = $e->getMessage();
			}
		}

		return $result;
	}
883166
public function setVersion(ResourceInterface $resource, $version) {
		if ($resource instanceof ResourceDocument) {
			$resource->addMeta($this->getKeyword('version'), $version, $level=Document::LEVEL_RESOURCE);
		}
		else {
			$resource->addMeta($this->getKeyword('version'), $version);
		}
	}
384615
public static Optional<MappingColumn> getVersionMappingColumn(final Class<?> entityType) {
		return Arrays.stream(getMappingColumns(entityType))
				.filter(MappingColumn::isVersion)
				.findFirst();
	}
68408
public static function checkAliasVersion(AssetTypeInterface $assetType, $dependency, $version)
    {
        $pos = strpos($version, '#');

        if ($pos > 0 && !preg_match('{[0-9a-f]{40}$}', $version)) {
            $dependency = substr($version, 0, $pos);
            $version = substr($version, $pos);
            $searchVerion = substr($version, 1);

            if (false === strpos($version, '*') && Validator::validateTag($searchVerion, $assetType)) {
                $dependency .= '-'.str_replace('#', '', $version);
            }
        }

        return array($dependency, $version);
    }
759134
public function removeAllImageVersions(EntityInterface $entity, array $options = []) {
		return $this->removeImageVersions(
			$entity,
			$this->getAllVersionsKeysForModel($entity->get('model')),
			$options
		);
	}
215700
public function getEventType(EntityInterface $entity, ArrayObject $options, $map = null)
    {
        $result = 'Json::' . $entity->getSource() . '::Default';

        if (! empty($options['event_type'])) {
            $result = $options['event_type'];
        }

        return $result;
    }
897170
public function getThumbnail(FileStorage $entity, string $version) : string
    {
        $versions = (array)Configure::read('FileStorage.imageHashes.file_storage');
        if (empty($versions)) {
            return str_replace(DS, '/', $entity->get('path'));
        }

        if (! array_key_exists($version, $versions)) {
            return str_replace(DS, '/', $entity->get('path'));
        }

        $path = in_array(strtolower($entity->get('extension')), self::IMAGE_EXTENSIONS) ?
            $this->getImagePath($entity, $version) :
            $this->getIconPath($entity, $version);

        return str_replace(DS, '/', $path);
    }
1075048
protected function persistEntity(EntityInterface $entity, array $data, array $options = []) : ?Response
    {
        $table = $this->loadModel();
        Assert::isInstanceOf($table, Table::class);

        $options = array_merge($options, ['lookup' => true]);
        $entity = $table->patchEntity($entity, $data, $options);

        $saved = false;
        try {
            $saved = $table->save($entity);
        } catch (PDOException $e) {
            Log::error($e->getMessage());
        }

        if ($entity->getErrors()) {
            Log::warning((string)json_encode($entity->getErrors()));
        }

        if (! $saved) {
            $this->Flash->error((string)__('The record could not be saved, please try again.'));
        }

        if ($saved) {
            $this->Flash->success((string)__('The record has been saved.'));

            $primaryKey = $table->getPrimaryKey();
            if (! is_string($primaryKey)) {
                throw new UnsupportedPrimaryKeyException();
            }

            // handle file uploads if found in the request data
            $fileUpload = new FileUpload($table);
            $fileUpload->link(
                $entity->get($primaryKey),
                (array)$this->request->getData()
            );

            $url = [];
            if ($table instanceof Table) {
                $url = $table->getParentRedirectUrl($table, $entity);
            }
            $url = ! empty($url) ? $url : ['action' => 'view', $entity->get($primaryKey)];

            return $this->redirect($url);
        }

        return null;
    }