PHP code example of hauerheinrich / hh-ext-faqs

1. Go to this page and download the library: Download hauerheinrich/hh-ext-faqs library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hauerheinrich / hh-ext-faqs example snippets


'constraints' => [
    'depends' => [
        'hh_ext_faqs' => '1.0.0-0.0.0',
    ],
],



declare(strict_types=1);

use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;

defined('TYPO3') or die();

ExtensionManagementUtility::addTCAcolumns('tt_content', [
    'tx_yourext_bg_image' => [
        'exclude' => true,
        'label' => 'LLL:EXT:your_ext/Resources/Private/Language/locallang_db.xlf:tt_content.tx_yourext_bg_image',
        'config' => [
            'type' => 'file',
            'allowed' => 'common-image-types',
            'maxitems' => 1,
        ],
    ],
]);

// Position the field inside the search plugin form:
ExtensionManagementUtility::addToAllTCAtypes(
    'tt_content',
    'tx_yourext_bg_image',
    'hhextfaqs_search',
    'after:tx_hhextfaqs_auto_expand'
);



declare(strict_types=1);

namespace YourVendor\YourExt\EventListener;

use HauerHeinrich\HhExtFaqs\Event\ModifySearchVariablesEvent;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Resource\FileCollector;

#[AsEventListener(identifier: 'your-ext/faq-search-bg-image')]
final class AddBackgroundImageToSearch
{
    public function __invoke(ModifySearchVariablesEvent $event): void
    {
        $fileCollector = GeneralUtility::makeInstance(FileCollector::class);
        $fileCollector->addFilesFromRelation(
            'tt_content',
            'tx_yourext_bg_image',
            $event->getContentElementData()
        );

        $event->addVariable('bgImage', $fileCollector->getFiles()[0] ?? null);
    }
}