Download the PHP package digitalwerk/content_element_registry without Composer
On this page you can find all versions of the php package digitalwerk/content_element_registry. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download digitalwerk/content_element_registry
More information about digitalwerk/content_element_registry
Files in digitalwerk/content_element_registry
Package content_element_registry
Short Description For this package there is no description available.
License
Informations about the package content_element_registry
⚠️ Project migrated ⚠️
Project was migrated to another project.
Please continue in this project
Content element registry
Typo3 extension simplify process of creating new content elements (CE) in Typo3 way
Install
Install extension via composer composer req digitalwerk/content-element-registry
and activate it in Extension module
Setup
After activating extension, you have to define your Content elements configuration classes. It can be done in two ways:
-
By defining paths in extension configuration (aka extConf). Can contain comma separated list of paths to directories Example:
EXT:your_ext_1/Classes/ContentElements/,EXT:your_ext_2/Classes/ContentElements/
- By registering Listener in
Services.yaml
of your extension as follows:
Method Vendor\Extension\EventListeners\ContentElementRegistryListener
can looks like this:
Creating new content element
To create new Content element you have to create new Class inside your folder defined in Setup section which extends Digitalwerk\ContentElementRegistry\ContentElement\AbstractContentElementRegistryItem
After clearing typo3 caches you should now see new content element in wizard
As you can see, there is neither title nor description of the content element. These are automatically fetched and translated from locallang file inside of your extension:
EXT:your_extension/Resources/Private/Language/locallang_db.xlf
. You can now define your CE title and description as follows:
When you add this new CE it will contain only default CE fields:
Adding CE fields
To add new fields you have to define it in \YourVendor\YourExtension\ContentElement\YourNewContentElement
:
By this, we defined new CE palette with name default
with two fields header
and bodytext
.
Code description:
- Name of the palette must be unique per CE. Label for palette can be defined in
locallang_db.xlf
with following key:tt_content.yourextension_yournewcontentelement.palette.default
- Fields definition syntax must follows TCA palette showitem syntax
- Used fields must be properly configured in tt_content TCA
- You can add as many palettes as you need ;)
Our CE now should looks like this:
If you need to override field configuration you can do this in this way: (In following example we've enabled rich text editor for bodytext
field)
CE Template
Template path of content element must be configured in typoscript as follow:
Template name is matched by CE class name. E.g. if is registered CE with class name YourNewContentElement
this
template must exists EXT:your_extension/Resources/Private/Templates/ContentElements/YourNewContentElement.html
.
Content of template can looks like this:
Whether you use <f:layout />
and <f:section />
it's fully up to you. You can also add section
<f:section name="Preview">
which is used for BE preview.
CE Icon
If you don't want to use the defaut icon, you can change it:
- Add an icon to the folder
EXT:your_extension/Resources/Public/Icons/ContentElement/yourextension_yournewcontentelement.svg
CE Domain Model
Model name is matched by CE class name. E.g. if is registered CE with class name YourNewContentElement
this model can
exists in EXT:your_extension/Classes/Domain/Model/YourNewContentElement.php
Content of model can
looks like this:
Into class you can write some functions, getters, setters, etc
. Some of them are inherited from
DigitalWerk\ContentElementRegistry\Domain\Model\ContentElement
(take a look ;).
Model in template
Model is accessible in the template of element with variable name {contentElement}
. To find out what data is loaded in the model in the template use:
<f:debug>{contentElement}</f:debug>
.
Create a new field and setup
Create a new field
- Create a field in the table
ext_table.sql
, e.g.new_field
. - In the TCA
EXT:your_extension/Configuration/TCA/Overrides/tt_content.php
create new column and config Typo3 Columns Config:
Setup a new field
-
In Class
\YourVendor\YourExtension\ContentElement\YourNewContentElement
add created fieldnew_field
: - In Model of CE
EXT:your_extension/Classes/Domain/Model/YourNewContentElement.php
add property of created field$newField
. You must follow the syntax, e.g.new_field
which is written in ext_table.php, you must writenewField
in the model.
Content element with IRRE
Mapping
Map in ext_typoscript_setup.typoscript
relation table to CE model:
Register relation icon
You can register relation icon using Typo3 Icon API
Relation TCA
In TCA EXT:your_extension/Configuration/TCA/Overrides/tx_contentelementregistry_domain_model_relation.php
create:
Relation add to CE
Add name of relation to palette:
Relation model
-
In model of CE create property and getter:
- Create a new file
YourNewRelation.php
in\YourVendor\YourExtension\Domain\Model\ContentElement\YourNewContentElement
. Here you can write getters and properties for fields in TCA of Relation:
CE field mapping
In Class of CE you can map field, when you want to use it in model, e.g. tx_contentelementregistry_relations
is called in the model txContentelementregistryRelation
,
but after mapping 'tx_contentelementregistry_relations' => 'relations'
,tx_contentelementregistry_relations
is called in the model relations
.
Changelog
v1.0.0
- dropped support for typo3 8 and typo3 9
- supported only typo3 v10.4
- experimental headless support