Search by

sy / bootstrap-article

syone

Plugin for adding Article feature

Package info

github.com/syframework/bootstrap-article

pkg:composer/sy/bootstrap-article

Statistics

Installs: 666

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 2

1.8.7 2026-11-30 08:00 UTC

README

sy/bootstrap plugin for adding "Article" feature in your sy/project based application.

Installation

From your sy/project application directory:

composer require sy/bootstrap-article

The project's post-update-cmd hook then runs @sy install (sy/project 8.0.0, sy/bootstrap ≥ 2.2), which copies the plugin files where they belong and migrates its schema:

  1. templates/ — missing files only, so a template the project has edited is never overwritten (here: protected/templates/…);
  2. assets/ — only when the vendor copy is newer (here: assets/ckeditor/templates/article, next to the CKEditor installation, discovered through assets.ckeditor-root);
  3. assets/css/app.css — rebuilt when a plugin .scss file is newer than it; Gulp reads protected/vendor/sy/bootstrap-*/scss/*.scss directly, so nothing is imported into app.scss;
  4. flyway repair then migrate — on the core schema and on the plugin schema (flyway_article_history), straight from the package's sql/ directory.

composer install-plugin no longer exists (sy/project 8.0.0). On a project older than that, run composer sy install after the composer require.

Translations need no registration: each Article component embeds its own translator (lang/bootstrap-article), and the section titles are owned by the Author, Share, Side and Categories components. The CKEditor engine itself (assets/js/wysiwyg.js, assets/js/plugins) comes from sy/bootstrap-wysiwyg, whose assets the same hook copies.

Page methods

Create 2 methods in your Project\Application\Page class (in protected/src/Application/Page.php):

	/**
	 * List of all articles page
	 */
	public function articlesAction() {
		$components = [
			'NAV'         => new \Sy\Bootstrap\Component\Article\Categories('articles'),
			'SEARCH_FORM' => new \Sy\Bootstrap\Component\Article\Search(),
			'FEED'        => new \Sy\Bootstrap\Component\Article\Feed(),
		];

		// Add article modal button
		$service = \Project\Service\Container::getInstance();
		if ($service->user->getCurrentUser()->hasPermission('article-create')) {
			$components['ADD_FORM'] = new \Sy\Bootstrap\Component\Article\Add(['class' => 'mb-3']);
		}

		$this->setContentVars($components);
	}

	/**
	 * Article page
	 */
	public function articleAction() {
		// Redirection if no article id provided
		$id = $this->get('id');
		if (is_null($id)) throw new \Sy\Bootstrap\Application\Page\NotFoundException();

		// Detect language
		$service = \Project\Service\Container::getInstance();
		$lang = $service->lang->getLang();

		// Retrieve article
		$article = $service->article->retrieve(['id' => $id, 'lang' => $lang]);

		if (empty($article)) {
			$lang = LANG;
			$article = $service->article->retrieve(['id' => $id, 'lang' => $lang]);
		}
		if (empty($article)) throw new \Sy\Bootstrap\Application\Page\NotFoundException();

		// The article may come from the language fallback: use its real lang.
		$lang = $article['lang'];

		// Article content
		$content = new \Sy\Bootstrap\Component\Article\Content($id, $lang);

		$this->setContentVars([
			'ARTICLE_BREADCRUMB' => new \Sy\Bootstrap\Component\Article\Breadcrumb($id, $lang),
			'ARTICLE_CONTENT'    => $content,
			'ARTICLE_AUTHOR'     => new \Sy\Bootstrap\Component\Article\Author($article['user_id']),
			'SIDE'               => new \Sy\Bootstrap\Component\Article\Side($id, $article['category_id']),
			'SHARE'              => new \Sy\Bootstrap\Component\Article\Share(PROJECT_URL . Url::build('page', 'article', ['id' => $id])),
		]);
	}

Component allowlist

