Themes


使用此端点来操作并获取 Mautic 主题的详细信息。

使用 Mautic API 库

您可以使用以下 :xref:`Mautic API 库 与此 API 进行交互,或者使用本文档中描述的各种 HTTP 端点。

<?php
use Mautic\MauticApi;
use Mautic\Auth\ApiAuth;

// ...
$initAuth  = new ApiAuth();
$auth      = $initAuth->newAuth($settings);
$apiUrl    = "https://example.com";
$api       = new MauticApi();
$themesApi = $api->newApi("themes", $auth, $apiUrl);

获取主题

成功时,以 application/zip 头的 ZIP 文件返回主题,失败时,返回包含错误消息的 JSON 响应。 PHP API 库将 ZIP 文件保存到系统的临时目录,并检索路径。

<?php

//...
$response = $themesApi->get($themeName);

HTTP 请求

GET /themes/THEME_NAME

响应

  • 当请求成功检索到主题 ZIP 文件时,返回 200 OK。

{
    "file": "/absolute/path/to/the/system/temp/dir/with/the/theme/zip/file"
}

设置临时文件路径

更改 PHP API 库创建 ZIP 文件的默认临时目录。 如果该目录不存在,则会创建它。

<?php

//...
$themesApi->setTemporaryFilePath("/absolute/path/to/a/different/temp/dir");
$response = $themesApi->get($themeName);

响应

  • 当请求成功更改或创建默认临时目录时,返回 200 OK。

{
    "file": "/absolute/path/to/a/different/temp/dir/zipfile"
}

列出主题

列出所有已安装的主题及其从 config.json 文件中提取的详细信息。

<?php

//...
$response = $themesApi->getList();

HTTP 请求

GET /themes

响应

  • 当请求成功检索到主题列表时,返回 200 OK。

{
    "themes": {
        "blank": {
            "name": "Blank",
            "key": "blank",
            "config": {
                "name": "Blank",
                "author": "Mautic team",
                "authorUrl": "https://mautic.org",
                "features": [
                    "page",
                    "email",
                    "form"
                ]
            }
        }
    }
}

属性

名称

类型

描述

themes

array

已安装主题及其配置的列表

主题对象属性

Name

Type

Description

name

string

主题的显示名称

key

string

主题的目录名和唯一标识符

config

object

从 config.json 文件加载的主题配置

Config object properties

Name

Type

Description

name

string

主题名称

author

string

主题作者

authorUrl

string

作者的网站 URL

features

array

支持的功能列表,例如 page、email 或 form

builder

array

可选的兼容构建器列表,例如 legacy 或 grapeJs

Create Theme

从提供的 ZIP 文件创建新的主题或更新现有主题。 主题名称来自 ZIP 文件的文件名。

<?php

//...
$data = array(
    'file' => dirname(__DIR__) . '/' . 'mytheme.zip'
);

$response = $themesApi->create($data);

Mautic 通过标准的 POST 文件数组发送文件,就像浏览器在上传时发送文件一样。

HTTP request

POST /themes/new

POST parameters

Name

Type

Description

file

file

包含主题的 ZIP 文件 - 必需

Response

  • 当请求成功创建主题时,返回 200 OK。

{
    "success": true
}

Error responses

如果出现以下情况,API 将返回错误消息:

  • 请求中未包含上传的文件

  • 上传的文件没有 .zip 扩展名

  • ZIP 文件缺少必需的文件 - config.json 和 html/message.html.twig

  • ZIP 文件包含不允许的文件扩展名

Delete Theme

删除一个主题。 系统会阻止删除默认主题。

<?php

//...
$response = $themesApi->delete($themeName);

HTTP request

DELETE /themes/THEME_NAME/delete

Response

  • 当请求成功删除主题时,返回 200 OK。

{
    "success": true
}

Note

Mautic 阻止永久删除与应用程序捆绑的默认主题。 尝试删除默认主题会将其隐藏。 使用 Mautic UI 中的主题可见性切换来恢复隐藏的默认主题。