Skip to content

Instantly share code, notes, and snippets.

View einpraegsam's full-sized avatar
💭
Ready to find solutions

Alexander Kellner einpraegsam

💭
Ready to find solutions
View GitHub Profile
@einpraegsam
einpraegsam / InsertExample.php
Last active November 12, 2024 07:43
TYPO3 QueryBuilder example use
<?php
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
// insert into tt_content (header, crdate, pid) VALUES ("New content", 123456789, 123);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
$queryBuilder
->insert('tt_content')
->values([
'header' => 'New content',
@einpraegsam
einpraegsam / RadialSearchRepository.php
Created July 3, 2017 10:28
Example radial search SQL statement for TYPO3 Extbase repositories
<?php
/**
* @param FilterDto $filterDto
* @return string
*/
protected function getSqlForRadialSearch(FilterDto $filterDto): string
{
$latitude = $filterDto->getLatitudeFromZip();
$longitude = $filterDto->getLongitudeFromZip();
@einpraegsam
einpraegsam / RealurlDecoding.php
Created July 11, 2017 08:54
Individual URI-path with realurl in TYPO3. In the following example we need to have paths like /lastname.firstname for a detailview on contacts. And of course we don't want to have redirects. Thinking of a configuration in realurl that uses /folder1/folder2/Action/lastname.firstname that will be extended with the classes below.
<?php
namespace In2code\Extkey\Hooks;
/**
* Class RealurlDecoding
*/
class RealurlDecoding
{
/**
@einpraegsam
einpraegsam / StringUtility.php
Created July 20, 2017 09:05
Get youtube code from any URI
<?php
namespace In2code\In2template\Migration\Utility;
/**
* Class StringUtility
*/
class StringUtility
{
/**
@einpraegsam
einpraegsam / DummyController.php
Created August 29, 2017 09:37
Use TYPO3 cache tags in a plugin
<?php
namespace In2code\Contacts\Controller;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
/**
* Class ContactController
*/
class ContactController extends ActionController
{
@einpraegsam
einpraegsam / datamappingExtbase.php
Last active November 3, 2023 16:15
Use DataMapper class in TYPO3 to convert an array into an object
public function mapProperties(): AnyModel
{
$properties = [
'uid' => 123,
'pid' => 123,
'firstname' => 'Alex',
'lastname' => 'Kellner'
'email' => '[email protected]'
];
$dataMapper = $this->objectManager->get(TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper::class);
@einpraegsam
einpraegsam / Update.sql
Created January 22, 2018 10:42
Update TYPO3 Powermail from 2.x to 5.x or a newer version
# Just copy all tables from plural to singular naming
create table tx_powermail_domain_model_form LIKE tx_powermail_domain_model_forms;
insert tx_powermail_domain_model_form select * from tx_powermail_domain_model_forms;
create table tx_powermail_domain_model_page LIKE tx_powermail_domain_model_pages;
insert tx_powermail_domain_model_page select * from tx_powermail_domain_model_pages;
create table tx_powermail_domain_model_field LIKE tx_powermail_domain_model_fields;
insert tx_powermail_domain_model_field select * from tx_powermail_domain_model_fields;
@einpraegsam
einpraegsam / ReadableDateViewHelper.php
Created July 24, 2018 14:28
ReadableDateViewHelper to show a date in TYPO3 Fluid with a readable date like: "2 Minutes ago", "4 hours ago", "2 days ago" or a date. Tipp: use a normal date viewhelper date in a title-attribute in a wrapping (e.g.) span tag to have a exact date and time while hovering the readable date.
<?php
declare(strict_types=1);
namespace In2code\Lux\ViewHelpers\Format;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* Class ReadableDateViewHelper
*
@einpraegsam
einpraegsam / PageModule.php
Created July 27, 2018 08:18
TYPO3: Adding a name and email to page settings for a person which is responsible for this page-branch is often wanted from different universities. In addition we want to show in the page module when and who did the last change on the current page. Example image: https://s.nimbusweb.me/attachment/1934043/8gzcifcqtdmhktr2q553/262407-2IdneYdKSIZ3K…
<?php
declare(strict_types=1);
namespace Unitue\Project\Hooks;
use TYPO3\CMS\Backend\Controller\PageLayoutController;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Exception\InvalidExtensionNameException;
use TYPO3\CMS\Fluid\View\StandaloneView;
use Unitue\Project\Utility\DatabaseUtility;
use Unitue\Project\Utility\ObjectUtility;
@einpraegsam
einpraegsam / GeneralUtility.php
Created February 6, 2019 12:30
Alternative GeneralUtility::xml2array() without 10MB restriction from libxml - for import and export . Quick and dirty hack, exactly like to the original one in TYPO3.
<?php
namespace TYPO3\CMS\Core\Utility;
use GuzzleHttp\Exception\RequestException;
use TYPO3\CMS\Core\Core\ApplicationContext;
use TYPO3\CMS\Core\Core\ClassLoadingInformation;
use TYPO3\CMS\Core\Crypto\Random;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Http\RequestFactory;
use TYPO3\CMS\Core\Service\OpcodeCacheService;