.. include:: /Includes.rst.txt .. _developer: ===================== Developer Information ===================== This chapter covers the technical aspects of extending and integrating with the Contexts extension. .. _developer-custom-context: Creating Custom Context Types ============================= You can create custom context types by implementing the context interface and registering your type. Step 1: Create the Context Class -------------------------------- .. code-block:: php getConfValue('myField'); $actualValue = $this->getActualValue(); return $configuredValue === $actualValue; } private function getActualValue(): string { // Your matching logic here return ''; } } Step 2: Register the Context Type --------------------------------- In your :file:`ext_localconf.php`: .. code-block:: php MyCustomContext::class, 'label' => 'LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:context.my_custom', ]; Step 3: Add TCA Configuration ----------------------------- In :file:`Configuration/TCA/Overrides/tx_contexts_contexts.php`: .. code-block:: php 'type, title, --palette--;;visibility, my_field', ]; \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns( 'tx_contexts_contexts', [ 'my_field' => [ 'label' => 'My Field', 'config' => [ 'type' => 'input', ], ], ] ); .. _developer-events: PSR-14 Events ============= .. versionadded:: 4.0.0 PSR-14 events replace legacy SC_OPTIONS hooks. The extension dispatches several PSR-14 events that you can listen to. ContextMatchEvent ----------------- Dispatched when a context is being matched. .. code-block:: php getContext(); $matches = $event->getMatches(); // Modify matching behavior if ($this->shouldOverride($context)) { $event->setMatches(true); } } } .. _developer-api: Context API =========== Checking Contexts Programmatically ---------------------------------- .. code-block:: php match()) { // Handle matched context } Getting Context Settings ------------------------ .. code-block:: php isEnabled()) { // Record is visible in current context } .. _developer-testing: Testing ======= Running Tests ------------- The extension uses PHPUnit with the TYPO3 Testing Framework. .. code-block:: bash # Run all tests ./Build/Scripts/runTests.sh all # Run unit tests only ./Build/Scripts/runTests.sh unit # Run with specific PHP version ./Build/Scripts/runTests.sh -p 8.3 unit # Run with coverage ./Build/Scripts/runTests.sh -c unit Writing Tests for Custom Contexts --------------------------------- .. code-block:: php match()); } } .. _developer-debugging: Debugging ========= Enable debug mode to see context matching details: .. code-block:: php $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['contexts']['debug'] = true; This outputs context matching information to the TYPO3 debug console.