Configuration
Configuration
You find more information about the configuration in the vehicle manager section Configuration.
Synchronization
You find more information about the synchronization in the vehicle manager section Synchronization.
Linking the vehicle number
To make vehicles reachable via their vehicle number (domain.com/VEHICLENUMBER), first install the extension terminal42/contao-url-rewrite.
In the folder app/src/EventListener, create a PHP file named HookListener.php.
<?php
namespace App\EventListener;
use Contao\CoreBundle\ServiceAnnotation\Hook;
use Contao\Database;
use Contao\StringUtil;
class HookListener {
/**
* @Hook("vehicleFetchItems")
*/
public function vehicleFetchItems($vehicles): void
{
$vehicles = json_decode(json_encode($vehicles), true);
$database = Database::getInstance();
$database->execute("TRUNCATE tl_url_rewrite");
foreach($vehicles as $item) {
$alias = '/details/'.StringUtil::generateAlias($item['hersteller'].' '.$item['modell'].' '.$item['baureihe'].' '.$item['eigene_id']).'.html';
$alias = str_replace(['ä','ü','ö'], ['a','u','o'], $alias);
$set = [
'name' => $item['eigene_id'],
'tstamp' => time(),
'type' => 'basic',
'requestPath' => '/'.$item['eigene_id'],
'responseUri' => $alias,
'responseCode' => 301
];
$database->prepare("INSERT INTO tl_url_rewrite %s")->set($set)->execute();
}
}
}The line $database->execute("TRUNCATE tl_url_rewrite"); empties the table. If you have other rewrite rules,
you need to adjust this part.
You may also need to adjust the alias in $alias = '/details/' if the vehicle detail page has a different URL.
Then create config.php in the folder app/contao/config and clear the cache in the Contao Manager.
<?php
use App\EventListener\HookListener;
$GLOBALS['TL_HOOKS']['vehicleFetchItems'][] = [HookListener::class, 'vehicleFetchItems'];With the next import, the table should be filled. You find it in the back end under System > URL rewrites.