cyber-gh/nova-page-manager 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

cyber-gh/nova-page-manager

Composer 安装命令:

composer require cyber-gh/nova-page-manager

包简介

Page(s) and region(s) manager for Laravel Nova.

README 文档

README

Latest Version on Packagist Total Downloads

This Laravel Nova package allows you to create and manage pages and regions. The package is geared towards headless CMS's.

Requirements

  • Laravel Nova <= 2.0.7 || >= 2.0.10

Laravel Nova 2.0.8 and 2.0.9 are breaking for Nova Page Manager.

Features

  • Pages and Regions management
  • Programmatically created templates for Pages and Regions
  • Multilanguage support
  • Optional pages draft support

Screenshots

Index View

Filter Dropdown

Page Content Area

Installation

Install the package in a Laravel Nova project via Composer and run migrations:

# Install package
composer require optimistdigital/nova-page-manager

# Run automatically loaded migrations
php artisan migrate

Publish the nova-page-manager configuration file and edit it to your preference:

php artisan vendor:publish --provider="OptimistDigital\NovaPageManager\ToolServiceProvider" --tag="config"

Register the tool with Nova in the tools() method of the NovaServiceProvider:

// in app/Providers/NovaServiceProvider.php

public function tools()
{
    return [
        // ...
        new \OptimistDigital\NovaPageManager\NovaPageManager
    ];
}

Usage

Creating templates

Templates can be created using the following Artisan command:

php artisan pagemanager:template {className}

This will ask you a few additional details and will create a base template in App\Nova\Templates.

The template base has a few properties:

// Define whether the template is for a page or a region
// Applicable values: 'page', 'region'
public static $type = 'page';

// The unique name for the page, usually similar to a slug
public static $name = 'about-us';

// The package has built in SEO fields support
// This boolean decides whether or not to display them
public static $seo = false;

// If you want to have multiple views with different
// templates, you can set two templates to have the
// same 'view' string and use it instead for matching
public static $view = null;

// Return all fields here, just as you would inside a resource
public function fields(Request $request): array
{
  return [
      Text::make('Title', 'title')
  ];
}

Registering templates

All your templates have to be registered in the config/nova-page-manager.php config file.

// in /config/nova-page-manager.php

// ...
'templates' => [
  \App\Nova\Templates\HomePageTemplate::class,
],
// ...

Defining locales

Locales can be defined similarly to how templates are registered. The config accepts a dictionary of locales.

// in /config/nova-page-manager.php

// ...
'locales' => [
  'en' => 'English',
  'et' => 'Estonian',
],

// OR

'locales' => function () {
  return Locale::all()->pluck('name', 'key');
},

// if you wish to cache the configuration, pass a reference instead:

'locales' => NovaPageManagerConfiguration::class . '::locales',
// ...

Enabling page draft feature

Draft feature allows you to create previews of pages before publishing them. By default this feature is not installed, but you can install nova-drafts with the following command.

composer require optimistdigital/nova-drafts

Overriding SEO fields

The default SEO fields can be overridden using the configuration file. The configuration file contains the key seo_fields which accepts an array (or a callable which returns an array) of fields.

Modify page path

To add a locale prefix to page paths or to modify page paths for any other reason on the Page model, supply a callback to page_path in the config.

// in /config/nova-page-manager.php

// ...
'page_path' => function (Page $page) {
  return "{$page->locale}/{$page->path}";
},

// if you wish to cache the configuration, pass a reference instead:

'page_path' => NovaPageManagerConfiguration::class . '::pageUrl',
// ...

Add links to front-end pages

To display a link to the actual page next to the slug, add or overwrite the closure in config/nova-page-manager.php for the key page_url.

// in /config/nova-page-manager.php

// ...
'page_url' => function (Page $page) {
  return env('FRONTEND_URL') . $page->path;
},

// if you wish to cache the configuration, pass a reference instead:

'page_url' => NovaPageManagerConfiguration::class . '::pageUrl',
// ...

Overwrite package resources

You can overwrite the package resources (Page & Region) by setting the config options in nova-page-manager.php.

Note: If you create your resources under App\Nova namespace, to avoid key duplication you must manually register all other resources in the NovaServiceProvider. See registering resources on Nova documentation.

Modifying Field values

