• Stars
    star
    154
  • Rank 241,344 (Top 5 %)
  • Language
    PHP
  • License
    GNU General Publi...
  • Created over 4 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A TYPO3 Extension for creating custom nested content elements

CI

EXT:container - A TYPO3 Extension for creating nested content elements

Features

  • Simple amazing containers (grids) as custom TYPO3 Content Elements
  • No default containers, everything will be built the way its needed for a project
  • Supports multilanguage (connected or free mode (mixed mode not supported))
  • Supports workspaces
  • Supports colPos-restrictions if EXT:content_defender >= 3.1.0 is installed
  • Frontend Rendering via DataProcessor and Fluid templates

Why did we create another "Grid" extension?

At b13 we've been long supporters and fans of gridelements, which we are thankful for and we used it in the past with great pleasure.

However, we had our pain points in the past with all solutions we've evaluted and worked with. These are our reasons:

  • We wanted an extension that works with multiple versions of TYPO3 Core with the same extension, to support our company's TYPO3 upgrade strategy.
  • We wanted to overcome issues when dealing with colPos field and dislike any fixed value which isn't fully compatible with TYPO3 Core.
  • We wanted an extension that is fully tested with multilingual and workspaces functionality.
  • We wanted an extension that only does one thing: EXT:container ONLY adds tools to create and render container elements, and nothing else. No FlexForms, no permission handling or custom rendering.
  • We wanted an extension where every grid has its own Content Type (CType) making it as close to TYPO3 Core functionality as possible.
  • We wanted an extension where the configuration of a grid container element is located at one single place to make creation of custom containers easy.
  • We wanted an extension that has a progressive development workflow: We were working with new projects in TYPO3 v10 sprint releases and needed custom container elements and did not want to wait until TYPO3 v10 LTS.

Installation

Install this extension via composer req b13/container or download it from the TYPO3 Extension Repository and activate the extension in the Extension Manager of your TYPO3 installation.

Once installed, add a custom content element to your sitepackage or theme extension (see "Adding your own container element").

Adding your own container element

  1. Register your custom container in your sitepackage or theme extension in Configuration/TCA/Overrides/tt_content.php as new Content Type
  2. Add TypoScript and your Fluid Template for frontend rendering
  3. Add an icon in Resources/Public/Icons/<CType>.svg

See EXT:container_example for a simple example of a custom container.

Registration of Container Elements

This is an example to create a 2 column container. The code snippet goes into a file in your sitepackage or theme extension in the folder Configuration/TCA/Overrides/. The file can have any name but it is good practice to name it according to the database table it relates to. In this case this would be tt_content.php.

\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\B13\Container\Tca\Registry::class)->configureContainer(
    (
        new \B13\Container\Tca\ContainerConfiguration(
            'b13-2cols-with-header-container', // CType
            '2 Column Container With Header', // label
            'Some Description of the Container', // description
            [
                [
                    ['name' => 'header', 'colPos' => 200, 'colspan' => 2, 'allowed' => ['CType' => 'header, textmedia']]
                ],
                [
                    ['name' => 'left side', 'colPos' => 201],
                    ['name' => 'right side', 'colPos' => 202]
                ]
            ] // grid configuration
        )
    )
    // set an optional icon configuration
    ->setIcon('EXT:container_example/Resources/Public/Icons/b13-2cols-with-header-container.svg')
);

Methods of the ContainerConfiguration Object

