Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,14 @@ parameters appended to the URL):
Besides the basic JSON API features, below are some additional Bolt specific
queries that you may find useful:

| URL | Description |
|-------------------------|----------------------------------------------------|
|`/{ct}/search?q={query}` | Searches for `{query}` in a specific `contenttype`.|
|`/search?q={query}` | Searches for `{query}` in all contenttypes. |
|`/menu` | Returns a list of all menus defined in `menu.yml`. |
|`/menu?q={name}` | Returns the menu with the specified name. |
| URL | Description |
|-------------------------|-------------------------------------------------------------|
|`/{ct}/search?q={query}` | Searches for `{query}` in a specific `contenttype`. |
|`/search?q={query}` | Searches for `{query}` in all contenttypes. |
|`/menu` | Returns a list of all menus defined in `menu.yml`. |
|`/menu?q={name}` | Returns the menu with the specified name. |
|`/taxonomy` | Returns a list of all taxonomies defined in `taxonomy.yml`. |
|`/taxonomy?q={name}` | Returns the taxonomy with the specified name. |

### Road Map

Expand Down
58 changes: 58 additions & 0 deletions src/Action/TaxonomyAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Bolt\Extension\Bolt\JsonApi\Action;

use Bolt\Config;
use Bolt\Extension\Bolt\JsonApi\Exception\ApiNotFoundException;
use Bolt\Extension\Bolt\JsonApi\Response\ApiResponse;
use Symfony\Component\HttpFoundation\Request;

/**
* Class TaxonomyAction
*
* @package Bolt\Extension\Bolt\JsonApi\Action
*/
class TaxonomyAction
{
/** @var Config $config */
protected $boltConfig;

/** @var \Bolt\Extension\Bolt\JsonApi\Config\Config $extensionConfig */
protected $extensionConfig;

/**
* TaxonomyAction constructor.
*
* @param Config $boltConfig
* @param \Bolt\Extension\Bolt\JsonApi\Config\Config $extensionConfig
*/
public function __construct(Config $boltConfig, \Bolt\Extension\Bolt\JsonApi\Config\Config $extensionConfig)
{
$this->boltConfig = $boltConfig;
$this->extensionConfig = $extensionConfig;
}

/**
* @param Request $request
*
* @return ApiResponse
*/
public function handle(Request $request)
{
if ($name = $request->get('q', '')) {
$name = "/$name";
}

$taxonomy = $this->boltConfig->get('taxonomy' . $name, false);

if (! $taxonomy) {
throw new ApiNotFoundException(
"Menu with name [$name] not found."
);
}

return new ApiResponse([
'data' => $taxonomy,
], $this->extensionConfig);
}
}
3 changes: 3 additions & 0 deletions src/Controllers/ContentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public function connect(Application $app)
$ctr->get('/menu', [$app['jsonapi.action.menu'], 'handle'])
->bind('jsonapi.menu');

$ctr->get('/taxonomy', [$app['jsonapi.action.taxonomy'], 'handle'])
->bind('jsonapi.taxonomy');

$ctr->get('/search', [$app['jsonapi.action.search'], 'handle'])
->bind('jsonapi.searchAll')
->convert('parameters', 'jsonapi.converter:grabParameters');
Expand Down
10 changes: 10 additions & 0 deletions src/Provider/APIProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Bolt\Extension\Bolt\JsonApi\Action\MenuAction;
use Bolt\Extension\Bolt\JsonApi\Action\SearchAction;
use Bolt\Extension\Bolt\JsonApi\Action\SingleAction;
use Bolt\Extension\Bolt\JsonApi\Action\TaxonomyAction;
use Bolt\Extension\Bolt\JsonApi\Config\Config;
use Bolt\Extension\Bolt\JsonApi\Converter\JSONAPIConverter;
use Bolt\Extension\Bolt\JsonApi\Helpers\DataLinks;
Expand Down Expand Up @@ -141,6 +142,15 @@ function ($app) {
}
);

$app['jsonapi.action.taxonomy'] = $app->share(
function ($app) {
return new TaxonomyAction(
$app['config'],
$app['jsonapi.config']
);
}
);

/**
* Add repository and query parsers to handle pagination to DI
*/
Expand Down