oussema / hidebycountries
Hide Content Elements depends on the frontend user country
Fund package maintenance!
Buy Me A Coffee
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:typo3-cms-extension
pkg:composer/oussema/hidebycountries
Requires
- php: >= 8.1 < 8.5
- typo3/cms-backend: ^13.1
- typo3/cms-core: ^13.1
- typo3/cms-extbase: ^13.1
- typo3/cms-fluid: ^13.1
- typo3/cms-frontend: ^13.1
- typo3/cms-install: ^13.1
Requires (Dev)
- a9f/fractor-extension-installer: ^0.5.6
- a9f/typo3-fractor: ^0.5.6
- friendsofphp/php-cs-fixer: ^3.47.1
- phpstan/phpdoc-parser: ^1.12.10
- phpunit/phpunit: ^10.5.58
- ssch/typo3-rector: ^3.7
- typo3/coding-standards: ^0.5.5
- typo3/testing-framework: ^8.2.7
Replaces
- typo3-ter/hidebycountries: 2.0.0
README
A TYPO3 extension that lets you show or hide content elements based on visitor’s country.
Features
- Hide or show any content element (CE) depending on visitor’s country code.
- Uses a pluggable GeoIP service API for country detection.
- Cookie-based tracking for visitor’s country for performance.
- Caching support to reduce repeated lookups.
- Optional indicator in backend page preview indicating restricted CEs.
- Compatible with TYPO3 v13.
Requirements
- TYPO3 CMS v13
- PHP 8.1+
- MySQL / MariaDB (or supported database driver)
- Composer to install dependencies (if using Composer mode)
Installation
via composer
composer require oussema/hidebycountries
Manual Installation
- Upload the extension folder to typo3conf/ext/hidebycountries
- Activate the extension via the Extension Manager
- Configure via Admin Tools → Settings → Extension Configuration → hidebycountries
Extension Configuration
In the Extension Configuration you will find the following settings:
| Options | Description | Default Values |
|---|---|---|
| developmentMode | Use fixed IP for testing instead of actual client IP | 1 |
| publicIpAddressForTesting | IP address used when development mode is active (its recomand to overwrite this) | 234.162.28.227 |
| classNameSpace | Fully qualified class-name of the GeoIP service implementation | \Oussema\HideByCountries\Utility\Apis\AetherEpiasGeoLocationService |
| showBackendRestrictionIndicator | Show a marker in backend preview for content elements with restrictions | 1 |
How It Works
- A PSR-15 middleware intercepts frontend requests, detects visitor country (by IP or cookie)
- The content element filter logic (configured via EventListener) checks each CE’s tx_hidebycountries field and either renders or hides the CE for the visitor’s country.
- If enabled, the backend preview displays a visual indicator for CEs that have country restrictions.
Developer Guide
Using a custom GeoIP service
1- Extend or replace the default service by implementing the GeoLocationApiInterface. Example:
<?php declare(strict_types=1); namespace Vendor\Extension\Utility\Apis; use Oussema\HideByCountries\Utility\Apis\GeoLocationApiInterface; class CustomGeoService implements GeoLocationApiInterface { public function getCountryForIp(string $ipAddress): string { // custom logic for fetching country code } }
2- In the extension configuration implement ur fully qualified class-name
Backend preview indicator event
If you’ve enabled the showBackendRestrictionIndicator option, the event listener will hook into the backend module preview and add a visual marker for restricted content elements.
Contributing
Contributions are very welcome! Please fork the repository and issue a pull request. Make sure to follow the coding standards and add tests for new features.
Testing
Unit and functional tests are located under /Tests. Make sure to have a valid testing database and correct environment variables configured.