adachsoft / content-articles-bundle
Symfony bundle that exposes content article management and public reading APIs.
Package info
gitlab.com/a.adach/content-articles-bundle
pkg:composer/adachsoft/content-articles-bundle
Requires
- php: ^8.3
- adachsoft/content-articles: ^0.2
- symfony/config: ^7.2
- symfony/dependency-injection: ^7.2
- symfony/http-foundation: ^7.2
- symfony/http-kernel: ^7.2
- symfony/routing: ^7.2
- symfony/yaml: ^7.2
Requires (Dev)
- adachsoft/php-code-style: ^0.9.0
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^13
- rector/rector: ^2.9
- symfony/browser-kit: ^7.2
- symfony/framework-bundle: ^7.2
- symplify/phpstan-rules: ^14.19
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
adachsoft/content-articles-bundle exposes the framework-independent adachsoft/content-articles article service as administrative and public JSON HTTP endpoints. It stores articles with the package's JSON file repository and leaves permission enforcement to the host application's authentication bundle.
Requirements
- PHP 8.3 or later.
- Symfony 7.2 components, including HttpKernel, HttpFoundation, Routing, Config, DependencyInjection, and YAML.
Installation
Install the bundle and enable it in the Symfony application:
composer require adachsoft/content-articles-bundle
<?php
// config/bundles.php
return [
AdachSoft\ContentArticlesBundle\ContentArticlesBundle::class => ['all' => true],
];
Configure storage, route prefixes, and the application permission prefix:
# config/packages/content_articles.yaml
content_articles:
storage_dir: '%kernel.project_dir%/var/content/articles'
route_prefix_admin: '/api/v1/admin/articles'
route_prefix_public: '/api/v1/articles'
permission_prefix: 'articles'
storage_dir is required. The other values default to the example values above. The JSON repository creates the directory when the first article is stored.
Import the bundle routes:
# config/routes/content_articles.yaml
content_articles_bundle:
resource: '@ContentArticlesBundle/src/Resources/config/routes.php'
type: php
Administrative routes declare _permission defaults; the bundle does not authorize requests itself. The host application's auth bundle must enforce those defaults. Public routes intentionally have no _permission default.
Usage
After installation, configure the bundle, import its routes, and connect the declared administrative _permission route defaults to the host application's authorization system. The endpoints and request examples below show how to create, update, publish, and retrieve articles.
Endpoints
The default permission prefix is articles. Changing permission_prefix changes the permission names below.
| Method | Path | Permission | Description |
|---|---|---|---|
GET | /api/v1/admin/articles | articles.read | List article summaries. Supports locale, comma-separated status, related=type:id, limit (1–100, default 20), and offset (default 0). |
GET | /api/v1/admin/articles/{id} | articles.read | Get a complete article. |
POST | /api/v1/admin/articles | articles.write | Create a draft; returns 201 and a Location header. |
PUT | /api/v1/admin/articles/{id}/content | articles.write | Replace title, subtitle, lead, and body. Requires If-Match with the expected revision. |
PUT | /api/v1/admin/articles/{id}/seo | articles.write | Replace or remove SEO metadata. Requires If-Match with the expected revision. |
POST | /api/v1/admin/articles/{id}/transition | articles.write | Move between draft and in_review; the JSON body contains status and revision. |
POST | /api/v1/admin/articles/{id}/publish | articles.publish | Publish an in-review article; the JSON body contains revision. |
POST | /api/v1/admin/articles/{id}/archive | articles.publish | Archive an article; the JSON body contains revision. |
POST | /api/v1/admin/articles/{id}/fact-checked | articles.write | Mark an article as fact-checked. |
GET | /api/v1/articles | None | List published summaries. Supports locale, related=type:id, limit, and offset; results are ordered by publication time. |
GET | /api/v1/articles/{locale}/{slug} | None | Get a published article and its published translations. |
Public responses use Cache-Control: public, max-age=300. Public list and translation results include only published articles. A draft is returned as 404 from the public API.
Article request validation errors use 422 and report every invalid field in error.details. A missing If-Match header returns 428 revision_required; a revision mismatch returns 409 revision_conflict with expected and actual details. Content Blocks validation failures return 422 invalid_body with each validation code, path, and message.
Create an article
The create request supplies the article ID, translation group ID, locale-specific slug, article fields, authors, optional related entities, and a Content Blocks document. The body value is a Content Blocks document such as docs/reference/article-full.json.
curl -i -X POST 'https://example.test/api/v1/admin/articles' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <token>' \
--data-binary @article-request.json
Example article-request.json:
{
"id": "11111111-1111-4111-8111-111111111111",
"translation_group_id": "22222222-2222-4222-8222-222222222222",
"slug": "tyrannosaurus-rex",
"locale": "en",
"title": "Tyrannosaurus rex",
"subtitle": null,
"lead": "A concise introduction to Tyrannosaurus rex.",
"body": {
"spec": "content-blocks/1.0",
"blocks": [
{
"id": "p1",
"type": "paragraph",
"data": {
"text": [
{ "type": "text", "text": "Tyrannosaurus rex lived at the end of the Cretaceous." }
]
}
}
]
},
"authors": [
{ "name": "Editorial Team", "type": "organization", "url": null }
],
"ai_disclosure": { "ai_assisted": false, "disclosure": null },
"related_entities": [
{ "type": "dinosaur", "id": "tyrannosaurus" }
],
"seo": null
}
Update and publish
Content and SEO updates use optimistic locking. Supply the current revision in If-Match:
curl -X PUT 'https://example.test/api/v1/admin/articles/11111111-1111-4111-8111-111111111111/content' \
-H 'Content-Type: application/json' \
-H 'If-Match: 1' \
-H 'Authorization: Bearer <token>' \
--data '{"title":"Updated title","subtitle":null,"lead":"Updated lead.","body":{"spec":"content-blocks/1.0","blocks":[{"id":"p1","type":"paragraph","data":{"text":[{"type":"text","text":"Updated content."}]}}]}}'
Move the article into review with its current revision, then publish it through the permission-specific route:
curl -X POST 'https://example.test/api/v1/admin/articles/11111111-1111-4111-8111-111111111111/transition' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <token>' \
--data '{"status":"in_review","revision":2}'
curl -X POST 'https://example.test/api/v1/admin/articles/11111111-1111-4111-8111-111111111111/publish' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <token>' \
--data '{"revision":3}'
Retrieve the published article without an administrative permission:
curl 'https://example.test/api/v1/articles/en/tyrannosaurus-rex'