Method name Description Parameters Default
setIcon icon file, or existing icon identifier string $icon 'EXT:container/Resources/Public/Icons/Extension.svg'
setBackendTemplate Template for backend view string $backendTemplate 'EXT:container/Resources/Private/Templates/Container.html'
setGridTemplate Template for grid string $gridTemplate 'EXT:container/Resources/Private/Templates/Container.html'
setGridPartialPaths / addGridPartialPath Partial root paths for grid, only affects the Fluid-based page module array $gridPartialPaths / string $gridPartialPath ['EXT:backend/Resources/Private/Partials/', 'EXT:container/Resources/Private/Partials/']
setGridLayoutPaths Layout root paths for grid, only affects the Fluid-based page module array $gridLayoutPaths []
setSaveAndCloseInNewContentElementWizard saveAndClose for new content element wizard (v10 only) bool $saveAndCloseInNewContentElementWizard true
setRegisterInNewContentElementWizard register in new content element wizard bool $registerInNewContentElementWizard true
setGroup Custom Group (used as optgroup for CType select (v10 only), and as tab in New Content Element Wizard). If empty "container" is used as tab and no optgroup in CType is used. string $group 'container'
setDefaultValues Default values for the newContentElement.wizardItems array $defaultValues []

Notes:

  • If EXT:content_defender >= 3.1.0 is installed you can use allowed, disallowed and maxitems in the column configuration
  • The container registry does multiple things:
    • Adds CType to TCA select items
    • Registers your icon
    • Adds PageTSconfig for newContentElement.wizardItems
    • Sets showitem for this CType (sys_language_uid,CType,tx_container_parent,colPos,hidden)
    • Saves the configuration in TCA in $GLOBALS['TCA']['tt_content']['containerConfiguration'][<CType>] for further usage
  • We provide some default icons you can use, see Resources/Public/Icons
    • container-1col
    • container-2col
    • container-2col-left
    • container-2col-right
    • container-3col
    • container-4col

TypoScript

The TypoScript is necessary to define the rendering of the container in the frontend. Normally you will place it in your sitepackage or theme extension near the place where you define other stuff regarding your content elements. templateRootPaths must be adapted to reflect the path of the html files in your sitepackage or theme extension.

// default/general configuration (will add 'children_<colPos>' variable to processedData for each colPos in container
tt_content.b13-2cols-with-header-container < lib.contentElement
tt_content.b13-2cols-with-header-container {
    templateName = 2ColsWithHeader
    templateRootPaths {
        10 = EXT:container_example/Resources/Private/Templates
    }
    dataProcessing {
        100 = B13\Container\DataProcessing\ContainerProcessor
    }
}

// if needed you can use ContainerProcessor with explicitly set colPos/variable values
tt_content.b13-2cols-with-header-container < lib.contentElement
tt_content.b13-2cols-with-header-container {
    templateName = 2ColsWithHeader
    templateRootPaths {
        10 = EXT:container_example/Resources/Private/Templates
    }
    dataProcessing {
        200 = B13\Container\DataProcessing\ContainerProcessor
        200 {
            colPos = 200
            as = children_200
        }
        201 = B13\Container\DataProcessing\ContainerProcessor
        201 {
            colPos = 201
            as = children_201
        }
    }
}

Options for DataProcessing

Option Description Default Parameter
contentId id of container to to process current uid of content element $cObj->data['uid'] ?ìnt
colPos colPos of children to to process empty, all children are processed (as children_<colPos>) ?int
as variable to use for proceesedData (only if colPos is set) children ?string
skipRenderingChildContent do not call ContentObjectRenderer->render() for children, (renderedContent in child will not exist) empty ?int

Template

The html template file goes in the folder that you have defined in your TypoScript above (see templateRootPaths). It's important to name it exacly as defined in templateName in TypoScript, in this case 2ColsWithHeader.html. The file name is case-sensitive!

<f:for each="{children_200}" as="record">
    {record.header} <br>
    <f:format.raw>
        {record.renderedContent}
    </f:format.raw>
</f:for>

<f:for each="{children_201}" as="record">
    {record.header} <br>
    <f:format.raw>
        {record.renderedContent}
    </f:format.raw>
</f:for>

With explicit colPos defined use {children_200]201>} as set in the example above

