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 / 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 / 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 / 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 / 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' => 'my@email.org'
];
$dataMapper = $this->objectManager->get(TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper::class);
@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 / 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 / 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 / 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 / InsertExample.php
Last active February 21, 2024 13:23
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',