protected function parseContentType($key, $contentType, $generalConfig)
{
// If the slug isn't set, and the 'key' isn't numeric, use that as the slug.
if (!isset($contentType['slug']) && !is_numeric($key)) {
$contentType['slug'] = Slugify::create()->slugify($key);
}
// If neither 'name' nor 'slug' is set, we need to warn the user. Same goes for when
// neither 'singular_name' nor 'singular_slug' is set.
if (!isset($contentType['name']) && !isset($contentType['slug'])) {
$error = sprintf("In contenttype <code>%s</code>, neither 'name' nor 'slug' is set. Please edit <code>contenttypes.yml</code>, and correct this.", $key);
throw new InvalidArgumentException($error);
}
if (!isset($contentType['singular_name']) && !isset($contentType['singular_slug'])) {
$error = sprintf("In contenttype <code>%s</code>, neither 'singular_name' nor 'singular_slug' is set. Please edit <code>contenttypes.yml</code>, and correct this.", $key);
throw new InvalidArgumentException($error);
}
// Contenttypes without fields make no sense.
if (!isset($contentType['fields'])) {
$error = sprintf("In contenttype <code>%s</code>, no 'fields' are set. Please edit <code>contenttypes.yml</code>, and correct this.", $key);
throw new InvalidArgumentException($error);
}
if (!isset($contentType['slug'])) {
$contentType['slug'] = Slugify::create()->slugify($contentType['name']);
}
if (!isset($contentType['name'])) {
$contentType['name'] = ucwords(preg_replace('/[^a-z0-9]/i', ' ', $contentType['slug']));
}
if (!isset($contentType['singular_slug'])) {
$contentType['singular_slug'] = Slugify::create()->slugify($contentType['singular_name']);
}
if (!isset($contentType['singular_name'])) {
$contentType['singular_name'] = ucwords(preg_replace('/[^a-z0-9]/i', ' ', $contentType['singular_slug']));
}
if (!isset($contentType['show_on_dashboard'])) {
$contentType['show_on_dashboard'] = true;
}
if (!isset($contentType['show_in_menu'])) {
$contentType['show_in_menu'] = true;
}
if (!isset($contentType['sort'])) {
$contentType['sort'] = false;
}
if (!isset($contentType['default_status'])) {
$contentType['default_status'] = 'draft';
}
if (!isset($contentType['viewless'])) {
$contentType['viewless'] = false;
}
if (!isset($contentType['liveeditor'])) {
$contentType['liveeditor'] = true;
}
// Override contenttype setting with view and config settings
if ($contentType['viewless'] || !$generalConfig['liveeditor']) {
$contentType['liveeditor'] = false;
}
// Allow explicit setting of a Contenttype's table name suffix. We default
// to slug if not present as it has been this way since Bolt v1.2.1
if (!isset($contentType['tablename'])) {
$contentType['tablename'] = Slugify::create()->slugify($contentType['slug'], '_');
} else {
$contentType['tablename'] = Slugify::create()->slugify($contentType['tablename'], '_');
}
if (!isset($contentType['allow_numeric_slugs'])) {
$contentType['allow_numeric_slugs'] = false;
}
list($fields, $groups) = $this->parseFieldsAndGroups($contentType['fields'], $generalConfig);
$contentType['fields'] = $fields;
$contentType['groups'] = $groups;
// Make sure taxonomy is an array.
if (isset($contentType['taxonomy'])) {
$contentType['taxonomy'] = (array) $contentType['taxonomy'];
}
// when adding relations, make sure they're added by their slug. Not their 'name' or 'singular name'.
if (!empty($contentType['relations']) && is_array($contentType['relations'])) {
foreach (array_keys($contentType['relations']) as $relkey) {
if ($relkey != Slugify::create()->slugify($relkey)) {
$contentType['relations'][Slugify::create()->slugify($relkey)] = $contentType['relations'][$relkey];
unset($contentType['relations'][$relkey]);
}
}
}
return $contentType;
}