flowpack/media-ui 问题修复 & 功能扩展

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

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

flowpack/media-ui

Composer 安装命令:

composer require flowpack/media-ui

包简介

This module allows managing media assets including pictures, videos, audio and documents.

README 文档

README

This package contains the new interface to manage media in Neos CMS (7.3 - 8.3).

During the initial development the package will be in the Flowpack namespace and will later replace neos/media-browser.

If you want to use Neos, please have a look at the Neos documentation.

Screenshots

Asset management

Asset selection

Asset details

Installation

Run the following command to install it:

composer require flowpack/media-ui

Afterward you should execute doctrine migrations, as the package adds new columns to the database:

./flow doctrine:migrate

In some rare cases it's necessary to flush the caches to prevent errors PHP errors, as the package extends some core classes:

./flow flow:cache:flush

Then you should update the paths of existing asset collections:

./flow assetcollections:updatepaths

This is only necessary once after the installation. Afterward the paths will be updated automatically.

What changes?

This package will currently add a second media backend module called Media (new) and a new media selection screen for asset and image editors. The old media module will still be available until this package replaces it completely with a later, major release of Neos.

Disabling the old Media module

If you don't need the old Media module, you can disable it in Settings.yaml:

Neos:
  Neos:
    modules:
      management:
        submodules:
          media:
            # Disable the default media module and use the new media ui
            enabled: false
          mediaui:
            # Moves the new module to top
            position: start

Disabling the new media selection

If you want to use this package in a real project you might want to disable the new media selection if it doesn't work as expected. You can do this by adding the following setting to your Settings.yaml:

Neos:
  Neos:
    Ui:
      frontendConfiguration:
        Flowpack.Media.Ui:
          useNewMediaSelection: false

Privileges

By default any editor (Neos.Neos:AbstractEditor) can access the new media module and manage assets, tags and collections.

To adjust the privileges you can use the following privilege targets for any role:

- privilegeTarget: 'Flowpack.Media.Ui:ManageAssets'
  permission: GRANT
- privilegeTarget: 'Flowpack.Media.Ui:ManageTags'
  permission: GRANT
- privilegeTarget: 'Flowpack.Media.Ui:ManageAssetCollections'
  permission: GRANT

Hierarchical asset collections

This package will enable a hierarchical asset collection structure via AOP (until the feature is in the Neos core). With this feature you can add a collection in another collection or assign existing ones to another and this way create a structure comparable with folders in your computer's file system.

It is recommended to enable the feature flag limitToSingleAssetCollectionPerAsset (see below) for a better experience - see below.

The package also provides the \Flowpack\Media\Ui\Security\Authorization\Privilege\ReadHierarchicalAssetCollectionPrivilege with the additional method isInPath(<string>), which can be used to control access to the collections.

privilegeTargets:
  'Flowpack\Media\Ui\Security\Authorization\Privilege\ReadHierarchicalAssetCollectionPrivilege':
    'Some.Package:ReadSpecialAssetCollectionAndSubCollections':
      matcher: 'isInPath("/important-collections")'
  'Flowpack\Media\Ui\Security\Authorization\Privilege\ReadAssetPrivilege':
    'Some.Package:ReadSpecialAssets':
      matcher: 'isInCollectionPath("/important-collections")'

Optional features

Limit assets to be only assigned to one AssetCollection

By limiting assets to only be in one collection you can enforce a more folder-like experience:

Neos:
  Neos:
    Ui:
      frontendConfiguration:
        Flowpack.Media.Ui:
          # Only allow a single asset collection selection per asset to treat collection like folders
          limitToSingleAssetCollectionPerAsset: true

Fast asset usage calculation & unused assets view

The default asset usage in Neos is very slow as it is calculated when at runtime. For that it checks your whole project where an asset might be used. For the new Media UI, a new method has been implemented via the package Flowpack.Neos.AssetUsage.

The package provides a service that stores all asset usage references in a database table (other storages can be implemented). After installing the package and its peer dependencies, you should therefore update the usage reference index:

./flow assetusage:update

You have to do this only once for each instance of the application, f.e. dev / staging / production. Afterwards the index will automatically be kept up-to-date. Make sure you run the command manually again after you run imports or change the content repository in any other unusual way. This will clean up any outdated usage.

You can now enable the feature via the following setting:

Neos:
  Neos:
    Ui:
      frontendConfiguration:
        Flowpack.Media.Ui:
          queryAssetUsage: true

Now the "delete" action for assets will be disabled if an asset is in use, and the filter dropdown contains a new item "Unused". Selecting it will switch the main view to show all unused assets.

Customise usage details

