diff --git a/administrator/components/com_contact/models/contact.php b/administrator/components/com_contact/models/contact.php index b06c723933c3a..90162f7fece7c 100644 --- a/administrator/components/com_contact/models/contact.php +++ b/administrator/components/com_contact/models/contact.php @@ -384,6 +384,31 @@ public function save($data) { $input = JFactory::getApplication()->input; + JLoader::register('CategoriesHelper', JPATH_ADMINISTRATOR . '/components/com_categories/helpers/categories.php'); + + // Cast catid to integer for comparison + $catid = (int) $data['catid']; + + // Check if New Category exists + if ($catid > 0) + { + $catid = CategoriesHelper::validateCategoryId($data['catid'], 'com_contact'); + } + + // Save New Category + if ($catid == 0) + { + $table = array(); + $table['title'] = $data['catid']; + $table['parent_id'] = 1; + $table['extension'] = 'com_contact'; + $table['language'] = $data['language']; + $table['published'] = 1; + + // Create new category and get catid back + $data['catid'] = CategoriesHelper::createCategory($table); + } + // Alter the name for save as copy if ($input->get('task') == 'save2copy') { diff --git a/administrator/components/com_contact/models/forms/contact.xml b/administrator/components/com_contact/models/forms/contact.xml index 726ef91c12b17..2dc780a6a5c3f 100644 --- a/administrator/components/com_contact/models/forms/contact.xml +++ b/administrator/components/com_contact/models/forms/contact.xml @@ -69,6 +69,8 @@ label="JCATEGORY" description="JFIELD_CATEGORY_DESC" required="true" + allowAdd="true" + default="" />