Bug fixes for media

This commit is contained in:
Matias Griese
2022-04-08 14:47:15 +03:00
parent 1b7531d111
commit f2bc892cb4
5 changed files with 16 additions and 5 deletions

View File

@@ -624,7 +624,7 @@ trait ImageMediaTrait
$file->touch();
}
return $this->generateCacheImage(GRAV_WEBROOT . '/' . $imageFile);
return $this->generateCacheImage(GRAV_WEBROOT . $imageFile);
}
/**

View File

@@ -194,7 +194,7 @@ abstract class AbstractMedia implements ExportInterface, MediaCollectionInterfac
public function current(): ?MediaObjectInterface
{
$instance = current($this->items);
if ($instance && !$instance instanceof MediaObjectInterface) {
if (false !== $instance && !$instance instanceof MediaObjectInterface) {
// Initialize media object.
$key = $this->key();
$this->items[$key] = $instance = $this->initMedium($key);

View File

@@ -47,7 +47,11 @@ abstract class LocalMedia extends AbstractMedia
*/
public function getPath(string $filename = null): ?string
{
return $this->path ? GRAV_WEBROOT . '/' . $this->path . ($filename ? '/' . $filename : '') : null;
if (!$this->path) {
return null;
}
return GRAV_WEBROOT . '/' . $this->path . ($filename ? '/' . $filename : '');
}
/**

View File

@@ -112,11 +112,18 @@ class Medium extends Data implements RenderableInterface, MediaFileInterface
*/
public function getMeta(): array
{
return [
// TODO: this may require some tweaking, works for now.
$meta = $this->metadata + ($this->meta ?? []) + [
'name' => $this->filename,
'mime' => $this->mime,
'size' => $this->size,
'width' => $this->width,
'height' => $this->height,
'orientation' => $this->orientation,
'modified' => $this->modified,
];
return array_filter($meta, static function($val) { return $val !== null; } );
}
/**

View File

@@ -936,7 +936,7 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
if ($media && !$media instanceof LocalMedia) {
$value = [];
foreach ($media->all() as $medium) {
$value[] = $medium->meta;
$value[] = $medium->getMeta();
}
}
}