:orphan:
:navigation-title: Create patch - Intention
.. include:: /Includes.rst.txt
.. index::
single: Patch
.. _quickstart-intent:
Quick Start: Create a patch - Intention
=======================================
For this part of the guide to be effective, we establish our intent.
This could be many things:
* **Fix a bug** in one of the TYPO3 Core Extensions
* Introduce a **new feature**
* Fix mistakes or add content in the **Documentation** of any of the Core Extensions
* Enhance **tests** for certain functionality
* Raise or add **dependencies** within TYPO3
* Adjust the **TYPO3 Build** or **Testing Pipeline**
* Make changes to the **TypeScript/SCSS build** of TYPO3
For the sake of clarity, let's pick a simple example:
I found a bug in the TYPO3 record editing backend (FormEngine) for
the `JsonElement` input (TCA type `json`). With a new HTML5 spec,
all Json presentations need a new attribute called `input-format="json"`
to be set.
For this you have already discovered the TYPO3 Core file
:file:`typo3/sysext/backend/Classes/Form/Element/JsonElement.php`,
which has this code at `line 188`:
.. code:: php
$editorHtml = '
';
} else {
$attributes['class'] = implode(' ', array_merge(explode(' ', $attributes['class']), ['formengine-textarea', 't3js-enable-tab']));
$resultArray['javaScriptModules'][] = JavaScriptModuleInstruction::create('@typo3/backend/form-engine/element/json-element.js');
$editorHtml = '
';
}
.. hint::
Before making any changes and creating a patch, it's important to ensure a
clean state in the repository, which means that a `git status` should tell
you `nothing to commit, working tree clean`. Also see :ref:`reset-to-a-clean-state`
for details.
.. code:: php
:caption: **We change this code into:**
:emphasize-lines: 3,12
$editorHtml = '
';
} else {
$attributes['class'] = implode(' ', array_merge(explode(' ', $attributes['class']), ['formengine-textarea', 't3js-enable-tab']));
$resultArray['javaScriptModules'][] = JavaScriptModuleInstruction::create('@typo3/backend/form-engine/element/json-element.js');
$editorHtml = '
';
Note that we added :html:`input-format="json"` in the marked lines.
After we patched the file, we can manually check it has the wanted effect.
To contribute this patch and to meet the TYPO3 quality criteria, this change
needs to be covered by a Unit or Functional Test (see
:ref:`Testing ` and :ref:`Using runTests.sh `).
Since testing is vital to TYPO3, we add a test for our code change above.
By browsing through the existing TYPO3 testing directories, we often find
tests that can be adapted for the change we make. In this case, there's
:file:`typo3/sysext/backend/Tests/Unit/Form/Element/JsonElementTest.php`
which already performs a test:
.. code:: php
self::assertStringContainsString('`,
this is beyond the scope of this chapter.
This concludes stating an intent for contributing a patch and you have a modified
file plus a test to contribute. Continue on :ref:`quickstart-patch`!