PHP code example of storychief / craft-cms-v3-storychief
1. Go to this page and download the library: Download storychief/craft-cms-v3-storychief library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
storychief / craft-cms-v3-storychief example snippets
use storychief\storychiefv3\events\EntryPublishEvent;
$this->on('beforeEntryPublish', function (EntryPublishEvent $event) {
$payload = $event->payload;
$settings = $event->settings;
$entry = $event->entry;
// Example 1:
$entry->sectionId = 2; // BLog
$entry->typeId = 2;
// Example 2:
if ($payload['data']['custom_fields']) {
foreach ($payload['data']['custom_fields'] as $customField) {
if ($customField['key'] === 'custom_field_name') {
$entry->sectionId = $customField['value'];
$entry->typeId = 2;
}
}
}
});
use storychief\storychiefv3\events\EntryUpdateEvent;
$this->on('beforeEntryUpdate', function (EntryUpdateEvent $event) {
// ...
});