【发布时间】:2021-07-10 01:57:52
【问题描述】:
我有一个使用 Drupal 8 的站点。我创建了一个自定义模块。这是它的代码:
https://github.com/S1BIOSE/generator_website
generator-website-page.html.twig:
<div class="card mb-5 overflow-hidden shadow rounded bg-white">
<div class="card-body">
<form>
<legend>Générateur de site web</legend>
<div class="mb-3">
<label for="TokenUrl" class="form-label">L'URL de votre site web</label>
<input type="text" class="form-control is-invalid" id="TokenUrl" required>
<div class="invalid-feedback">
Ce champ est requis.
</div>
<small id="helpUrl" class="form-text">Entrez l'URL complète de votre site web.</small>
</div>
<div class="mb-3">
<label for="TokenTitle" class="form-label">Nom de l'entreprise</label>
<input type="text" class="form-control is-invalid" id="TokenTitle" required>
<div class="invalid-feedback">
Ce champ est requis.
</div>
<small id="helpTitle" class="form-text">Entrez le nom de votre entreprise.</small>
</div>
<div class="mb-3">
<label for="TokenDescription" class="form-label">Présentation de l'entreprise</label>
<textarea class="form-control is-invalid" id="TokenDescription" rows="5" required></textarea>
<div class="invalid-feedback">
Ce champ est requis.
</div>
<small id="helpDescription" class="form-text">Entrez une description de votre entreprise.</small>
</div>
<div class="mb-3">
<label for="TokenFeed" class="form-label">Fil d'actualité</label>
<input type="text" class="form-control" id="TokenFeed">
<small id="helpFeed" class="form-text">Entrez l'url de votre Flux RSS sur la plateforme S1BIOSE.</small>
</div>
<button type="submit" class="btn btn-primary">Générer</button>
</form>
</div>
</div>
我应该在我的模块中放入什么来生成上面的3个文件并替换以 Token 开头的单词?
在这个自定义模块中,我创建了一个带有 ID 的表单(我不确定这是否是正确的方法)。例如,在 TokenTitle 字段中输入的数据必须替换 TokenTitle 出现在文件中的任何位置。
当用户提交表单时,它必须下载包含正确数据的 3 个文件(在表单中输入的那个)。如果可能,在 ZIP 存档中。
表格中提交的信息无需保存在数据库中。
manifest.json
{
"orientation":"portrait",
"short_name": "TokenTitle",
"name": "TokenTitle",
"display": "standalone",
"background_color": "#000000",
"theme_color": "#000000",
"description": "TokenDescription",
"lang": "fr",
"icons": [{
"src": "icon-144.png",
"sizes": "144x144",
"type": "image/png",
"purpose": "any maskable"
}, {
"src": "icon-192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "any maskable"
}, {
"src": "icon-512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "any maskable"
}],
"start_url": "/?source=pwa",
"scope": "/"
}
站点地图.xml
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>TokenUrl/index.html</loc>
<lastmod>TokenDate</lastmod>
</url>
</urlset>
sw.js
const staticCacheName = 'TokenTimestamp';
const filesToCache = [
'/',
'/index.html',
'/CHANGELOG.md',
'/bootstrap.min.css',
'/style.css',
'/bootstrap.bundle.min.js',
'/popover.js',
'/clipboard.min.js',
'/btn-clipboard.js',
'/pwa.js',
'/feed.js',
'/toasts.js',
'/icon-32.png',
'/icon-144.png',
'/icon-192.png',
'/icon-512.png',
'/iphone5_splash.png',
'/iphone6_splash.png',
'/iphoneplus_splash.png',
'/iphonex_splash.png',
'/iphonexr_splash.png',
'/iphonexsmax_splash.png',
'/ipad_splash.png',
'/ipadpro1_splash.png',
'/ipadpro3_splash.png',
'/ipadpro2_splash.png'
];
self.addEventListener('install', event => {
event.waitUntil(
caches.open(staticCacheName).then(cache => {
return cache.addAll(filesToCache);
})
);
});
self.addEventListener('activate', event => {
event.waitUntil(caches.keys().then(function(cacheNames) {
return Promise.all(
cacheNames.filter(function(staticCacheName) {
}).map(function(staticCacheName) {
return caches.delete(staticCacheName);
})
);
}));
});
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request).then(cachedResponse => {
if (cachedResponse) {
return cachedResponse;
}
return fetch(event.request);
})
);
});
self.addEventListener('message', event => {
if (event.data.action === 'skipWaiting') {
self.skipWaiting();
}
});
【问题讨论】:
标签: php file drupal drupal-8 drupal-modules