Concepts

  • Complete registration is done with one PHP call to TCA Registry
  • A container in the TYPO3 backend Page module is rendered like a page itself (see View/ContainerLayoutView)
  • For backend clipboard and drag & drop <tx_container_parent>_<colPos> used in the data-colpos attribute in the wrapping CE-div Element (instead of just the colPos as in the PageLayoutView)
  • The <tx_container_parent>_<colPos> parameter is resolved to tx_container_parent and colPos value in DataHandler hooks
  • When translating a container, all child elements get also translated (the child elements are not explicit listed during the translation dialog)
  • Copying or moving children of a container copies or moves translations as well
  • Custom definitions make use of custom colPos values so site owners build their own elements, no fixed colPos given, so no interference with existing solutions
  • Each container type is just a definition for its own CType

TODOs / Proofments

  • Integrity proofment
  • List module actions

Extension Tests and Coding Guidelines

You can run our test suite for this extension yourself:

  • run composer install
  • run Build/Scripts/runTests.sh -s unit
  • run Build/Scripts/runTests.sh -s functional
  • run Build/Scripts/runTests.sh -s acceptance

See Tests/README.md how to run the tests local (like github-actions runs the tests).

To assure coding guidelines are fullfilled:

  • run .Build/bin/phpstan analyse -c Build/phpstan10.neon
  • run .Build/bin/php-cs-fixer fix --config=Build/php-cs-fixer.php --dry-run --stop-on-violation --using-cache=no

Credits

This extension was created by Achim Fritz in 2020 for b13 GmbH, Stuttgart.

Find examples, use cases and best practices for this extension in our container blog series on b13.com.

Find more TYPO3 extensions we have developed that help us deliver value in client projects. As part of the way we work, we focus on testing and best practices to ensure long-term performance, reliability, and results in all our code.

More Repositories

1

menus

TYPO3 Extension for creating fast menus in a fast fashion
PHP
54
star
2

make

Kickstarter CLI tool for various TYPO3 functionalities
PHP
41
star
3

host_variants

TYPO3 extension to extend the base variants condition in the site configuration with the current host.
PHP
31
star
4

bolt

Easier integrations for TYPO3 sites
PHP
26
star
5

masi

Extend TYPO3's URL Handling
PHP
23
star
6

t3ext-dam_falmigration

TYPO3 Extension: Migrate DAM Records and Relations to TYPO3 6.x File Abstraction Layer (FAL)
PHP
22
star
7

http2

TYPO3 Extension for supporting HTTP/2 Server Push
PHP
20
star
8

picture

A TYPO3 ViewHelper for flexible image renderings
PHP
18
star
9

slimphp-bridge

SlimPHP Integration in TYPO3 Frontend for rapid API development
PHP
16
star
10

link2language

Allows to set links to a specific language of a page in FormEngine and the RTE link selector
PHP
16
star
11

permission-sets

TYPO3 Extension to configure user permissions based on deployable files
PHP
16
star
12

justincase

TYPO3 Extension - No matter what case your URL is, we'll hit it.
PHP
16
star
13

geocoding

TYPO3 Extension: Geocoding: Provides services for google maps GeoCoding API
PHP
15
star
14

distributed-locks

Adds a Redis Locking Strategy for TYPO3 frontend page generation, useful on distributed systems with NFS.
PHP
12
star
15

t3ext-environment

TYPO3 Extension: allow environment-dependent settings
PHP
12
star
16

unlocalizedcrop

TYPO3 Extension: Disables cropping for sys_file_reference translations and keeps them in sync
PHP
11
star
17

typo3-config

Helper Package for maintaining TYPO3 Configuration in projects
PHP
10
star
18

container-example

Example for creating custom containers with EXT:container
PHP
9
star
19

proxycachemanager

TYPO3 Extension: Generic Proxy Cache Manager - Can be configured for nginx or Varnish as Reverse Proxy
PHP
9
star
20

listelements

BETA: listelements
PHP
8
star
21

trusted-url-params

TYPO3 Extension to ensure that only safe queryParams from TYPO3s Routing are added to generated links
PHP
8
star
22

assetcollector

Add CSS / SVG / JS to Content templates, and load them only once
PHP
8
star
23

t3ext-seo_basics

TYPO3 Extension: SEO Basics
PHP
7
star
24

uniquealiasmapper

