### Configure multi-webspace setups Source: https://github.com/sulu/suluarticlebundle/blob/2.6/Resources/doc/installation.md Examples for configuring default webspaces, including simple, localized, and localized with default fallback configurations. ```yaml # config/packages/sulu_article.yaml sulu_article: default_main_webspace: 'webspace1' default_additional_webspaces: - 'webspace2' - 'webspace3' ``` ```yaml # config/packages/sulu_article.yaml sulu_article: default_main_webspace: de: 'webspaceA' en: 'webspaceX' default_additional_webspaces: de: - 'webspaceN' - 'webspaceM' en: - 'webspaceN' ``` ```yaml # config/packages/sulu_article.yaml sulu_article: default_main_webspace: default: 'webspaceA' en: 'webspaceX' fr: 'webspaceF' default_additional_webspaces: default: - 'webspaceB' - 'webspaceC' de: - 'webspaceN' - 'webspaceM' en: - 'webspaceN' ``` -------------------------------- ### Custom Article Controller (Before) Source: https://github.com/sulu/suluarticlebundle/blob/2.6/UPGRADE.md Example of a custom article controller implementation before refactoring, showing manual serialization and rendering. ```php class CustomArticleController extends Controller { public function indexAction(Request $request, ArticleDocument $object, $view) { $content = $this->get('jms_serializer')->serialize( $object, 'array', SerializationContext::create() ->setSerializeNull(true) ->setGroups(['website', 'content']) ->setAttribute('website', true) ); return $this->render( $view . '.html.twig', $this->get('sulu_website.resolver.template_attribute')->resolve($content), $this->createResponse($request) ); } } ``` -------------------------------- ### Install SuluArticleBundle via Composer Source: https://github.com/sulu/suluarticlebundle/blob/2.6/README.md Use these commands to add the required Elasticsearch dependency and the bundle itself to your project. ```bash composer require "elasticsearch/elasticsearch:7.17.*" # should match version of your elasticsearch installation composer require sulu/article-bundle ``` -------------------------------- ### Define Article Page Routes Source: https://github.com/sulu/suluarticlebundle/blob/2.6/UPGRADE.md Configure article page routes in `app/config/config.yml` as the bundle no longer prepends this configuration. This example shows how to define the route schema and parent. ```yaml sulu_route: mappings: # ... Sulu\Bundle\ArticleBundle\Document\ArticlePageDocument: generator: "article_page" options: route_schema: "/{translator.trans("page")}-{object.getPageNumber()}" parent: "{object.getParent().getRoutePath()}" ``` -------------------------------- ### Custom Article Controller (After) Source: https://github.com/sulu/suluarticlebundle/blob/2.6/UPGRADE.md Example of a custom article controller implementation after refactoring, extending `WebsiteArticleController` and using `renderArticle`. ```php class CustomArticleController extends WebsiteArticleController { public function indexAction(Request $request, ArticleInterface $object, $view, $pageNumber = 1) { return $this->renderArticle($request, $object, $view, $pageNumber, []); } } ``` -------------------------------- ### Custom Article Overview Controller Source: https://context7.com/sulu/suluarticlebundle/llms.txt Example PHP code for a custom controller to list articles using Elasticsearch queries. ```APIDOC ## Custom Article Overview Controller ### Description This PHP code defines a custom controller for creating article overview pages. It utilizes the ONGR Elasticsearch Bundle to perform queries and load articles. ### Language PHP ### Code Example ```php esManagerLive = $esManagerLive; } public function indexAction( Request $request, StructureInterface $structure, $preview = false, $partial = false ): Response { $page = $request->query->getInt('page', 1); if ($page < 1) { throw new NotFoundHttpException(); } $articles = $this->loadArticles($page, self::PAGE_SIZE, $request->getLocale()); $pages = (int) ceil($articles->count() / self::PAGE_SIZE) ?: 1; return $this->renderStructure( $structure, [ 'page' => $page, 'pages' => $pages, 'articles' => $articles ], $preview, $partial ); } private function loadArticles(int $page, int $pageSize, string $locale) { $repository = $this->esManagerLive->getRepository(ArticleViewDocument::class); $search = $repository->createSearch() ->addSort(new FieldSort('authored', FieldSort::DESC)) ->setFrom(($page - 1) * $pageSize) ->setSize($pageSize) ->addQuery(new TermQuery('locale', $locale)); return $repository->findDocuments($search); } } ``` ``` -------------------------------- ### Upgrade Elasticsearch and Article Bundle Source: https://github.com/sulu/suluarticlebundle/blob/2.6/UPGRADE.md Commands to remove old dependencies, install the required Elasticsearch version, and update the bundle. ```bash # Remove ongr packages: composer remove ongr/elasticsearch-bundle --no-update composer remove ongr/elasticsearch-dsl --no-update # Use your matching elasticsearch version here ( ^5, ^6 or ^7 ): composer require elasticsearch/elasticsearch:"^7" --no-update # Update article bundle to newest version: composer require sulu/article-bundle:"^2.1" --with-dependencies # Reindex your articles when upgrading elasticsearch version: bin/adminconsole ongr:es:index:create --manager default bin/adminconsole ongr:es:index:create --manager live bin/adminconsole sulu:article:reindex bin/websiteconsole sulu:article:reindex ``` ```bash # Remove ongr packages: composer remove ongr/elasticsearch-bundle --no-update composer remove ongr/elasticsearch-dsl --no-update # Use your matching elasticsearch version here ( ^5, ^6 or ^7 ): composer require elasticsearch/elasticsearch:”^7” --no-update # Update article bundle to newest version: composer require sulu/article-bundle:”^1.2” --with-dependencies # Reindex your articles when upgrading elasticsearch version: bin/adminconsole ongr:es:index:create --manager default bin/adminconsole ongr:es:index:create --manager live bin/adminconsole sulu:article:reindex bin/websiteconsole sulu:article:reindex ``` -------------------------------- ### Get Single Article Source: https://context7.com/sulu/suluarticlebundle/llms.txt Retrieve a specific article using its UUID. ```APIDOC ## GET /admin/api/articles/{uuid} ### Description Retrieves a specific article by its unique identifier (UUID). ### Method GET ### Endpoint /admin/api/articles/{uuid} ### Path Parameters - **uuid** (string) - Required - The UUID of the article to retrieve. ### Query Parameters - **locale** (string) - Required - The locale of the article to retrieve. ### Request Example ```bash curl -X GET "https://example.com/admin/api/articles/550e8400-e29b-41d4-a716-446655440000?locale=en" \ -H "Authorization: Bearer YOUR_TOKEN" ``` ``` -------------------------------- ### Twig Excerpt Data Resolution (Before) Source: https://github.com/sulu/suluarticlebundle/blob/2.6/UPGRADE.md Example of how excerpt data was resolved in the article template in older versions, accessing categories and images as arrays. ```twig {{ extension.excerpt.categories[0] }} {{ extension.excerpt.images.ids[0] }} {{ extension.excerpt.icon.ids[0] }} ``` -------------------------------- ### Twig Excerpt Data Resolution (After) Source: https://github.com/sulu/suluarticlebundle/blob/2.6/UPGRADE.md Example of how excerpt data is resolved in the article template in newer versions, directly accessing IDs from resolved objects. ```twig {{ extension.excerpt.categories[0].id }} {{ extension.excerpt.images[0].id }} {{ extension.excerpt.icon[0].id }} ``` -------------------------------- ### Initialize Elasticsearch Index Source: https://context7.com/sulu/suluarticlebundle/llms.txt Run console commands to initialize PHPCR document nodes and create Elasticsearch indexes. ```bash # Create PHPCR document nodes php bin/console sulu:document:init # Create Elasticsearch indexes php bin/console ongr:es:index:create php bin/console ongr:es:index:create --manager=live ``` -------------------------------- ### Configure Multi-Webspace Articles Source: https://context7.com/sulu/suluarticlebundle/llms.txt Set up main and additional webspaces for articles, including localized configurations. ```yaml # config/packages/sulu_article.yaml sulu_article: # Simple configuration default_main_webspace: 'webspace1' default_additional_webspaces: - 'webspace2' - 'webspace3' # Localized configuration default_main_webspace: default: 'webspaceA' en: 'webspaceX' fr: 'webspaceF' default_additional_webspaces: default: - 'webspaceB' - 'webspaceC' de: - 'webspaceN' - 'webspaceM' ``` -------------------------------- ### Migrate teaser provider Source: https://github.com/sulu/suluarticlebundle/blob/2.6/UPGRADE.md Runs the migration command for teaser providers in articles. ```bash bin/console phpcr:migrations:migrate ``` -------------------------------- ### Initialize bundle and Elasticsearch index Source: https://github.com/sulu/suluarticlebundle/blob/2.6/Resources/doc/installation.md Commands to initialize PHPCR nodes and create the Elasticsearch indices. ```bash php bin/console sulu:document:init ``` ```bash php bin/console ongr:es:index:create php bin/console ongr:es:index:create --manager=live ``` -------------------------------- ### Full bundle configuration reference Source: https://github.com/sulu/suluarticlebundle/blob/2.6/Resources/doc/installation.md Comprehensive configuration options for the SuluArticleBundle. ```yaml # config/packages/sulu_article.yaml sulu_article: index_name: su_articles hosts: ['127.0.0.1:9200'] default_main_webspace: null default_additional_webspaces: [] smart_content: default_limit: 100 documents: article: view: Sulu\Bundle\ArticleBundle\Document\ArticleViewDocument article_page: view: Sulu\Bundle\ArticleBundle\Document\ArticlePageViewObject types: # Prototype name: translation_key: ~ # Display tab 'all' in list view display_tab_all: true # Set default author if none isset default_author: true search_fields: # Defaults: - title - excerpt.title - excerpt.description - excerpt.seo.title - excerpt.seo.description - excerpt.seo.keywords - teaser_description ``` -------------------------------- ### Create New Article Source: https://context7.com/sulu/suluarticlebundle/llms.txt Create an article by sending a JSON payload with template and content data. ```bash curl -X POST "https://example.com/admin/api/articles?locale=en&action=publish" \ -H "Authorization: Bearer YOUR_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "template": "blog_post", "title": "Getting Started with Elasticsearch", "routePath": "/articles/getting-started-elasticsearch", "article": "
Learn how to integrate Elasticsearch...
", "authored": "2024-01-15T10:00:00+00:00", "author": 1 }' ``` -------------------------------- ### Register bundles in AbstractKernel Source: https://github.com/sulu/suluarticlebundle/blob/2.6/Resources/doc/installation.md Manual registration of the SuluArticleBundle and ONGR Elasticsearch bundle in the bundles configuration file. ```php /* config/bundles.php */ Sulu\Bundle\ArticleBundle\SuluArticleBundle::class => ['all' => true], ONGR\ElasticsearchBundle\ONGRElasticsearchBundle::class => ['all' => true], ``` -------------------------------- ### Configure SuluArticleBundle and core Source: https://github.com/sulu/suluarticlebundle/blob/2.6/Resources/doc/installation.md Define the Elasticsearch index, hosts, and routing mappings in the bundle configuration file. ```yaml # config/packages/sulu_article.yaml sulu_article: index_name: '%env(resolve:ELASTICSEARCH_INDEX)%' hosts: - '%env(resolve:ELASTICSEARCH_HOST)%' types: article: translation_key: "sulu_article.article" sulu_route: mappings: Sulu\Bundle\ArticleBundle\Document\ArticleDocument: generator: schema options: route_schema: '/articles/{implode("-", object)}' ongr_elasticsearch: # If you expect more than 10000 articles, you need to set the `max_result_window` to an appropriate number # managers: # default: # index: # settings: # max_result_window: 20000 # live: # index: # settings: # max_result_window: 20000 analysis: tokenizer: pathTokenizer: type: path_hierarchy analyzer: pathAnalyzer: tokenizer: pathTokenizer ``` -------------------------------- ### Custom Article Overview Controller Source: https://github.com/sulu/suluarticlebundle/blob/2.6/Resources/doc/overview-page.md Handles loading and rendering articles using Elasticsearch. Ensure the Elasticsearch manager is correctly configured in services.yaml. ```php esManagerLive = $esManagerLive; } public function indexAction(Request $request, StructureInterface $structure, $preview = false, $partial = false) { $page = $request->query->getInt('page', 1); if ($page < 1) { throw new NotFoundHttpException(); } $articles = $this->loadArticles($page, self::PAGE_SIZE, $request->getLocale()); $pages = (int) ceil($articles->count() / self::PAGE_SIZE) ?: 1; return $this->renderStructure( $structure, [ 'page' => $page, 'pages' => $pages, 'articles' => $articles ], $preview, $partial ); } private function loadArticles($page, $pageSize, $locale) { $repository = $this->getRepository(); $search = $repository->createSearch() ->addSort(new FieldSort('authored', FieldSort::DESC)) ->setFrom(($page - 1) * $pageSize) ->setSize($pageSize) ->addQuery(new TermQuery('locale', $locale)); return $repository->findDocuments($search); } /** * @return Repository */ private function getRepository() { return $this->esManagerLive->getRepository(ArticleViewDocument::class); } } ``` -------------------------------- ### Custom Article Overview Controller Source: https://context7.com/sulu/suluarticlebundle/llms.txt Implement a custom controller to fetch and display articles using Elasticsearch queries. ```php esManagerLive = $esManagerLive; } public function indexAction( Request $request, StructureInterface $structure, $preview = false, $partial = false ): Response { $page = $request->query->getInt('page', 1); if ($page < 1) { throw new NotFoundHttpException(); } $articles = $this->loadArticles($page, self::PAGE_SIZE, $request->getLocale()); $pages = (int) ceil($articles->count() / self::PAGE_SIZE) ?: 1; return $this->renderStructure( $structure, [ 'page' => $page, 'pages' => $pages, 'articles' => $articles ], $preview, $partial ); } private function loadArticles(int $page, int $pageSize, string $locale) { $repository = $this->esManagerLive->getRepository(ArticleViewDocument::class); $search = $repository->createSearch() ->addSort(new FieldSort('authored', FieldSort::DESC)) ->setFrom(($page - 1) * $pageSize) ->setSize($pageSize) ->addQuery(new TermQuery('locale', $locale)); return $repository->findDocuments($search); } } ``` -------------------------------- ### Drop and Create Elasticsearch Indices Source: https://github.com/sulu/suluarticlebundle/blob/2.6/UPGRADE.md Commands to drop and create Elasticsearch indices for default and live environments. Use `--force` to bypass confirmation prompts when dropping indices. ```bash bin/adminconsole ongr:es:index:drop -m default --force ``` ```bash bin/websiteconsole ongr:es:index:drop -m live --force ``` ```bash bin/adminconsole ongr:es:index:create -m default ``` ```bash bin/websiteconsole ongr:es:index:create -m live ``` ```bash bin/adminconsole sulu:article:index-rebuild ###LOCALE### ``` ```bash bin/websiteconsole sulu:article:index-rebuild ###LOCALE### --live ``` -------------------------------- ### Perform Article Actions Source: https://context7.com/sulu/suluarticlebundle/llms.txt Execute lifecycle actions such as unpublishing, removing drafts, or copying content between locales. ```bash # Unpublish article curl -X POST "https://example.com/admin/api/articles/550e8400-e29b-41d4-a716-446655440000?action=unpublish&locale=en" \ -H "Authorization: Bearer YOUR_TOKEN" # Remove draft curl -X POST "https://example.com/admin/api/articles/550e8400-e29b-41d4-a716-446655440000?action=remove-draft&locale=en" \ -H "Authorization: Bearer YOUR_TOKEN" # Copy article curl -X POST "https://example.com/admin/api/articles/550e8400-e29b-41d4-a716-446655440000?action=copy&locale=en" \ -H "Authorization: Bearer YOUR_TOKEN" # Copy locale content from English to German and French curl -X POST "https://example.com/admin/api/articles/550e8400-e29b-41d4-a716-446655440000?action=copy-locale&locale=en&src=en&dest=de,fr" \ -H "Authorization: Bearer YOUR_TOKEN" ``` -------------------------------- ### Run PHPCR migrations Source: https://github.com/sulu/suluarticlebundle/blob/2.6/UPGRADE.md Executes the migration script to backfill the routePathName property on existing article nodes. ```bash bin/adminconsole phpcr:migrations:migrate ``` -------------------------------- ### Implementing an ArticleIndexListener Source: https://github.com/sulu/suluarticlebundle/blob/2.6/Resources/doc/article-view-document.md Use an event listener to populate custom document properties during the indexing process. ```php getDocument(); $viewDocument = $event->getViewDocument(); $data = $document->getStructure()->toArray(); if (!array_key_exists('myCustomProperty', $data)) { return; } $viewDocument->myCustomProperty = $data['myCustomProperty']; } } ``` ```xmlLearn how to integrate Elasticsearch...
", "authored": "2024-01-15T10:00:00+00:00", "author": 1 } ``` ### Request Example (with publish action) ```bash curl -X POST "https://example.com/admin/api/articles?locale=en&action=publish" \ -H "Authorization: Bearer YOUR_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "template": "blog_post", "title": "Getting Started with Elasticsearch", "routePath": "/articles/getting-started-elasticsearch", "article": "Learn how to integrate Elasticsearch...
", "authored": "2024-01-15T10:00:00+00:00", "author": 1 }' ``` ``` -------------------------------- ### Import translated XLIFF files Source: https://github.com/sulu/suluarticlebundle/blob/2.6/Resources/doc/xliff.md Use the sulu:article:import command to import translated content. The --overrideSettings flag can be used to update existing settings. ```bash $ bin/adminconsole sulu:article:import export.xliff de --overrideSettings ``` -------------------------------- ### Rebuild Elasticsearch Index (Live) Source: https://github.com/sulu/suluarticlebundle/blob/2.6/UPGRADE.md Use this command to rebuild the Elasticsearch index for articles, including live content. Replace ###LOCALE### with the desired locale code (e.g., en, de). ```bash bin/adminconsole sulu:article:index-rebuild ###LOCALE### --live ``` -------------------------------- ### Configure Sulu Article Bundle Source: https://context7.com/sulu/suluarticlebundle/llms.txt Define Elasticsearch connection settings, article types, and routing mappings in the bundle configuration. ```yaml # config/packages/sulu_article.yaml sulu_article: index_name: '%env(resolve:ELASTICSEARCH_INDEX)%' hosts: - '%env(resolve:ELASTICSEARCH_HOST)%' types: article: translation_key: "sulu_article.article" blog: translation_key: "app.article_types.blog" smart_content: default_limit: 100 default_author: true search_fields: - title - excerpt.title - excerpt.description - teaser_description sulu_route: mappings: Sulu\Bundle\ArticleBundle\Document\ArticleDocument: generator: schema options: route_schema: '/articles/{implode("-", object)}' ongr_elasticsearch: analysis: tokenizer: pathTokenizer: type: path_hierarchy analyzer: pathAnalyzer: tokenizer: pathTokenizer ``` -------------------------------- ### Configure Page Tree Route Source: https://context7.com/sulu/suluarticlebundle/llms.txt Define the route path property and cascade behavior for articles. ```xml{{ article.excerpt.description|default(article.teaserDescription) }}
Updated content...
" }' ``` -------------------------------- ### Render Selected Articles in Twig Source: https://context7.com/sulu/suluarticlebundle/llms.txt Iterates through selected articles and displays their details in a template. ```twig {# Render selected articles #} {% for article in content.featuredArticles %}{{ article.excerpt.description }}
{% if article.excerpt.images|length > 0 %}{{ content.highlightedArticle.excerpt.description }}
Read more