如何克隆TYPO3扩展?基于现有扩展构建自定义扩展的操作指引
Hey there! Cloning a TYPO3 extension to build your own custom version is a super common workflow, and I’ll walk you through every step you need to follow, plus all the critical files and parameters you must modify to avoid conflicts and make it your own.
第一步:准备与克隆原扩展
- First, grab the source code of the extension you want to clone. You can either:
- Use
git cloneto pull the repo directly into your TYPO3 project’stypo3conf/ext/directory - Download a ZIP of the extension and extract it into
typo3conf/ext/
- Use
- Immediately rename the extension directory to your custom name (follow TYPO3 rules: lowercase letters only, underscores allowed, no special characters). For example, if cloning
news, rename it tomy_custom_news.
第二步:核心文件与参数修改
These are the non-negotiable changes you need to make to ensure your extension is recognized as a separate, unique extension by TYPO3.
1. Extension Configuration File (ext_emconf.php)
This is TYPO3’s primary way to identify your extension—don’t skip any of these:
- Update
$EM_CONF[$_EXTKEY]['title']: Set your custom extension name (e.g.,My Custom News Plugin) - Modify
$EM_CONF[$_EXTKEY]['description']: Write a clear description explaining this is your customized fork - Update
$EM_CONF[$_EXTKEY]['author'],$EM_CONF[$_EXTKEY]['author_email'], and$EM_CONF[$_EXTKEY]['author_company']with your own details - Reset
$EM_CONF[$_EXTKEY]['version']to1.0.0(or your preferred starting version) to avoid version conflicts with the original extension - Verify
$EM_CONF[$_EXTKEY]['constraints']['depends']: Keep the TYPO3 version and other dependency requirements aligned with your project needs (you can adjust these later if needed)
2. Composer Configuration (composer.json)
If the original extension uses Composer (most modern ones do), update these fields:
name: Change to your own vendor/extension-key format (e.g.,yourcompany/my-custom-news)description: Match what you wrote inext_emconf.phpauthors: Replace with your team/author informationextra.typo3/cms.extension-key: Set this to your new extension directory name (e.g.,my_custom_news)- Remove any dependencies on the original extension (since you’re now using your own fork)
3. Namespace Replacements (All PHP & Template Files)
TYPO3 uses PSR-4 namespaces, so you’ll need to do a global replace across all files:
- Find the original extension’s namespace (e.g.,
Vendor\News) and replace it with your custom namespace (e.g.,YourCompany\MyCustomNews) - Don’t forget:
- Fluid templates with custom view helpers (update the namespace declarations in
.htmlfiles) - Configuration files in
Configuration/TCA/orConfiguration/Services.yamlthat reference the original namespace
- Fluid templates with custom view helpers (update the namespace declarations in
4. Database-Related Files
If the extension uses custom database tables:
- Rename tables in
ext_tables.sql: Change prefixes liketx_news_domain_model_*totx_mycustomnews_domain_model_* - Rename TCA configuration files in
Configuration/TCA/: For example,tx_news_domain_model_news.phpbecomestx_mycustomnews_domain_model_news.php, and update all table/namespace references inside - Update table registrations in
ext_tables.phpto match your new table names
5. Plugin/Backend Module Registrations
- Frontend Plugins: In
Configuration/TCA/Overrides/sys_template.php, replace all references to the original extension key (e.g.,tx_news) with your new key. Also update the plugin name and description. - Backend Modules: In
Configuration/Backend/Modules.php, adjust the module identifier, namespace, and labels to match your extension. - ext_localconf.php: Update the
configurePlugin()call from\TYPO3\CMS\Extbase\Utility\ExtensionUtility:\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin( 'MyCustomNews', // Your new extension key 'List', // Plugin name [ \YourCompany\MyCustomNews\Controller\NewsController::class => 'list, show' ], // non-cacheable actions [ \YourCompany\MyCustomNews\Controller\NewsController::class => '' ] );
6. Language Files
- Update all language file references in templates and configuration: Replace
LLL:EXT:news/Resources/Private/Language/...withLLL:EXT:my_custom_news/Resources/Private/Language/... - You can also modify the language strings themselves in
Resources/Private/Language/locallang.xlfto fit your custom needs.
第三步: Test & Validate
- Go to the TYPO3 backend’s Extension Manager, find your new extension, and install it
- Test all core functionality: frontend plugin rendering, backend CRUD operations, database interactions, etc.
- If you run into errors, double-check for missed namespace replacements, table name references, or extension key typos—these are the most common pitfalls!
内容的提问来源于stack exchange,提问作者Karine Lévis