All fields have a registered macro resolveResponseUsing(callable $resolveResponseCallback) which allows you to modify the field's value before it is returned through the Page Manager's API (ie nova_get_page()).

The signature for the callback is: function ($value, $templateModel) { ... }.

For example:

Multiselect::make('Products')
  ->options(Product::all()->pluck('name', 'id'))
  ->resolveResponseUsing(function ($value, $templateModel) {
      return Product::findMany($value);
  }),

Helper functions

nova_get_pages_structure($previewToken)

The helper function nova_get_pages_structure($previewToken) returns the base pages structure (slugs, templates, child-parent relationships) that you can build your routes upon in the front-end. This does not return the pages' data. Preview token is optional and used only if draft feature is enabled. By default drafts will not be included in the structure.

Example response:

[
  {
    "locales": ["en_US", "et_EE"],
    "id": {
      "en_US": 3,
      "et_EE": 4
    },
    "name": {
      "en_US": "Home",
      "et_EE": "Kodu"
    },
    "slug": {
      "en_US": "/",
      "et_EE": "/"
    },
    "template": "home-page",
    "children": [
      {
        "locales": ["en_US"],
        "id": {
          "en_US": 5
        },
        "name": {
          "en_US": "About"
        },
        "slug": {
          "en_US": "about"
        },
        "template": "home-page"
      }
    ]
  }
]

nova_get_regions()

The helper function nova_get_regions() returns all the regions and their data.

Example response:

[
  {
    "locales": ["en_US"],
    "id": {
      "en_US": 3
    },
    "name": {
      "en_US": "Main header"
    },
    "template": "main-header",
    "data": {
      "en_US": {
        "content": [
          {
            "layout": "horizontal-text-section",
            "attributes": {
              "text": "Lorem ipsum"
            }
          }
        ]
      }
    }
  }
]

nova_get_page($pageId)

The helper function nova_get_page($pageId) finds and returns the page with the given ID.

Example response for querying page with ID 3 (nova_get_page(3)):

{
  "locale": "en_US",
  "id": 3,
  "name": "Home",
  "slug": "/",
  "data": {
    "banner": [],
    "categories_grid": []
  },
  "template": "home-page"
}

nova_get_page_by_slug($slug, $previewToken)

The helper function nova_get_page_by_slug($slug, $previewToken) finds and returns the page with the given slug. Preview token is optional and used to query draft pages when draft feature is enabled.

Example response for querying page with slug /home and preview token L1SVNKDzBNVkBq8EQSna (nova_get_page_by_slug("home", "L1SVNKDzBNVkBq8EQSna")):

{
  "locale": "en_US",
  "id": 3,
  "name": "Home",
  "slug": "/",
  "data": {
    "banner": [],
    "categories_grid": []
  },
  "template": "home-page",
  "preview_token": "L1SVNKDzBNVkBq8EQSna"
}

nova_page_manager_get_page_by_path($slug, $previewToken, $locale)

The helper function nova_page_manager_get_page_by_path($slug, $previewToken, $locale) finds and returns the page with the given path and all of it's parents. Preview token and locale are optional. Preview token is used to query draft pages when draft feature is enabled.

Example response for querying page with slug /home/about and preview token L1SVNKDzBNVkBq8EQSna (nova_page_manager_get_page_by_path("home/about", "L1SVNKDzBNVkBq8EQSna")):

{
  "locale": "en_US",
  "id": 2,
  "name": "about",
  "slug": "about",
  "parent": {
    "locale": "en_US",
    "id": 1,
    "name": "home",
    "slug": "home",
    "path": "/home",
    "parent_id": null,
    "data": {
      "banner": [],
      "categories_grid": []
    },
    "template": "home-page"
  },
  "parent_id": 1,
  "template": "about-page",
  "preview_token": "L1SVNKDzBNVkBq8EQSna",
  "path": "/home/about"
}

Credits

License

Nova page manager is open-sourced software licensed under the MIT license.

cyber-gh/nova-page-manager 适用场景与选型建议

cyber-gh/nova-page-manager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 105 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 01 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「page」 「manager」 「nova」 「laravel」 「optimistdigital」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 cyber-gh/nova-page-manager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 cyber-gh/nova-page-manager 我们能提供哪些服务?
定制开发 / 二次开发

基于 cyber-gh/nova-page-manager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 105
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 41
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-01-03