Unique Alias Mapper for URL Routing in TYPO3 v9+
PHP
7
star
25

xray

TYPO3 Extension doing some sanity checks with data integrity
PHP
7
star
26

backendpreviews

PHP
7
star
27

content-sync

TYPO3 Extension to sync content between 2 TYPO3 instances
PHP
6
star
28

t3ext-format

TYPO3 Extension: Helper extension to allow easy use of putting data in different formats (CSV, Excel, PDF etc)
PHP
6
star
29

doktypemapper

PHP
6
star
30

sessionpassword

TYPO3 Extension: Use a simple password form to add usergroups and show pages/content only for the current session
PHP
5
star
31

online-media-updater

A TYPO3 Extension for updating youtube/vimeo preview images in the backend
HTML
5
star
32

tag

Tags Input for TYPO3 Core
JavaScript
5
star
33

authorized-preview

TYPO3 Extension for previewing disabled languages without a backend login
PHP
5
star
34

codeblock

Code Block is a TYPO3 extension. It adds a content type to display source code processed using highlight.php to render code snippets with syntax highlighting.
PHP
4
star
35

slugr

Bulk Re-generate URLs for pages in TYPO3 v9+
PHP
4
star
36

cta

Fields, configuration and a content element type for all kinds of CTAs for TYPO3
PHP
3
star
37

snipper

Keep external links secure
PHP
3
star
38

newspage

PHP
3
star
39

pagetsconfig

Allows to modify TCA values with pagetsconfig in TYPO3 v10+
PHP
3
star
40

otf

TYPO3 Extension for on-the-fly evaluation hints in FormEngine
PHP
3
star
41

cloudflare-cdn

Cloudflare CDN functionality for TYPO3
PHP
3
star
42

t3ext-memolist

TYPO3 Extension: Memolist - A Helper Class for Session Saving
PHP
2
star
43

sitemap-inspector

TYPO3 Extension to compare and check for XML sitemaps
PHP
2
star
44

distributed-flysystem

Syncs files between frontend nodes in a multi-head environment based on PHP League / Flysystem
PHP
2
star
45

pdfreactor

PHP wrapper library for PDFreactor
PHP
2
star
46

b_scrollTo

JavaScript
2
star
47

ddev-rabbitmq

Adds a rabbitmq service to ddev
Shell
2
star
48

hydra

PHP
2
star
49

twoclickmedia

PHP
2
star
50

typo3-composerize

Prepare TYPO3 extensions for composer
PHP
2
star
51

magnets

TYPO3 Extension as API dealing with GeoIP locations
PHP
2
star
52

form-custom-templates

Extend email finishers in EXT:form with a selectable template to let the editor choose which email template to use.
PHP
2
star
53

evergreen-errors

A custom TYPO3 Error Handler which never communicates a 50x HTTP Error
PHP
1
star
54

graceful-cache

TYPO3 cache backends which do not always have to be enabled
PHP
1
star
55

gonzo

Take control of your Page URLs in TYPO3 v9.
PHP
1
star
56

b_dropdown

Javascrip dropdown menu
JavaScript
1
star
57

js-form

Module to submit a form via ajax and do a basic validation
JavaScript
1
star
58

t3ext-country2language

TYPO3 Extension: Country-To-Language GEO Mapping
PHP
1
star
59

collapse

Collapse or expand Content Element in TYPO3's Page Module
PHP
1
star
60

js-sliderWithProgressbar

JavaScript
1
star
61

t3ext-adobedps

TYPO3 Extension: Authorize Adobe DPS Applications for Frontend Users
PHP
1
star
62

t3ext-feusertools

TYPO3 Extension: Frontend User Tools and Helpers
PHP
1
star
63

simplenews

Example extension for TYPO3 v9+ "slug" field in custom records and Route Enhancers
PHP
1
star
64

breakpointlistener

JavaScript
1
star
65

t3ext-sharing_basics

TYPO3 Extension: Adds Facebook Open Graph metatags to pages to be edited in the backend, including title, description, thumbnails.
PHP
1
star