Skip to content

Add missing field to StoriesRequest/Response "by_slugs" #80

@leewallis

Description

@leewallis

storyblokurl


Expected Behavior

When supplying the field "by_slugs" to a Stories Request, the parameter doesn't exist, but does exist on the Storyblok documentation.

Current Behavior

Currently, the Stories Request does not expose any way of querying a collection of stories by slugs only.

Steps to Reproduce

  1. The below code example will retrieve all stories with a full_slug starting with 'StoryFolderName'
use Storyblok\Api\StoriesApi;
use Storyblok\Api\StoryblokClient;
use Storyblok\Api\Domain\Value\Dto\Pagination;
use Storyblok\Api\Request\StoriesRequest;

$client = new StoryblokClient(/* ... */);

$storiesApi = new StoriesApi($client);
$response = $storiesApi->all(new StoriesRequest(
    language: 'de',
    pagination: new Pagination(page: 1, perPage: 30)
    startsWith => new Slug('StoryFolderName/'),
));
  1. The below code, does not retrieve any stories by the slugs supplied
use Storyblok\Api\StoriesApi;
use Storyblok\Api\StoryblokClient;
use Storyblok\Api\Domain\Value\Dto\Pagination;
use Storyblok\Api\Domain\Value\Slug\SlugCollection;
use Storyblok\Api\Request\StoriesRequest;

$client = new StoryblokClient(/* ... */);

$storiesApi = new StoriesApi($client);
$response = $storiesApi->all(new StoriesRequest(
    language: 'de',
    pagination: new Pagination(page: 1, perPage: 30)
    bySlugs => new SlugCollection(['StoryFolderName/*', 'StoryFolderName2/*']),
));

Proposed Fix

Add in the following code to StoriesRequest class construct:
public ?SlugCollection $bySlugs = new SlugCollection(),

The SlugCollection is used on the exclude_slugs parameter, which in essence, is the exact opposite of the by_slugs functionality.

And add in the follow code to the toArray method:

if ($this->bySlugs->count() > 0) {
    $array['by_slugs'] = $this->bySlugs->toString();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions