Categories

Note

此页面的内容需要进行重大更新。旧页面包含过时且可能不准确的信息。您仍然可以在 Mautic Developer Documentation archived repository 中访问它。

如果您有兴趣帮助开发此页面和其他新内容的,请考虑加入文档编写工作。

请阅读 Contributing Guidelines 和 Contributing to Mautic’s documentation 以开始您的贡献。

Categories 是一种组织 Mautic 元素的机制。 Mautic 有一个 CategoryBundle,您可以利用它将 Categories 集成到您的插件中。

添加 Categories

您可以通过插件的 config.php 文件来添加 Categories,通过将其作为键添加到返回的配置数组中:

<?php

'categories' => [
    'plugin:helloWorld' => 'mautic.helloworld.world.categories'
]

请使用 plugin: 作为 Category 键的前缀,因为它决定了管理 Categories 的权限。 helloWorld 应该与权限类名匹配。

配置 Routes 中的 Categories

您无需为 Categories 添加自定义路由,但是,当生成指向插件的 Category 列表的 URL 时,请使用以下代码:

<?php

$categoryUrl = $router->generateUrl('mautic_category_index', ['bundle' => 'plugin:helloWorld']);

在表单中包含 Categories

要将 Category 选择列表添加到表单中,请使用 category 作为表单类型,并传递 bundle 作为选项:

<?php

$builder->add('category', 'category', [
    'bundle' => 'plugin:helloWorld'
]);

限制 Category 管理

要限制对 Categories 的访问,请在插件的 Permission class 中使用以下方法。

在 __construct() 方法中,添加 $this->addStandardPermissions('categories');,然后在 buildForm() 方法中,添加 $this->addStandardFormFields('helloWorld', 'categories', $builder, $data);.

请参阅 Roles and Permissions 中的代码示例。

这两个标准辅助方法会添加 view、edit、create、delete、publish 和 full 权限,用于管理 Categories。