### 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']; } } ``` ```xml ``` -------------------------------- ### Define environment variables Source: https://github.com/sulu/suluarticlebundle/blob/2.6/Resources/doc/installation.md Set the Elasticsearch host and index name in the .env file. ```text # .env ELASTICSEARCH_HOST=127.0.0.1:9200 ELASTICSEARCH_INDEX=su_myproject ``` -------------------------------- ### List Articles via REST API Source: https://context7.com/sulu/suluarticlebundle/llms.txt Demonstrates various cURL requests to the article API for listing, filtering, and searching. ```bash # Get articles with pagination curl -X GET "https://example.com/admin/api/articles?locale=en&limit=10&page=1" \ -H "Authorization: Bearer YOUR_TOKEN" # Filter by article type curl -X GET "https://example.com/admin/api/articles?locale=en&types=blog,news" \ -H "Authorization: Bearer YOUR_TOKEN" # Filter by category, tag, or author curl -X GET "https://example.com/admin/api/articles?locale=en&categoryId=5&tagId=3&contactId=1" \ -H "Authorization: Bearer YOUR_TOKEN" # Search articles curl -X GET "https://example.com/admin/api/articles?locale=en&search=elasticsearch" \ -H "Authorization: Bearer YOUR_TOKEN" ``` -------------------------------- ### Move Articles via Console Source: https://context7.com/sulu/suluarticlebundle/llms.txt Execute a command to move articles between parent pages. ```bash bin/console sulu:article:page-tree:move /old-parent /new-parent sulu_io en ``` -------------------------------- ### Create Frontend Twig Template Source: https://context7.com/sulu/suluarticlebundle/llms.txt Implement the Twig template to render article content and metadata on the frontend. ```twig {# templates/articles/blog_post.html.twig #} {% extends "base.html.twig" %} {% block content %}

{{ content.title }}

{% if author %} By {{ author.fullName }} | {% endif %} Published: {{ authored|date('F j, Y') }}

