vardot / entity-definition-update-manager
实体定义更新管理器 - 为开发者提供执行自动实体更新的类。
Requires
- drupal/core: ~8.9 || ~9.0 || ~10
README
为开发者提供执行自动实体更新的类。
仅用于开发环境。不要在生产网站上使用。
已移除自动实体更新支持
https://www.drupal.org/node/3034742
用户已弃用函数:在 Drupal 8.7.0 中弃用 EntityDefinitionUpdateManagerInterface::applyUpdates()
函数,并在 Drupal 9.0.0 之前已移除。
如何使用实体定义更新管理器类
为实体定义更新管理器定制的类。
在您的根 composer.json 文件中引入包
"vardot/entity-definition-update-manager": "~1.0"
或使用命令在项目中引入包
$ composer require vardot/entity-definition-update-manager:~1.0
1. 添加所需的命名空间
在自定义模块或自定义安装配置文件中添加以下命名空间。
use Vardot\Entity\EntityDefinitionUpdateManager;
2. 执行配置导入或更新
在 hook_install 或 hook_update 中导入或更新配置,或在任何 post install 或 post update 中。
3. 从定义类中运行类解析器实例
// Entity updates to clear up any mismatched entity and/or field definitions
// And Fix changes were detected in the entity type and field definitions.
\Drupal::classResolver()
->getInstanceFromDefinition(EntityDefinitionUpdateManager::class)
->applyUpdates();
示例:安装时使用
Varbase 核心组件 在安装时管理大量配置。安装后需要更新实体定义。
查看 varbase_core_install
钩子函数
https://git.drupalcode.org/project/varbase_core/-/blob/9.0.x/varbase_core.install#L77
示例:更新时使用
Varbase API 在某个时刻需要在 hook_update 中更新配置。更新实体定义后才能正常工作。没有实体定义更新将无法工作。
查看 varbase_api_update_8702
钩子函数
https://git.drupalcode.org/project/varbase_api/-/blob/9.0.x/varbase_api.install#L159
何时使用和何时不使用?
当配置导入/更新按正常方式工作时不使用。
如果所有配置都在 config/install
中,并且安装过程中没有问题。
当自定义管理的配置按自定义顺序导入或更新,并且导入过程中涉及自定义操作或更改时使用。
如果模块或配置文件具有大量可选或管理配置。这些配置位于 config/optional
、config/managed
或其他物理位置。然后它们使用自定义 Drupal Config Factory 或 Drupal Install Factory 进行导入或更新。
必须在每个安装步骤的最后至少运行一次,例如对于 Varbase、Vardoc、Uber Publisher 等安装配置文件。