springworks/entity-diagrams

生成实体图,展示您的Craft网站的不同部分是如何相互关联的

2.0.1 2024-09-18 15:23 UTC

This package is auto-updated.

Last update: 2024-09-18 15:24:24 UTC


README

生成实体图,展示您的Craft网站的不同部分是如何相互关联的

要求

此插件需要Craft CMS 4.0.0或更高版本。

安装

要安装插件,请按照以下说明操作。

  1. 打开您的终端并转到您的Craft项目

     cd /path/to/project
    
  2. 然后告诉Composer加载插件

     composer require springworks/entity-diagrams
    
  3. 在控制面板中,转到设置 → 插件,然后点击实体图插件的“安装”按钮。

实体图概览

您是否曾想获得一个视觉概览,了解您的Craft网站的不同元素是如何相互配合的?实体图功能可以满足您的需求,生成一个可在浏览器中缩放和调整大小的SVG文件,或者下载为SVG文件以供您按需重用。

支持所有原生顶级Craft元素(条目、分类、标签、用户、全局和资产),您可以选择包含或排除某些元素类型,或创建描述网站子部分的自定义文档分组。如果安装了Craft Commerce插件,也支持商业产品。

插件将扫描请求的元素类型,并生成实体图,显示元素类型、所有字段的列表(按条目类型和字段布局选项卡细分),并将直接从相关关系字段包含相关元素类型之间的连接。

有选项包括所有字段或无字段,以及是否展开矩阵块以包括其子字段。

使用 entity-diagrams.php 配置文件,您可以添加自定义作者链接(如果某个部分的作者始终来自特定用户组,则很有用)。

您还可以创建自定义节点和链接。如果您有与网站其他元素交互的自定义数据库表,这将很有用。

这是一个强大的工具,可以直观地了解复杂网站的结构,对于让新开发者上手或接管由他人开发的网站非常有用。

配置实体图

通过在Craft配置文件夹中创建一个名为 entity-diagrans.php 的配置文件来配置实体图(即在 general.phpdb.php 配置文件旁边)。

配置文件可能看起来像这样

<?php
/**
 * entity-diagrams.php
 *
 * Optional manual config to create custom groupings of sections/category groups/globals/user groups/tag groups/asset volumes/products
 * to create entity diagrams of related parts of the system
 */

use craft\helpers\App;

return [
    'docGroups' => [ // Create predefined groups of elements to show in a diagram, 'name' => config array
    ],
    'options' => [ // default options, overridden by docGroups and UI
        'includeFields' => 1,
        'includeOnlyRelationFields' => 0,
        'expandMatrixBlocks' => 1,
        'includeAuthor' => 0,
        'includeCustomNodes' => 0,
        'includeCustomLinks' => 0,
    ],
    'dotOptions' => [
        'rankDir' => 'LR',
        'splines' => 'splines',
        'title' => 'Site Diagram',
    ],
];

其中最强大的功能是创建预定义的文档组(docGroups),这些文档组表示网站的独立子部分。您还可以使用此功能向图中添加自定义节点和链接。

文档组定义可能看起来像这样

<?php
/**
 * entity-diagrams.php
 *
 * Optional manual config to create custom groupings of sections/category groups/globals/user groups/tag groups/asset volumes/products
 * to create entity diagrams of related parts of the system
 */

use craft\helpers\App;

return [
    'docGroups' => [ // Create predefined groups of elements to show in a diagram, 'name' => config array
        'Group Name' => [
            'sections' => [ // list all section handles to include
                'news',
                'pages',
                'blog',
            ],
            'categories' => [ // list all categoryGroup handles to include
                'newsCategories',
                'blogCategories',
            ],
            'userGroups' => [ // list all userGroup handles to include
                'contributors',
                'editors',
            ],
            'globals' => [ // list all global handles to include
                'siteSettings',
            ],
            'tags' => [ // list all tag group handles to include
            ],
            'volumes' => [ // list all asset volume handles to include
                'newsImages',
                'blogImages',
            ],
            'products' => [ // list all Commerce product type handles to include
            ],
            'authorMap' => [ // map userGroups to sections if entry authorship in a section is limited to by userGroup
                'news' => ['editors'],
                'blog' => ['editors','contributors'],
            ],
            'customNodes' => [ // add any custom nodes not handled automatically by Craft, e.g. custom database tables.
            ],
            'customLinks' => [ // add any custom links not handled automatically by Craft, e.g. linking to a matrix block id in a field. Format: "section.handle|categoryGroup.handle|userGroup.handle[:field.handle] -> section.handle|categoryGroup.handle|userGroup.handle"
            ],
            'options' => [
                'includeFields' => 1,
                'includeOnlyRelationFields' => 0,
                'expandMatrixBlocks' => 1,
                'includeAuthor' => 1,
                'includeCustomNodes' => 0,
                'includeCustomLinks' => 1,
            ],
        ],
    ],
    'options' => [ // default options, overridden by docGroups and UI
        'includeFields' => 1,
        'includeOnlyRelationFields' => 0,
        'expandMatrixBlocks' => 1,
        'includeAuthor' => 0,
        'includeCustomNodes' => 0,
        'includeCustomLinks' => 0,
    ],
    'dotOptions' => [
        'rankDir' => 'LR',
        'splines' => 'splines',
        'title' => 'Site Diagram',
    ],
];

您可以添加任意数量的文档组。

包含或排除特定类型的所有或无元素

如果要包含特定类型的所有元素,则将数组值设置为 '*',如下所示

   ...
   'sections' => '*', // include all section handles
   ...

类似地,要排除特定类型的所有元素,则将数组值设置为空数组,如下所示

   ...
   'tags' => [], // don't include any tag groups
   ...

自定义节点和链接

您可以在文档组中包含自定义节点,例如自定义数据库表等,如下所示

   ...
   'customNodes' => [ // add any custom nodes not handled automatically by Craft, e.g. custom database tables.
       [
           'name' => 'User Progress - Tasks',
           'handle' => 'userProgressTasks',
           'type' => 'DATABASE TABLE',
           'fields' => [
               'task',
               'user',
               'status',
           ],
       ],
   ],
   ...

类似地,自定义链接可以定义如下

   ...
   'customLinks' => [ // add any custom links not handled automatically by Craft, e.g. linking to a matrix block id in a field. Format: "section.handle|categoryGroup.handle|userGroup.handle[:field.handle] -> section.handle|categoryGroup.handle|userGroup.handle"
       'userProgressTasks:task->taskEntries',
   ],
   ...

使用实体图

转到实体图控制面板页面,选择您要在图中包含的元素,或选择自定义文档组(在 entity-diagrams.php 配置文件中定义),然后点击 生成图表。图表将注入到下面的iframe中,您可以使用鼠标和滚轮缩放和移动图表。

插件为图表生成DOT文件,该文件由d3-graphviz渲染为SVG格式。您可以下载此SVG文件,用于打印文档或将其转换为PDF。

有各种选项可以更改图表的渲染方式,尽管其中一些并不特别适合复杂图表。这些选项主要是为了完整性而包括的。

支持

该插件采用MIT许可证发布,这意味着只要您不将责任归咎于我们(并遵守原始许可证),您可以对它做任何事情。它是免费的,这意味着没有任何支持包含在内,但您可能仍然会得到支持。只需在GitHub上发布一个问题,我们将看看我们能做什么。

Steve Rowling提供