Skip to content

Commit

Permalink
Add Page::videos() and Page::media() methods
Browse files Browse the repository at this point in the history
  • Loading branch information
giuscris committed Oct 12, 2024
1 parent 49d88eb commit 0e18da0
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion formwork/src/Pages/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,29 @@ public function setLanguage(Language|string|null $language): void
}

/**
* Return a Files collection containing only images
* Return all page images
*/
public function images(): FileCollection
{
return $this->files()->filterBy('type', 'image');
}

/**
* Return all page videos
*/
public function videos(): FileCollection
{
return $this->files()->filterBy('type', 'video');
}

/**
* Return all page media files (images and videos)
*/
public function media(): FileCollection
{
return $this->files()->filterBy('type', fn (string $type) => in_array($type, ['image', 'video'], true));
}

/**
* Render page to string
*/
Expand Down

0 comments on commit 0e18da0

Please sign in to comment.