The usage calculation mechanism in Neos already supports custom usage providers via the AssetUsageStrategyInterface. If your strategy implements this interface, the Media UI will show the usages separately for each strategy.

By also implementing the UsageDetailsProviderInterface you can provide a custom label for the strategy and also custom headers and values for each entry.

Show similar assets

This package provides a SimilarAssetStrategyInterface. Other packages can implement this interface and provide a list of other assets based on a given asset.

Example for this could be perceptually similar images or assets with similar filenames.

Given that you installed a package with a strategy, enable the feature in the ui with the following setting:

Neos:
  Neos:
    Ui:
      frontendConfiguration:
        Flowpack.Media.Ui:
          showSimilarAssets: true

Disable asset redirect checkbox

If you don't want to or can't use the automatic generation of redirects for assets, you can disable it with the following setting:

Neos:
  Neos:
    Ui:
      frontendConfiguration:
        Flowpack.Media.Ui:
          createAssetRedirectsOption: false

Architecture

API / GraphQL

This module introduces a GraphQL API for the Neos Media system. The API is open and can be reused for custom apps. A valid Neos backend user is required to access it, but you can define custom policies and an authentication provider to allow access without a user and f.e. use a token based authentication.

Schema

The GraphQL schema can be found here.

Interface

This module uses React for the implementation of the UI. Currently, most parts of the application are implemented as feature based packages in the packages folder. In future releases the code will be further split into smaller packages.

State management

Query variables

Query related state variables are stored via GraphQL Mutations in the Apollo Client Cache. Some of those variables are then persisted into the localstorage of the browser.

Resolved query result state

The MediaUI provider currently stores the results in its state and provides them to all child components via provider values. This will probably be changed to only set shared states that all components can access.

Component states

Component state should be stored with React hooks.

Shared component states

The shared component states are current implemented via React Recoil atoms and selectors. See the state folders in the various modules in packages for examples.

Those should be used every time multiple components share a state that is not relevant for the GraphQL queries.

Fund the development

We need your help to develop this package. You can find supporter badges on the official Neos funding site.

Contributing

To start with development, make sure you have nvm and yarn installed and run the following command in the package's folder:

yarn

Running the standalone dev server without Neos

The dev server allows to run the module without a Neos instance. This is also the basis for running most tests and implementing new features.

yarn dev

Enter localhost:8000 in your browser, and you will have a running media ui instance without Neos.

Building the module assets

This will create a production build of the module assets.

yarn build

Recompile files during development

The following command will recompile and reload the media module when changes to the scripts happen:

yarn watch

Only watch the backend module code

yarn watch:module

Only watch the UI plugin

yarn watch:editor

Check for code quality

Run the following command to verify the TypeScript files:

yarn lint

Run e2e tests

First start the dev server via yarn dev and the run the following command to execute all end-to-end tests:

yarn test:e2e

The test configuration is defined in .testcaferc.json.

To use a different browser, you can define it when running the tests:

yarn test firefox

Check out the Testcafe documentation for more information and supported browsers.

Run phpstan for codestyle checks

First, make sure you have phpstan installed.

If the package is installed in a Neos distribution:

composer run codestyle

If the package is standalone

composer run codestyle:ci

Run PHPUnit for unit tests

If the package is installed in a Neos distribution:

composer run test

If the package is standalone

composer run test:ci

Other development hints

Before you commit

Please don't add the compiled frontend assets to your commits/PRs.

We will build the assets when a new release is due.

If you want to build the assets for a release, use the following command to prevent cache issues:

yarn build:no-cache

Register additional icons

Font Awesome icons are registered in packages/src/lib/FontAwesome. This way the bundle size is kept to a minimum.

Patches

Several patches are applied during installation via patch-package. Additional patches can be generated and stored there with the same tool if necessary.

Connection between the backend module and UI plugin

The codebase is 99% reused between the backend module and the asset selection in the Neos UI. Make sure changes work in both worlds or provide a compatibility layer in the corresponding initialisation.

Development helpers

  • Extension for debugging GraphQL schema and queries in the browser
  • Plugin for code completion and helpers in PHPStorm

License

See license.

flowpack/media-ui 适用场景与选型建议

flowpack/media-ui 是一款 基于 TypeScript 开发的 Composer 扩展包,目前已累计 94.97k 次下载、GitHub Stars 达 21, 最近一次更新时间为 2020 年 06 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 flowpack/media-ui 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 94.97k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 21
  • 点击次数: 18
  • 依赖项目数: 2
  • 推荐数: 1

GitHub 信息

  • Stars: 21
  • Watchers: 8
  • Forks: 25
  • 开发语言: TypeScript

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2020-06-19