/** * Saves an entry type. * * @return null */ public function actionSaveEntryType() { $this->requirePostRequest(); $entryTypeId = craft()->request->getPost('entryTypeId'); if ($entryTypeId) { $entryType = craft()->sections->getEntryTypeById($entryTypeId); if (!$entryType) { throw new Exception(Craft::t('No entry type exists with the ID “{id}”', array('id' => $entryTypeId))); } } else { $entryType = new EntryTypeModel(); } // Set the simple stuff $entryType->sectionId = craft()->request->getRequiredPost('sectionId', $entryType->sectionId); $entryType->name = craft()->request->getPost('name', $entryType->name); $entryType->handle = craft()->request->getPost('handle', $entryType->handle); $entryType->hasTitleField = (bool) craft()->request->getPost('hasTitleField', $entryType->hasTitleField); $entryType->titleLabel = craft()->request->getPost('titleLabel', $entryType->titleLabel); $entryType->titleFormat = craft()->request->getPost('titleFormat', $entryType->titleFormat); // Set the field layout $fieldLayout = craft()->fields->assembleLayoutFromPost(); $fieldLayout->type = ElementType::Entry; $entryType->setFieldLayout($fieldLayout); // Save it if (craft()->sections->saveEntryType($entryType)) { craft()->userSession->setNotice(Craft::t('Entry type saved.')); $this->redirectToPostedUrl($entryType); } else { craft()->userSession->setError(Craft::t('Couldn’t save entry type.')); } // Send the entry type back to the template craft()->urlManager->setRouteVariables(array('entryType' => $entryType)); }
/** * @param EntryTypeModel $entryType * @param array $entryTypeDefinition * @param string $entryTypeHandle * @param int $sectionId */ private function populateEntryType(EntryTypeModel $entryType, array $entryTypeDefinition, $entryTypeHandle, $sectionId) { $entryType->setAttributes(array('handle' => $entryTypeHandle, 'sectionId' => $sectionId, 'name' => $entryTypeDefinition['name'], 'hasTitleField' => $entryTypeDefinition['hasTitleField'], 'titleLabel' => $entryTypeDefinition['titleLabel'], 'titleFormat' => $entryTypeDefinition['titleFormat'])); $fieldLayout = craft()->artVandelay_fields->getFieldLayout($entryTypeDefinition['fieldLayout']); $entryType->setFieldLayout($fieldLayout); }