Search by

adachsoft / content-articles-bundle

Arkadiusz Adach

Symfony bundle that exposes content article management and public reading APIs.

Package info

gitlab.com/a.adach/content-articles-bundle

Issues

pkg:composer/adachsoft/content-articles-bundle

Statistics

Installs: 7

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.0 2026-12-02 20:08 UTC

This package is auto-updated.

Last update: 2026-12-02 19:09:02 UTC


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.

MethodPathPermissionDescription
GET/api/v1/admin/articlesarticles.readList 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.readGet a complete article.
POST/api/v1/admin/articlesarticles.writeCreate a draft; returns 201 and a Location header.
PUT/api/v1/admin/articles/{id}/contentarticles.writeReplace title, subtitle, lead, and body. Requires If-Match with the expected revision.
PUT/api/v1/admin/articles/{id}/seoarticles.writeReplace or remove SEO metadata. Requires If-Match with the expected revision.
POST/api/v1/admin/articles/{id}/transitionarticles.writeMove between draft and in_review; the JSON body contains status and revision.
POST/api/v1/admin/articles/{id}/publisharticles.publishPublish an in-review article; the JSON body contains revision.
POST/api/v1/admin/articles/{id}/archivearticles.publishArchive an article; the JSON body contains revision.
POST/api/v1/admin/articles/{id}/fact-checkedarticles.writeMark an article as fact-checked.
GET/api/v1/articlesNoneList published summaries. Supports locale, related=type:id, limit, and offset; results are ordered by publication time.
GET/api/v1/articles/{locale}/{slug}NoneGet 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'