By default, Article neutralizes every server-side component (data-sycomponent). A project can authorize its own components in protected/conf/conf.php:

define('WYSIWYG_COMPONENT_ALLOWLIST', [
	'article' => [\Project\Component\Article\Map::class],
]);

The entries are merged with the package default (empty for Article), and the editor's components option is enabled automatically when the resulting list is not empty. Allowed components are instantiated and rendered by ComponentRenderer; their data-sycomponent wrapper is kept so they are rebuilt after a save even when HtmlSanitizer removes the rendered form controls. While editing, the sycomponent widget masks the rendered component and saves the source slot instead of the rendered form; a successful save reloads the page so the component is rebuilt server-side. The Sycomponent dialog lists readable component names and renders one typed field per constructor parameter; components without parameters hide the arguments area, and the source slot is generated from the class name ({INLINE_STYLE}). After an insertion or an edit, the editor previews the final component through /editor/article/render, which checks the allowlist and the article permission before instantiating the component. The action comes from the Sy\Bootstrap\Application\Editor\Render trait (wysiwyg): Application\Editor\Article only declares its page language (renderLanguage()) and its translator directories (renderTranslators()). The component catalogue follows the same split: the editor declares components.metadata-url (/editor/article/metadata) and the plugin fetches it when the dialog is first opened, instead of receiving the map with every page; the action comes from the Sy\Bootstrap\Application\Editor\Metadata trait (wysiwyg 1.10), which shares its allowlist with the render endpoint and answers 304 to a revalidating If-None-Match. The endpoint uses the article language, so the rendered labels match the page translations. Double-click a component or use the Edit component context-menu entry to reopen the dialog with its current arguments. The CKEditor interface follows the connected user's language when available, falling back to the display language for guests; the article language used by load-data/save-data is unchanged. The same constant also accepts content (CMS) and place keys.

Add URL converter in Application.php

In protected/src/Application.php:

<?php
namespace Project;

use Sy\Bootstrap\Lib\Url;

class Application extends \Sy\Bootstrap\Application {

	protected function initUrlConverter() {
		Url\AliasManager::setAliasFile(__DIR__ . '/../conf/alias.php');
		Url::addConverter(new Url\AliasConverter());
		Url::addConverter(new Url\ArticleConverter()); // Add article converter
		Url::addConverter(new Url\ControllerActionConverter());
	}

}

Converters are evaluated in registration order. ArticleConverter must be registered before ControllerActionConverter, which is the terminal fallback; its position relative to AliasConverter depends on whether aliases should take precedence over article URLs. With this configuration, an article is reachable as /a/<alias> and is mapped to p=page, a=article, id=<id> and lang=<article language>.

Article URLs have no language segment: ArticleConverter sets the current language from the article, so the page is rendered in the article language. See the URL Converters wiki page for the full converter contract, ordering rules and Url::build() examples.

Add the articles sitemap in Sitemap.php

In protected/src/Application/Sitemap.php

<?php
namespace Project\Application;

class Sitemap extends \Sy\Bootstrap\Application\Sitemap {

	public function __construct() {
		parent::__construct();
		$this->addProvider(new \Sy\Bootstrap\Application\Sitemap\Page());
		$this->addProvider(new \Sy\Bootstrap\Application\Sitemap\Article()); // Add the articles sitemap
	}

}

Article adds one entry to the sitemap index (<project>/sitemap/article) and lists every public article, one entry per language: <loc> is the article URL (/a/<alias>), <lastmod> is its updated_at date, and <alternate> lists every translation of the same article (the join is not filtered on the translation status).

The provider must be registered: Sitemap resolves the requested action to Project\Application\Sitemap\<Action> then Sy\Bootstrap\Application\Sitemap\<Action>, and answers 404 when no provider class matches the action or when that class was never added with addProvider(). An unregistered Article sitemap is therefore a 404, not an empty file; leaving it out of Sitemap.php also keeps the article URLs out of the sitemap index.