{{ content.article|default()|raw }}
{% if extension.excerpt.categories|length > 0 %}
{% for category in extension.excerpt.categories %} {{ category.name }} {% endfor %}
{% endif %}
{% endblock %} ``` -------------------------------- ### Retrieve Single Article Source: https://context7.com/sulu/suluarticlebundle/llms.txt Fetch details for a specific article using its UUID. ```bash curl -X GET "https://example.com/admin/api/articles/550e8400-e29b-41d4-a716-446655440000?locale=en" \ -H "Authorization: Bearer YOUR_TOKEN" ``` -------------------------------- ### Configure API routing Source: https://github.com/sulu/suluarticlebundle/blob/2.6/Resources/doc/installation.md Register the article API routes in the admin configuration. ```yaml # config/routes/sulu_admin.yaml sulu_article_api: resource: "@SuluArticleBundle/Resources/config/routing_api.yml" type: rest prefix: /admin/api ``` -------------------------------- ### Create Article Source: https://context7.com/sulu/suluarticlebundle/llms.txt Create a new article with provided content and metadata. Can also publish the article upon creation. ```APIDOC ## POST /admin/api/articles ### Description Creates a new article. You can specify an action like 'publish' to publish it immediately. ### Method POST ### Endpoint /admin/api/articles ### Query Parameters - **locale** (string) - Required - The locale for the new article. - **action** (string) - Optional - The action to perform, e.g., 'publish'. ### Request Body - **template** (string) - Required - The template used for the article. - **title** (string) - Required - The title of the article. - **routePath** (string) - Required - The URL path for the article. - **article** (string) - Required - The main content of the article. - **authored** (string) - Optional - The authoring date and time (ISO 8601 format). - **author** (integer) - Optional - The ID of the author. ### Request Example ```json { "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 } ``` ### 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 Resourcelocator Adresse ``` ```yaml # config/packages/sulu_article.yaml sulu_article: content_types: page_tree_route: page_route_cascade: task # "request", "task", or "off" ``` -------------------------------- ### Enable Asynchronous Route Updates Source: https://github.com/sulu/suluarticlebundle/blob/2.6/Resources/doc/routing.md Configure the SuluArticleBundle to use the SuluAutomationBundle for asynchronous route updates. ```yaml sulu_article: content_types: page_tree_route: page_route_cascade: task # "request" or "off" ``` -------------------------------- ### Extending ArticleViewDocument Source: https://github.com/sulu/suluarticlebundle/blob/2.6/Resources/doc/article-view-document.md Create a custom document class by extending the base SuluArticleViewDocument and adding custom properties. ```php Articles Artikel ``` -------------------------------- ### Configure single_article_selection property Source: https://github.com/sulu/suluarticlebundle/blob/2.6/Resources/doc/content-types.md Use this property type to allow manual selection of a single article. ```xml Article Artikel ``` -------------------------------- ### Export and Import XLIFF Translations Source: https://context7.com/sulu/suluarticlebundle/llms.txt Commands to manage article translations via XLIFF files. ```bash # Export articles to XLIFF format bin/adminconsole sulu:article:export export.xliff en # Import translated XLIFF file bin/adminconsole sulu:article:import export.xliff de --overrideSettings ``` -------------------------------- ### Define template paths Source: https://github.com/sulu/suluarticlebundle/blob/2.6/Resources/doc/installation.md Paths for the XML structure template and the HTML Twig template. ```text %kernel.project_dir%/config/templates/articles/default.xml ``` ```text %kernel.project_dir%/templates/articles/default.html.twig ``` -------------------------------- ### Move Articles via Console Command Source: https://github.com/sulu/suluarticlebundle/blob/2.6/Resources/doc/routing.md Update the parent page of articles related to a specific page URL using the console command. ```bash bin/console sulu:article:page-tree:move /page-1 /page-2 sulu_io de ``` -------------------------------- ### Registering an AppBundle Source: https://github.com/sulu/suluarticlebundle/blob/2.6/Resources/doc/article-view-document.md Register a custom bundle to allow overriding document classes in the ElasticsearchBundle. ```php ['all' => true], ] ``` -------------------------------- ### Extend ArticleViewDocument Source: https://context7.com/sulu/suluarticlebundle/llms.txt Customizing the Elasticsearch document structure and event listener for indexing. ```php getDocument(); $viewDocument = $event->getViewDocument(); $data = $document->getStructure()->toArray(); if (array_key_exists('customProperty', $data)) { $viewDocument->customProperty = $data['customProperty']; } } } ``` ```yaml # config/services.yaml services: App\EventListener\ArticleIndexListener: tags: - { name: kernel.event_listener, event: sulu_article.index, method: onIndex } # config/packages/sulu_article.yaml sulu_article: documents: article: view: App\Document\ArticleViewDocument # config/packages/ongr_elasticsearch.yaml ongr_elasticsearch: managers: default: mappings: - AppBundle live: mappings: - AppBundle ``` -------------------------------- ### Configuring view-class and Elasticsearch Source: https://github.com/sulu/suluarticlebundle/blob/2.6/Resources/doc/article-view-document.md Update your application configuration to map the custom document class. ```yaml ongr_elasticsearch: ... managers: default: ... mappings: - AppBundle ... live: ... mappings: - AppBundle ... sulu_article: documents: article: view: AppBundle\Document\ArticleViewDocument ``` -------------------------------- ### Load Similar Articles Source: https://github.com/sulu/suluarticlebundle/blob/2.6/Resources/doc/twig-extensions.md Loads articles that are similar to the currently requested article, with configurable filtering options. ```APIDOC ## `sulu_article_load_similar` ### Description Returns similar articles compared to the requested one. Note: Which fields are included in this request can be configured with `sulu_article.search_fields` config parameter. ### Arguments - **limit** (integer) - optional - set the limit - default: 5 - **types** (array) - optional - filter for article types - default: type of the requested article - **locale** (string) - optional - filter for locale - default: locale of the request - **ignoreWebspaces** (bool) - optional - ignore webspace settings - default: false ### Returns The content-type returns a list of `ArticleResourceItem` instances. ### Example ```twig {% set articles = sulu_article_load_similar(5, ['blog']) %} ``` ``` -------------------------------- ### Filter Smart Content by Article Types Source: https://github.com/sulu/suluarticlebundle/blob/2.6/Resources/doc/article-types.md This XML configuration demonstrates how to use the 'smart_content' type to filter articles based on specified article types. This is useful for predefining content selection criteria. ```xml ``` -------------------------------- ### Configure Route Schema in YAML Source: https://github.com/sulu/suluarticlebundle/blob/2.6/Resources/doc/routing.md Define the default route schema for ArticleDocument in the application configuration. ```yml sulu_route: mappings: Sulu\Bundle\ArticleBundle\Document\ArticleDocument: generator: schema options: route_schema: '/articles/{implode("-", object)}' ``` -------------------------------- ### Extending ArticleViewDocument Source: https://github.com/sulu/suluarticlebundle/blob/2.6/Resources/doc/article-view-document.md Instructions on how to extend the ArticleViewDocument to include custom indexed data. ```APIDOC ## How to extend ArticleViewDocument? To extend the indexed data you can extend the `ArticleViewDocument`. This can be achieved by performing the following steps. The same steps can also be used to extend the `ArticlePageViewObject`. ### 0. Create a Bundle Class Unfortunately, the ElasticsearchBundle allows to overwrite document classes only if an `AppBundle` is registered in the application. If you do not have registered such a bundle yet, you need to add it to your `src` directory and enable it in the `config/bundles.php` file. ```php ['all' => true], ] ``` #### 1. Create custom class ```php getDocument(); $viewDocument = $event->getViewDocument(); $data = $document->getStructure()->toArray(); if (!array_key_exists('myCustomProperty', $data)) { return; } $viewDocument->myCustomProperty = $data['myCustomProperty']; } } ``` ```xml ``` ``` -------------------------------- ### Define Smart Content Provider Source: https://context7.com/sulu/suluarticlebundle/llms.txt Configures a smart content property in the page template XML to fetch dynamic article lists. ```xml Latest Articles Neueste Artikel ``` -------------------------------- ### Configure article_selection property Source: https://github.com/sulu/suluarticlebundle/blob/2.6/Resources/doc/content-types.md Use this property type to allow manual selection of multiple articles in the Sulu admin interface. ```xml Articles Artikel ``` -------------------------------- ### Render Smart Content Articles in Twig Source: https://context7.com/sulu/suluarticlebundle/llms.txt Iterates through dynamic smart content results and renders them. ```twig {# Render smart content articles #}
{% for item in content.latestArticles %} {% set article = item.content %}

