Created
September 5, 2018 11:10
-
-
Save Anubarak/5e080f527f784d05cfc32a41c900e3d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$sectionHandle = 'character'; | |
$entryTypeHandle = 'character'; | |
$newEntryTypeHandle = 'newType3'; | |
$newEntryTypeName = 'A new Type3'; | |
/** @var Section $section */ | |
$section = Craft::$app->getSections()->getSectionByHandle($sectionHandle); | |
$entryTypes = $section->getEntryTypes(); | |
$entryType = ArrayHelper::filterByValue($entryTypes, 'handle', $entryTypeHandle); | |
if(\count($entryType) === 1){ | |
/** @var EntryType $entryType */ | |
$entryType = $entryType[0]; | |
$newEntryType = new EntryType([ | |
'sectionId' => $entryType->sectionId, | |
'handle' => $newEntryTypeHandle, | |
'name' => $newEntryTypeName | |
]); | |
$oldLayout = $entryType->getFieldLayout(); | |
$fieldLayout = new FieldLayout([ | |
'tabs' => $oldLayout->getTabs(), | |
'fields' => $oldLayout->getFields(), | |
'type' => $oldLayout->type | |
]); | |
if(!Craft::$app->getFields()->saveLayout($fieldLayout)){ | |
die('Couldn`t save layout'); | |
} | |
echo 'new layout ID ' . $fieldLayout->id . '<br>'; | |
$newEntryType->setFieldLayout($fieldLayout); | |
$success = Craft::$app->getSections()->saveEntryType($newEntryType); | |
echo "<pre>"; | |
var_dump($success); | |
var_dump($newEntryType->getErrors()); | |
echo "</pre>"; | |
die(); | |
} | |
die('no entry type found'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment