/** * Determine which templates will result in templatefields. * * @param ContentType $contentType * @param Content $content * * @return array */ private function getTemplateFieldTemplates(ContentType $contentType, Content $content) { $templateFieldTemplates = []; $templateFieldsConfig = $this->config->get('theme/templatefields'); if ($templateFieldsConfig) { $templateFieldTemplates = array_keys($templateFieldsConfig); // Special case for default template $toRepair = []; foreach ($contentType['fields'] as $name => $field) { if ($field['type'] === 'templateselect' && !empty($content->values[$name])) { $toRepair[$name] = $content->values[$name]; $content->set($name, ''); } } if ($content->hasTemplateFields()) { $templateFieldTemplates[] = ''; } foreach ($toRepair as $name => $value) { $content->set($name, $value); } } return $templateFieldTemplates; }
/** * Set a Contenttype record values from a HTTP POST. * * @param Entity\Content $content * @param array $formValues * @param array $contentType * * @throws AccessControlException */ private function setPostedValues(Entity\Content $content, $formValues, $contentType) { // Ensure all fields have valid values $formValues = $this->setSuccessfulControlValues($formValues, $contentType['fields']); $formValues = Input::cleanPostedData($formValues); unset($formValues['contenttype']); $user = $this->users->getCurrentUser(); if ($id = $content->getId()) { // Owner is set explicitly, is current user is allowed to do this? if (isset($formValues['ownerid']) && (int) $formValues['ownerid'] !== $content->getOwnerid()) { if (!$this->users->isAllowed("contenttype:{$contentType['slug']}:change-ownership:{$id}")) { throw new AccessControlException('Changing ownership is not allowed.'); } $content->setOwnerid($formValues['ownerid']); } } else { $content->setOwnerid($user['id']); } // Make sure we have a proper status. if (!in_array($formValues['status'], ['published', 'timed', 'held', 'draft'])) { if ($status = $content->getStatus()) { $formValues['status'] = $status; } else { $formValues['status'] = 'draft'; } } // Set the object values appropriately foreach ($formValues as $name => $value) { if ($name === 'relation' || $name === 'taxonomy') { continue; } else { $content->set($name, empty($value) ? null : $value); } } $this->setPostedRelations($content, $formValues); $this->setPostedTaxonomies($content, $formValues); }