Skip to content

Instantly share code, notes, and snippets.

@ogrosko
ogrosko / gist:581202ad1ec6cb86099ddcc0933bdb92
Created July 10, 2020 07:21
Redirect to 404 from extbase action
# https://stackoverflow.com/questions/55007086/how-to-return-a-proper-404-error-from-extbase-with-a-error-handling-configuratio
$response = GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
$GLOBALS['TYPO3_REQUEST'],
'Your error message',
['code' => PageAccessFailureReasons::PAGE_NOT_FOUND]
);
throw new ImmediateResponseException($response);
@ogrosko
ogrosko / sort.php
Last active February 10, 2020 11:01
Typo3 page tree flat sorting
/**
* @return array
*/
public function getSortingMatrix(): array
{
$matrix = [];
$rootLine = GeneralUtility::makeInstance(RootlineUtility::class, $this->getUid())->get();
foreach ($rootLine as $level => $item) {
$matrix[$level] = $item['sorting'];
@ogrosko
ogrosko / gist:15f97e0121d275039f48c9879bb2f07f
Created September 5, 2019 08:21
Connect to solr server from localhost
ssh -N -L 8983:127.0.0.1:8983 [email protected]
@ogrosko
ogrosko / gist:3aca9c12db0d4c4e988bf7f72bb6636f
Created August 22, 2019 14:09
Parse Extbase query and view as raw mysql query
$queryParser = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser::class);
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($queryParser->convertQueryToDoctrineQueryBuilder($query)->getSQL());
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($queryParser->convertQueryToDoctrineQueryBuilder($query)->getParameters());
@ogrosko
ogrosko / .htaccess
Last active October 14, 2019 09:45
Password protected host
#Protected hosts by password
<If "%{HTTP_HOST} in { 'hotst.name.com' }">
AuthType Basic
AuthName "Password Protected"
AuthUserFile /var/www/html/.htpasswd
Require valid-user
</If>
#Protected hosts by password and env variable
<If "!(%{ENV:TYPO3_CONTEXT} in {'Development/DDev', 'Testing'})">
@ogrosko
ogrosko / Model.php
Created September 4, 2018 08:29
Typo3 localization FAL workarround fix
/**
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference>
*/
public function getMedia(): \TYPO3\CMS\Extbase\Persistence\ObjectStorage
{
//Never ending typo3 BUG with typo3 FAL localizations
if ($GLOBALS['TSFE']->sys_language_uid > 0) {
$query = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file_reference');
$fileReferences = $query
->select('uid')
@ogrosko
ogrosko / FormController.php
Created July 25, 2018 14:57
Typo3 extbase conditional validation
/**
* Initialize action for submit action
*/
public function initializeSubmitAction()
{
if ($this->arguments->hasArgument('order') and $this->request->getArgument('order')['shipping']) {
$validatorResolver = $this->objectManager->get(ValidatorResolver::class);
$dynamicValidator = $validatorResolver->createValidator(GenericObjectValidator::class);
foreach ($this->request->getArgument('order')['shipping'] as $shippingMethod) {
switch ($shippingMethod) {
@ogrosko
ogrosko / FlexForm.xml
Created February 12, 2018 10:58
Flexform FAL image with image palette
<settings.advertising>
<TCEforms>
<label>LLL:EXT:dw_page_types/Resources/Private/Language/locallang_db.xlf:flexform.plugin.event.advertising</label>
<config>
<type>inline</type>
<maxitems>1</maxitems>
<minitems>0</minitems>
<foreign_table>sys_file_reference</foreign_table>
<foreign_field>uid_foreign</foreign_field>
<foreign_table_field>tablenames</foreign_table_field>
@ogrosko
ogrosko / ContentProtector.php
Created January 3, 2018 15:05
Flux Drag&Drop accept allowedContentTypes
<?php
namespace BinaryBay\BbBoilerplate\Utility;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Extbase\Service\FlexFormService;
use TYPO3\CMS\Extbase\Object\ObjectManager;
@ogrosko
ogrosko / Element.html
Created November 30, 2017 09:25
Flux custom fal fields
<flux:field.inline.fal name="settings.users"
maxItems="8"
collapseAll="true"
foreignTypes="{
2: {
showitem: '
--palette--;;your_palette_name,
--palette--;;filePalette
'
}