Seeder by CartThrob Version 1.2.0
Channel Entry Library
The Channel Entry library included with Seeder is very flexible and can be used to programmatically manipulate a complete Channel Entry object.
Basic Use
The easiest way to get started is through the ChannelEntryService
provided with CartThrob Seeder. A simple example would be:
Get Existing Entry
$cd_service = ee('cartthrob_seeder:ChannelEntryService');
$entry = $cd_service->getEntry($id);
Get Blank Entry (for creation)
Note you need a channel_id when starting a new entry.
$cd_service = ee('cartthrob_seeder:ChannelEntryService'); $entry = $entry = $cd_service->getBlankEntry($channel_id);
Both the above examples will return a
CartThrob\Seeder\Channels\Entries\Entry
object which will let you manipulate to your needs.
Edit Entry
$cd_service = ee('cartthrob_seeder:ChannelEntryService');
$entry = $cd_service->getEntry($id);
$data = [
'my_custom_field' => [1,5,3],
'title' => 'My New Title',
];
$entry->setData($data);
$entry->save();
Create Entry
$cd_service = ee('cartthrob_seeder:ChannelEntryService');
$entry = $entry = $cd_service->getBlankEntry($channel_id);
$date = new \DateTime();
$entry->set('title', 'My Title');
$entry->set('author_id', 56);
$entry->save();
$entry_id = $entry->getEntryId();
Note that all objects are usable after writes.
$cd_service = ee('cartthrob_seeder:ChannelEntryService');
$entry = $cd_service->getEntry($id);
$data = [
'my_custom_field' => [1,5,3],
'title' => 'My New Title',
];
$entry->setData($data);
$entry->save();
$entry->set('title', 'Another Title');
$entry->save();
$entry->set('title', 'Once More');
$entry->save();
Supported First Party FieldTypes
Below are the ExpressionEngine FieldTypes that are represented within the Channel Entry Library and how their data is provided programmatically.
Text string
The raw data as a string
Textarea string
The raw data as a string
Toggle boolean
Simple true
/false
dending on value
File integer
The file_id
for the file used in the field
Checkboxes array
A flat array of selected values from set options
Date DateTime
A configured DateTime
object
Multi Select array
A flat array of selected values from set options
Color Picker string
The raw data as a string
URL string
The raw data as a string
Colorpicker string
The raw data as a string
Duration array
A breakdown of the duration details
Email Addressstring
The raw data as a string
Relationship array
A flat array of entry_ids the Parent is related to
Rich Text Editor (RTE) string
The raw data as a string
Selectstring
The raw data as a string