{{ article.title }}

{{ article.excerpt.description|default(article.teaserDescription) }}

{% endfor %}
``` -------------------------------- ### Load similar articles with Twig Source: https://github.com/sulu/suluarticlebundle/blob/2.6/Resources/doc/twig-extensions.md Retrieves a list of articles similar to the current one using the sulu_article_load_similar function. ```twig {% set articles = sulu_article_load_similar(5, ['blog']) %} ``` -------------------------------- ### Define Article XML Template Source: https://context7.com/sulu/suluarticlebundle/llms.txt Specify the article structure, fields, and controller mapping using an XML template. ```xml ``` -------------------------------- ### Reindex articles Source: https://github.com/sulu/suluarticlebundle/blob/2.6/Resources/doc/commands.md Rebuilds the article index by loading all articles and updating their content. ```bash bin/adminconsole sulu:article:reindex bin/websiteconsole sulu:article:reindex ``` -------------------------------- ### Sulu Article Overview Template Configuration Source: https://github.com/sulu/suluarticlebundle/blob/2.6/Resources/doc/overview-page.md Defines a Sulu template for an article overview page, specifying the view, controller, cache lifetime, and properties. ```xml ``` -------------------------------- ### Tagging properties for search Source: https://github.com/sulu/suluarticlebundle/blob/2.6/Resources/doc/article-view-document.md Use the sulu.search.field tag in your XML configuration to automatically include properties in the contentFields index. ```xml Text Text ``` -------------------------------- ### Migrate and Reindex Data Source: https://github.com/sulu/suluarticlebundle/blob/2.6/UPGRADE.md Execute these commands to migrate data and reindex Elasticsearch after author and authored fields become localized. The `--no-interaction` flag skips interactive prompts. ```bash bin/adminconsole phpcr:migrations:migrate ``` ```bash bin/websiteconsole sulu:article:reindex --no-interaction ``` -------------------------------- ### Update Existing Article Source: https://context7.com/sulu/suluarticlebundle/llms.txt Modify an existing article's content using a PUT request. ```bash curl -X PUT "https://example.com/admin/api/articles/550e8400-e29b-41d4-a716-446655440000?locale=en&action=publish" \ -H "Authorization: Bearer YOUR_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "title": "Updated: Getting Started with Elasticsearch", "article": "

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.title }}

{{ article.excerpt.description }}

{% if article.excerpt.images|length > 0 %} {{ article.title }} {% endif %}
{% endfor %} ``` -------------------------------- ### Render Single Selected Article in Twig Source: https://context7.com/sulu/suluarticlebundle/llms.txt Displays details for a single selected article reference. ```twig {# Render single selected article #} {% if content.highlightedArticle %}

{{ content.highlightedArticle.title }}

{{ content.highlightedArticle.excerpt.description }}

Read more
{% endif %} ``` -------------------------------- ### Rebuild Elasticsearch Index Source: https://github.com/sulu/suluarticlebundle/blob/2.6/UPGRADE.md Use this command to rebuild the Elasticsearch index for articles. Replace ###LOCALE### with the desired locale code (e.g., en, de). ```bash bin/adminconsole sulu:article:index-rebuild ###LOCALE### ``` -------------------------------- ### Export articles to XLIFF Source: https://github.com/sulu/suluarticlebundle/blob/2.6/Resources/doc/xliff.md Use the sulu:article:export command to generate an XLIFF file for a specific locale. ```bash $ bin/adminconsole sulu:article:export export.xliff en ```