### Build and Run Strapi After Plugin Installation Source: https://github.com/virtuslab-open-source/strapi-plugin-navigation/blob/master/README.md After installing the Strapi Navigation plugin, these commands rebuild the Strapi instance and then start it in development mode. This ensures the plugin is properly integrated and accessible in the Strapi UI. ```bash yarn build yarn develop ``` -------------------------------- ### Install Dependencies and Link Strapi Plugin Source: https://github.com/virtuslab-open-source/strapi-plugin-navigation/blob/master/README.md After cloning the repository, install all project dependencies using `yarn install`. Then, use `yarn watch:link` to enable file change watching via Strapi's `plugin-sdk`, which helps in development by linking the plugin to your Strapi project. ```ts // Install all dependencies yarn install // Watch for file changes using `plugin-sdk` and follow the instructions provided by this official Strapi developer tool yarn watch:link ``` -------------------------------- ### Install Strapi Navigation Plugin via Yarn Source: https://github.com/virtuslab-open-source/strapi-plugin-navigation/blob/master/README.md This command installs the latest version of the Strapi Navigation plugin using Yarn. It's the first step to integrate the plugin into your Strapi project. ```bash yarn add strapi-plugin-navigation@latest ``` -------------------------------- ### Example GraphQL Response for Rendered Navigation Source: https://github.com/virtuslab-open-source/strapi-plugin-navigation/blob/master/README.md Illustrates the JSON structure returned by the `renderNavigation` GraphQL query. It shows a list of navigation items, each with `id`, `title`, `path`, `related` content, and nested `items` for hierarchical structures. ```json { "data": { "renderNavigation": [ { "id": 8, "title": "Test page", "path": "/test-path", "related": { "id": 3, "__typename": "WithFlowType", "Name": "Test" }, "items": [ { "id": 11, "title": "Nested", "path": "/test-path/nested-one", "related": { "id": 1, "__typename": "Page", "Title": "Eg. Page title" } } ] }, { "id": 10, "title": "Another page", "path": "/another", "related": { "__typename": "Page", "Title": "Eg. Page title" }, "items": [] } ] } } ``` -------------------------------- ### Example GraphQL `navigationItemRelated` Configuration Source: https://github.com/virtuslab-open-source/strapi-plugin-navigation/blob/master/README.md Provides a concrete example of configuring the `navigationItemRelated` property with specific content type names like 'Page' and 'UploadFile'. This demonstrates how to link navigation items to your custom content types for GraphQL resolution. ```ts gql: { navigationItemRelated: ['Page', 'UploadFile'], }, ``` -------------------------------- ### Registering Lifecycle Hooks for Navigation Content Types Source: https://github.com/virtuslab-open-source/strapi-plugin-navigation/blob/master/README.md Provides an example of how to register asynchronous lifecycle hooks for `navigation` and `navigation-item` content types using `registerLifecycleHook`. It demonstrates listening to the `afterCreate` event and performing an action like logging the result, allowing custom logic to be executed at specific points in the content lifecycle. ```ts const navigationCommonService = strapi.plugin('navigation').service('common'); navigationCommonService.registerLifecycleHook({ callback: async ({ action, result }) => { const saveResult = await logIntoSystem(action, result); console.log(saveResult); }, contentTypeName: 'navigation', hookName: 'afterCreate' }); navigationCommonService.registerLifecycleHook({ callback: async ({ action, result }) => { const saveResult = await logIntoSystem(action, result); console.log(saveResult); }, contentTypeName: 'navigation-item', hookName: 'afterCreate' }); ``` -------------------------------- ### Retrieve All Navigation Items (GET /api/navigation) Source: https://github.com/virtuslab-open-source/strapi-plugin-navigation/blob/master/README.md This endpoint fetches a list of all available navigation items. Optional parameters allow filtering by locale and ordering results. The response is an array of navigation objects, each containing details such as ID, name, slug, and locale. ```APIDOC GET /api/navigation Parameters: locale (optional): string - The locale to filter navigation items. orderBy (optional): string - Field to order results by. orderDirection (optional): string - Direction of ordering (e.g., 'asc', 'desc'). ``` ```HTTP https://localhost:1337/api/navigation?locale=en ``` ```json [ { "id": 383, "documentId": "njx99iv4p4txuqp307ye8625", "name": "Floor", "slug": "floor-pl", "visible": true, "createdAt": "2023-09-29T12:45:54.399Z", "updatedAt": "2023-09-29T13:44:08.702Z", "locale": "pl" }, { "id": 384, "documentId": "njx99iv4p4txuqp307ye8625", "name": "Floor", "slug": "floor-fr", "visible": true, "createdAt": "2023-09-29T12:45:54.399Z", "updatedAt": "2023-09-29T13:44:08.725Z", "locale": "fr" }, { "id": 382, "documentId": "njx99iv4p4txuqp307ye8625", "name": "Floor", "slug": "floor", "visible": true, "createdAt": "2023-09-29T12:45:54.173Z", "updatedAt": "2023-09-29T13:44:08.747Z", "locale": "en" }, { "id": 374, "documentId": "njx99iv4p4txuqp307ye8625", "name": "Main navigation", "slug": "main-navigation-pl", "visible": true, "createdAt": "2023-09-29T12:22:30.373Z", "updatedAt": "2023-09-29T13:44:08.631Z", "locale": "pl" }, { "id": 375, "documentId": "njx99iv4p4txuqp307ye8625", "name": "Main navigation", "slug": "main-navigation-fr", "visible": true, "createdAt": "2023-09-29T12:22:30.373Z", "updatedAt": "2023-09-29T13:44:08.658Z", "locale": "fr" }, { "id": 373, "documentId": "njx99iv4p4txuqp307ye8625", "name": "Main navigation", "slug": "main-navigation", "visible": true, "createdAt": "2023-09-29T12:22:30.356Z", "updatedAt": "2023-09-29T13:44:08.680Z", "locale": "en" } ] ``` -------------------------------- ### Render Navigation Structure by ID or Slug (GET /api/navigation/render) Source: https://github.com/virtuslab-open-source/strapi-plugin-navigation/blob/master/README.md This endpoint renders a navigation structure based on a provided navigation ID or slug. The rendering format can be controlled by the 'type' parameter, supporting 'TREE', 'RFR', or 'FLAT' (default). It returns a structured representation of the navigation, including nested items and related content. ```APIDOC GET /api/navigation/render/{navigationIdOrSlug} Parameters: navigationIdOrSlug (required): string - The ID or slug of the navigation to render. type (optional): string - The rendering format. Accepted values: 'TREE', 'RFR', or 'FLAT' (default). ``` ```HTTP https://localhost:1337/api/navigation/render/njx99iv4p4txuqp307ye8625 ``` ```json [ { "id": 1, "documentId": "njx99iv4p4txuqp307ye8625", "title": "News", "type": "INTERNAL", "path": "news", "externalPath": null, "uiRouterKey": "News", "menuAttached": false, "parent": null, "master": 1, "created_at": "2020-09-29T13:29:19.086Z", "updated_at": "2020-09-29T13:29:19.128Z", "related": { "__contentType": "Page", "id": 1, "documentId": "njx99iv4p4txuqp307ye8625", "title": "News" } } ] ``` ```HTTP https://localhost:1337/api/navigation/render/njx99iv4p4txuqp307ye8625?type=TREE ``` ```json [ { "title": "News", "menuAttached": true, "path": "/news", "type": "INTERNAL", "uiRouterKey": "news", "slug": "benefits", "external": false, "related": { "__contentType": "Page", "id": 1, "title": "News" }, "items": [ { "title": "External url", "menuAttached": true, "path": "http://example.com", "type": "EXTERNAL", "uiRouterKey": "generic", "external": true } ] } ] ``` ```HTTP https://localhost:1337/api/navigation/render/njx99iv4p4txuqp307ye8625?type=RFR ``` ```json { "pages": { "News": { "id": "News", "title": "News", "related": { "contentType": "page", "collectionName": "pages", "id": 1 }, "path": "/news", "slug": "news", "parent": null, "menuAttached": true }, "Community": { "id": "Community", "title": "Community", "related": { "contentType": "page", "collectionName": "pages", "id": 2 }, "path": "/community", "slug": "community", "parent": null, "menuAttached": true }, "Highlights": { "id": "Highlights", "title": "Highlights", "related": { "contentType": "page", "collectionName": "pages", "id": 3 }, "path": "/community/highlights", "slug": "community-highlights", "parent": "Community", "menuAttached": false } }, "nav": { "root": [ { "label": "News", "type": "internal", "page": "News" }, { "label": "Community", "type": "internal", "page": "Community" }, { "label": "External url", "type": "external", "url": "http://example.com" } ], "Community": [ { "label": "Highlights", "type": "internal", "page": "Highlights" } ] } } ``` -------------------------------- ### Clone Strapi Plugin Navigation Repository Source: https://github.com/virtuslab-open-source/strapi-plugin-navigation/blob/master/README.md To contribute to the Strapi Plugin Navigation project, begin by cloning the repository from GitHub. This command will fetch the project files to your local machine. ```bash git clone git@github.com:VirtusLab-Open-Source/strapi-plugin-navigation.git ``` -------------------------------- ### Strapi Navigation Plugin Configuration Properties Source: https://github.com/virtuslab-open-source/strapi-plugin-navigation/blob/master/README.md This section details the available configuration properties for the Strapi Navigation plugin. These properties allow customization of navigation items, content type integration, and GraphQL settings. ```APIDOC Properties: additionalFields: Description: Additional fields for navigation items. allowedLevels: Description: Maximum level for which you're able to mark item as "Menu attached". contentTypes: Description: UIDs of related content types. contentTypesNameFields: Description: Definition of content type title fields. Format: 'api::.': ['field_name_1', 'field_name_2'] Default: If not set, titles are pulled from fields like ['title', 'subject', 'name']. Tip: Proper content type UID can be found in the URL of Content Manager. pathDefaultFields: Description: The attribute to copy the default path from per content type. Syntax: 'api::.': ['url_slug', 'path'] gql: Description: Settings for GraphQL integration. cascadeMenuAttached: Description: Set to 'Disabled' if "Menu attached" should not cascade on child items. ``` -------------------------------- ### Strapi Plugin Navigation Public API Specification Source: https://github.com/virtuslab-open-source/strapi-plugin-navigation/blob/master/README.md Details the public REST and GraphQL API endpoints for rendering navigation structures, including available query parameters to filter and customize the output. ```APIDOC Public API Endpoints: REST API: /api/navigation/render/:navigationIdOrSlug GraphQL API: (implied by Strapi's GraphQL capabilities) Query Parameters: navigationIdOrSlug: Description: ID or slug for which your navigation structure is generated. Examples: REST: https://localhost:1337/api/navigation/render/njx99iv4p4txuqp307ye8625 REST: https://localhost:1337/api/navigation/render/main-menu type: Type: Enum (FLAT, TREE, RFR) Description: Structure type of returned navigation. Example: https://localhost:1337/api/navigation/render/njx99iv4p4txuqp307ye8625?type=FLAT menu (menuOnly for GQL): Type: Boolean Description: Query only navigation items that are attached to menu. Example: https://localhost:1337/api/navigation/render/njx99iv4p4txuqp307ye8625?menu=true path: Type: String Description: Query navigation items by its path. Example: https://localhost:1337/api/navigation/render/njx99iv4p4txuqp307ye8625?path=/home/about-us ``` -------------------------------- ### Configure Strapi Plugin Order for GraphQL Source: https://github.com/virtuslab-open-source/strapi-plugin-navigation/blob/master/README.md To ensure GraphQL schemas and types like `Navigation` are properly injected when using `strapi-plugin-navigation`, configure the `config/plugins.{js|ts}` file. The `graphql` plugin should be initialized after the `navigation` plugin to allow types to be injected correctly. ```ts module.exports = { navigation: { enabled: true }, graphql: { enabled: true }, }; ``` -------------------------------- ### Configure Strapi Navigation Plugin in plugins.js/ts Source: https://github.com/virtuslab-open-source/strapi-plugin-navigation/blob/master/README.md This TypeScript/JavaScript snippet demonstrates how to configure the Strapi Navigation plugin within the `config/plugins.{js|ts}` file. It shows common configuration options such as enabling the plugin, defining additional fields, specifying content types, and setting up content type name and path fields. ```typescript module.exports = ({ env }) => ({ // ... navigation: { enabled: true, config: { additionalFields: ['audience', { name: 'my_custom_field', type: 'boolean', label: 'My custom field' }], contentTypes: ['api::page.page'], contentTypesNameFields: { 'api::page.page': ['title'] }, pathDefaultFields: { 'api::page.page': ['slug'] }, allowedLevels: 2, gql: {...}, } } }); ``` -------------------------------- ### GraphQL API for Rendered Navigation Structure Source: https://github.com/virtuslab-open-source/strapi-plugin-navigation/blob/master/README.md Documentation for the `renderNavigation` GraphQL query, which returns a rendered navigation structure. The structure depends on the specified `type` (`TREE`, `RFR`, or `FLAT` by default). It functions similarly to the REST API for navigation rendering. ```APIDOC Query: renderNavigation Description: Returns a rendered navigation structure. Parameters: navigationIdOrSlug: string (required) - The ID or slug of the navigation to render. type: enum (optional) - The desired rendering type. Possible values: TREE, RFR, FLAT (default). menuOnly: boolean (optional) - If true, renders only menu items. Returns: Array of NavigationItem objects (structure shown in example response) ``` -------------------------------- ### Strapi Navigation Plugin Public API Authorization Strategies Source: https://github.com/virtuslab-open-source/strapi-plugin-navigation/blob/master/README.md Explains the two main authorization strategies for the plugin's Public API (REST and GraphQL): user-based (Public, Authenticated roles) and token-based (Full Access, Custom tokens). It highlights the implications of each approach, including the need for authentication tokens and recommendations for granular access. ```APIDOC Authorization Strategy: User based: Public Role: Description: Default role for unauthenticated users. Enabling Public API here makes it fully public without any permission checks. Authenticated Role: Description: Default role for Strapi Users. If enabled, requires User authentication token (Bearer ) for calls. Token based: Full Access Token: Description: Grants full access to every Strapi Content API, including plugin endpoints. Custom Token: Description: Provides granular access management to every Strapi Content API endpoint as well as plugin Public API (recommended approach). Note: Read-Only tokens do not cover access to plugin Public API 'render' and 'renderChild' endpoints. Use Custom token type for granular and secured access. ``` -------------------------------- ### GraphQL Query for Rendered Navigation Structure Source: https://github.com/virtuslab-open-source/strapi-plugin-navigation/blob/master/README.md Demonstrates how to query the `renderNavigation` endpoint using GraphQL to retrieve a navigation structure. It specifies `navigationIdOrSlug`, `type` (e.g., `TREE`), and `menuOnly` parameters, and selects various fields including `id`, `title`, `path`, and `related` content types like `Page` or `WithFlowType`. ```graphql query { renderNavigation(navigationIdOrSlug: "main-navigation", type: TREE, menuOnly: false) { id title path related { id __typename ... on Page { Title } ... on WithFlowType { Name } } items { id title path related { id __typename ... on Page { Title } ... on WithFlowType { Name } } } } } ``` -------------------------------- ### Enable Strapi Navigation Plugin in Configuration Source: https://github.com/virtuslab-open-source/strapi-plugin-navigation/blob/master/README.md To activate the `navigation` plugin within your Strapi project, modify the `config/plugins.{js|ts}` file. Ensure the `enabled` property for `navigation` is set to `true`. ```ts //... 'navigation': { enabled: true, //... } //... ``` -------------------------------- ### Define GraphQL Union Types for Navigation Source: https://github.com/virtuslab-open-source/strapi-plugin-navigation/blob/master/README.md Illustrates the GraphQL union types required for the navigation plugin to define the GQL response format for fetched data. This configuration ensures proper type resolution for `master`, `items`, and `related` navigation elements. ```gql master: Int items: [NavigationItem] related: NavigationRelated ``` -------------------------------- ### Extend Strapi Navigation Plugin for Custom Slug Generation Source: https://github.com/virtuslab-open-source/strapi-plugin-navigation/blob/master/README.md Shows how to extend the Strapi Navigation plugin's `getSlug` service method in `admin/src/index.js` to add custom logic, such as appending a suffix to generated slugs, by overriding the original function. This allows for tailored slug formatting beyond the default plugin behavior. ```ts // path: /admin/src/index.js module.exports = { // ... bootstrap({ strapi }) { const navigationCommonService = strapi.plugin('navigation').service('common'); const originalGetSlug = navigationCommonService.getSlug; const preprocess = (q) => { return q + 'suffix'; }; navigationCommonService.getSlug = (query) => { return originalGetSlug(preprocess(query)); }; } }; ``` -------------------------------- ### RFR Navigation Item Data Structure Source: https://github.com/virtuslab-open-source/strapi-plugin-navigation/blob/master/README.md Illustrates a simplified navigation item structure, often used for specific rendering needs, showing its ID, title, related content type, path, and parent reference. ```json { "id": "News", "title": "News", "related": { "contentType": "page", "collectionName": "pages", "id": 1 }, "path": "/news", "slug": "news", "parent": null, "menuAttached": true } ``` -------------------------------- ### Additional Fields Configuration Object Structure Source: https://github.com/virtuslab-open-source/strapi-plugin-navigation/blob/master/README.md Describes the structure for configuring additional fields in the `config.(js|ts)` file, detailing the `additionalFields` array and the `CustomField` type with its properties (`type`, `name`, `label`, `enabled`). The `name` property must be unique, and it's advised not to edit `name` and `type` after creation. ```APIDOC config: { additionalFields: Array } CustomField: { type: 'string' | 'boolean' | 'media', name: string, label: string, enabled?: boolean } ``` -------------------------------- ### Strapi Navigation Plugin RBAC Permissions Source: https://github.com/virtuslab-open-source/strapi-plugin-navigation/blob/master/README.md Details the specific permissions available for the Strapi Navigation plugin within the Admin Panel's Roles settings. It outlines mandatory permissions like 'Read' for panel access and other permissions for updating navigation structures and plugin settings. ```APIDOC Plugins -> Navigation -> Read: Purpose: Grants access to the Navigation Panel. Plugins -> Navigation -> Update: Purpose: Allows users to change Navigation structure. Plugins -> Navigation -> Settings: Purpose: Special permission for users to change plugin settings. ``` -------------------------------- ### Flat Navigation Item Data Structure Source: https://github.com/virtuslab-open-source/strapi-plugin-navigation/blob/master/README.md Represents a single navigation item in a flat structure, including its ID, title, type, path, and relationships. The 'parent' field indicates the parent item's ID, and 'master' refers to the main navigation ID. ```json { "id": 1, "documentId": "njx99iv4p4txuqp307ye8625", "title": "News", "type": "INTERNAL", "path": "news", "externalPath": null, "uiRouterKey": "News", "menuAttached": false, "parent": 8, "master": 1, "createdAt": "2020-09-29T13:29:19.086Z", "updatedAt": "2020-09-29T13:29:19.128Z", "related": { /**/ }, "audience": [] } ``` -------------------------------- ### Configure GraphQL `navigationItemRelated` Property Source: https://github.com/virtuslab-open-source/strapi-plugin-navigation/blob/master/README.md Shows the basic structure for configuring the `gql` property within the plugin's configuration, specifically for `navigationItemRelated`. This property is used to define the union types that will be used to resolve related content types in GraphQL queries. ```ts gql: { navigationItemRelated: [''], }, ``` -------------------------------- ### Tree Navigation Item Data Structure Source: https://github.com/virtuslab-open-source/strapi-plugin-navigation/blob/master/README.md Defines a navigation item within a hierarchical tree structure, including its title, path, type, and a nested 'items' array for child navigation items. 'external' indicates if the path is an external URL. ```json { "title": "News", "menuAttached": true, "path": "/news", "type": "INTERNAL", "uiRouterKey": "news", "slug": "benefits", "external": false, "related": { // }, "items": [ { "title": "External url", "menuAttached": true, "path": "http://example.com", "type": "EXTERNAL", "uiRouterKey": "generic", "external": true } // < Tree Navigation Item models > ] } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.