Pimcore Object Types: Text Types
Explore the power of text types within Pimcore Object Types, empowering businesses to efficiently manage textual content across their digital data structures. From product descriptions to blog posts, discover how Pimcore's text types streamline content creation and management workflows.
Overview over the Pimcore Object Data Types Text
In the digital landscape, content reigns supreme. Whether it's crafting compelling product descriptions to entice customers or publishing engaging blog posts to drive traffic, businesses rely on efficient content management systems to streamline their workflows. Pimcore, renowned for its versatility and robust features, offers a comprehensive solution with its Object Types module. In this article series, we delve into the intricacies of Pimcore Object Types, starting with a focus on text types. Let's unravel the capabilities of text types within Pimcore and how they revolutionize content management for businesses of all sizes.
The Input Data Type
The Input Data Type gives you a simple way to store string data in your object. It is stored as a varchar in the database and is limited to the length of the varchar colum length.
It has all the default settings of Pimcore data types like Mandatory field (needs to be filled before saving), Indexed (creates an index in the database table for the column), Unique, Not editable (can only be filled via code or copying), Invisible (will not show in the Backend), Visible in Grid (visible in the Pimcore folder view), Visible in Search Result as well as CSS Styling (only affects Pimcore Backend), Default Values (will not affect newly created objects via code, only in Backend), Default value generator service (dynamically generate default value), width (only affect Pimcore Backend), Show Character Count, Columnlength (limits the length of the database column)
You can also define advances Validation of the field via Regex.
$object = MyObject::getById(1);
// get data from input field
$input = $object->getInputExample();
$object = MyObject::getById(1);
// set data to input field
$object->setInputExample('ExampleData');
$object->save();
// clear data of input field
$object->setInputExample(null);
$object->save();
The Textarea Data Type
Similar to the input data type the textarea allows you to store strings. Different to the textarea data type allows you to store longer strings as it creates a longtext column in your database table.
It also shows a multiple lines fields in the object and might help with data visibilty. It cannot be declared as unique and also does not support default values and since it can contain a lot of data it can be excluded from the Pimcore backend search.
$object = MyObject::getById(1);
// get data from textarea field
$textarea = $object->getTextareaExample();
$object = MyObject::getById(1);
// set data to textarea field
$object->setTextareaExample('ExampleData');
$object->save();
// clear data of textarea field
$object->setTextareaExample(null);
$object->save();
The WSYIWYG Data Type
Similar to the textarea data type the WYSIWYG data type allows you to store string data. Different to the textarea data type it initializes a WYSIWYG editor in the Pimcore backend and stores HTML code in the database. For this you need to have the TinyMCEBundle installed in your Pimcore Instance.
You can also define extra editor configurations (see TinyMCE Configuration)
$object = MyObject::getById(1);
// get data from wysiwyg field
$Wysiwyg = $object->getWysiwygExample();
$object = MyObject::getById(1);
// set data to wysiwyg field
$object->setWysiwygExample('<p>ExampleData</p>');
$object->save();
// clear data of wysiwyg field
$object->setWysiwygExample(null);
$object->save();
{# don't forget to output the value raw as it contains HTML code #}
{{ pimcore_object(1).wysiwygExample|raw }}
The Password Data Type
This type allows you to store password encrypted in the database. It will also create a varchar column in the database table but will store the data encrypted with a selected algorithm. Default it will use the password_hash algorithm, but has a huge selection to choose from.
$object = MyObject::getById(1);
// get data from password field
$Password = $object->getPasswordExample();
$object = MyObject::getById(1);
// set data to password field
$object->setPasswordExample('supersecretpassword'); // will be encrypted automatically
$object->save();
// clear data of password field
$object->setPasswordExample(null);
$object->save();
// verify password
// selected algorithm can be omitted if password_hash is selected
$isValid = password_verify($object->getPasswordExample(), 'selected algorithm');
The Input Quantity Value Data Type
This data type requires some setup first.
You need to define Quantity Values first in the QuantityValue Unit Definition shown below.
In this example we created weight quantity values with grams, kilograms and miligrams.
You can limit which quantity value should be allowed in this field.
It will automatically add the unit separated by a space to the string.
In the database it will create two columns with the value and the unit separated.
$object = MyObject::getById(1);
// get data from inputQuantityValue field
$inputQuantityValue = $object->getInputQuantityValueExample();
$object = MyObject::getById(1);
// set data to inputQuantityValue field
$unit = \Pimcore\Model\DataObject\QuantityValue\Unit::getByAbbreviation("g");
$object->setInputQuantityValueExample(new \Pimcore\Model\DataObject\Data\QuantityValue(('ExampleData', $unit->getId()));
$object->save();
// clear data of inputQuantityValue field
$object->setInputQuantityValueExample(null);
$object->save();
Comments (0)
-
No Comments