diff --git a/docs/extension/_YourExtension.php b/docs/extension/_YourExtension.php new file mode 100644 index 000000000..419e5127a --- /dev/null +++ b/docs/extension/_YourExtension.php @@ -0,0 +1,38 @@ +load('your-extension.php'); + $container->prependExtensionConfig('guides', [ + 'themes' => [ + 'typo3docs' => [ + 'extends' => 'bootstrap', + 'templates' => [dirname(__DIR__, 2) . '/resources/template'], + ], + ], + ]); + } +} diff --git a/docs/extension/_composer.json b/docs/extension/_composer.json new file mode 100644 index 000000000..a479b1a6a --- /dev/null +++ b/docs/extension/_composer.json @@ -0,0 +1,15 @@ +{ + "name": "t3docs/typo3-docs-theme", + "description": "A theme for use in the phpdocumentor", + "type": "library", + "license": "MIT", + "homepage": "https://docs.typo3.org", + "autoload": { + "psr-4": { + "T3Docs\\Typo3DocsTheme\\": "src/" + } + }, + "require": { + "phpdocumentor/guides-theme-bootstrap": "dev-main" + } +} \ No newline at end of file diff --git a/docs/extension/_your-extension.php b/docs/extension/_your-extension.php new file mode 100644 index 000000000..abb95ff40 --- /dev/null +++ b/docs/extension/_your-extension.php @@ -0,0 +1,15 @@ +services() + ->defaults() + ->autowire() + ->autoconfigure() + ->set(SomeDirective::class) + ->tag('phpdoc.guides.directive'); +}; diff --git a/docs/extension/index.rst b/docs/extension/index.rst index 53ebd19fd..62e086d0d 100644 --- a/docs/extension/index.rst +++ b/docs/extension/index.rst @@ -14,7 +14,8 @@ which you invoke the CLI. It should look like this:: -.. code-block:: xml +.. code-block:: xml + :caption: your_project/guides.xml @@ -30,4 +31,6 @@ Some ways to extend the guides: .. toctree:: + structure + templates text-roles diff --git a/docs/extension/structure.rst b/docs/extension/structure.rst new file mode 100644 index 000000000..c8b9a94ff --- /dev/null +++ b/docs/extension/structure.rst @@ -0,0 +1,62 @@ +.. include:: /include.rst.txt + +.. _extension_structure: + +================= +General Structure +================= + +You can extend the guides with your own Composer-based Symfony extension. + +.. _extension_composer: + +composer.json +============= + +Each Composer package must have a file `composer.json`. See an example here: + +.. literalinclude:: _composer.json + :language: json + :caption: your-extension/composer.json + :lineos: + +The PHP sources can be found in the directory `src` then as is stated in line 8 +in the `composer.json`. + +.. _extension_symfony: + +Create an extension +=================== + +For the PHP package to be an extension you need a class +extending `\Symfony\Component\DependencyInjection\Extension\Extension` by +implementing the interface +`Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface` we +can also add our ow configurations to our extension: + +.. literalinclude:: _YourExtension.php + :language: php + :caption: your-extension/DependencyInjection/YourExtension.php + :lineos: + +Lines 24 to 28 load a :ref:`Dependency Injection configuration ` +file. Lines 29 to 36 configure the directory overriding the default templates. +Read chapter :ref:`extending_templates` to learn more about this. + +.. note:: + This is a Symfony extension, not a TYPO3 extension. See also the + `Symfony documentation about Extensions `__. + +.. _extension_di_configuration: + +Dependency Injection configuration +=================================== + +.. literalinclude:: _your-extension.php + :language: php + :caption: your-extension/resources/config/your-extension.php + :lineos: + +This is the place to register custom classes such as directives, text roles, +custom compiler passes etc. You can also read about configuration files here: +https://symfony.com/doc/current/bundles/configuration.html diff --git a/docs/extension/templates.rst b/docs/extension/templates.rst new file mode 100644 index 000000000..795d2ea42 --- /dev/null +++ b/docs/extension/templates.rst @@ -0,0 +1,53 @@ +.. include:: /include.rst.txt + +.. _extending_templates: + +=================== +Extending Templates +=================== + +Register the templates overrides in your extensions +:ref:`Extension class `: + +.. literalinclude:: _YourExtension.php + :language: php + :caption: your-extension/DependencyInjection/YourExtension.php + :lineos: + :emphasize-lines: 29-35 + +It is recommended to always extend an existing template so that the base +templates twig files can be used as fallback for non-defined specific template +files. + +In order to extend the default bootstrap theme, require the according base +extension in your extension's `composer.json`: + +.. code-block:: json + :caption: your-extension/composer.json + + { + "name": "t3docs/typo3-docs-theme", + "...": "...", + "require": { + "phpdocumentor/guides-theme-bootstrap": "dev-main" + } + } + +And then set `'extends' => 'bootstrap'` (line 32 in the first code-snippet). + +To extend the base template (plain HTML) require `phpdocumentor/guides` in your +`composer.json`, and omit the key `extends`: + + +.. code-block:: php + :caption: your-extension/DependencyInjection/YourExtension.php + + $container->prependExtensionConfig('guides', [ + 'themes' => ['mytheme' => dirname(__DIR__, 3) . '/resources/template'], + ]); + +You can now copy any twig file from the extended extensions and change it with +the full power of `Twig `__. + +Have a look at the `custom theme for TYPO3 Documentation `__ +for an example on how to create a theme which also features custom directives.