mirror of
https://github.com/joomla-extensions/weblinks.git
synced 2025-01-27 22:38:28 +00:00
Create Categories on-the-fly on Link edit form (#252)
* Create Categories on-the-fly on Weblink edit form Create Categories on-the-fly on Weblink edit form (1/3) * Create Categories on-the-fly on Weblink edit form Create Categories on-the-fly on Weblink edit form (2/3) * Create Categories on-the-fly on Weblink edit form Create Categories on-the-fly on Weblink edit form (3/3 * CS fix CS fix * Update weblink.xml * Update weblink.php * Update weblink.php * one space one space as suggested
This commit is contained in:
parent
3548e9f9e0
commit
143fef691b
@ -17,11 +17,14 @@
|
|||||||
description="COM_WEBLINKS_FIELD_ALIAS_DESC"
|
description="COM_WEBLINKS_FIELD_ALIAS_DESC"
|
||||||
hint="JFIELD_ALIAS_PLACEHOLDER" />
|
hint="JFIELD_ALIAS_PLACEHOLDER" />
|
||||||
|
|
||||||
<field name="catid" type="categoryedit" extension="com_weblinks"
|
<field name="catid"
|
||||||
label="JCATEGORY" description="COM_WEBLINKS_FIELD_CATEGORY_DESC"
|
type="categoryedit"
|
||||||
>
|
extension="com_weblinks"
|
||||||
</field>
|
label="JCATEGORY"
|
||||||
|
description="COM_WEBLINKS_FIELD_CATEGORY_DESC"
|
||||||
|
required="true"
|
||||||
|
default=""
|
||||||
|
/>
|
||||||
|
|
||||||
<field name="url" type="url"
|
<field name="url" type="url"
|
||||||
class="span12"
|
class="span12"
|
||||||
|
@ -292,6 +292,31 @@ class WeblinksModelWeblink extends JModelAdmin
|
|||||||
{
|
{
|
||||||
$app = JFactory::getApplication();
|
$app = JFactory::getApplication();
|
||||||
|
|
||||||
|
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_weblinks');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save New Category
|
||||||
|
if ($catid == 0 && $this->canCreateCategory())
|
||||||
|
{
|
||||||
|
$table = array();
|
||||||
|
$table['title'] = $data['catid'];
|
||||||
|
$table['parent_id'] = 1;
|
||||||
|
$table['extension'] = 'com_weblinks';
|
||||||
|
$table['language'] = $data['language'];
|
||||||
|
$table['published'] = 1;
|
||||||
|
|
||||||
|
// Create new category and get catid back
|
||||||
|
$data['catid'] = CategoriesHelper::createCategory($table);
|
||||||
|
}
|
||||||
|
|
||||||
// Alter the title for save as copy
|
// Alter the title for save as copy
|
||||||
if ($app->input->get('task') == 'save2copy')
|
if ($app->input->get('task') == 'save2copy')
|
||||||
{
|
{
|
||||||
@ -332,4 +357,37 @@ class WeblinksModelWeblink extends JModelAdmin
|
|||||||
|
|
||||||
return array($name, $alias);
|
return array($name, $alias);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows preprocessing of the JForm object.
|
||||||
|
*
|
||||||
|
* @param JForm $form The form object
|
||||||
|
* @param array $data The data to be merged into the form object
|
||||||
|
* @param string $group The plugin group to be executed
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 3.6.0
|
||||||
|
*/
|
||||||
|
protected function preprocessForm(JForm $form, $data, $group = 'content')
|
||||||
|
{
|
||||||
|
if ($this->canCreateCategory())
|
||||||
|
{
|
||||||
|
$form->setFieldAttribute('catid', 'allowAdd', 'true');
|
||||||
|
}
|
||||||
|
|
||||||
|
parent::preprocessForm($form, $data, $group);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the user allowed to create an on the fly category?
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
* @since 3.6.0
|
||||||
|
*/
|
||||||
|
private function canCreateCategory()
|
||||||
|
{
|
||||||
|
return JFactory::getUser()->authorise('core.create', 'com_weblinks');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ defined('_JEXEC') or die;
|
|||||||
JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');
|
JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');
|
||||||
|
|
||||||
JHtml::_('behavior.formvalidator');
|
JHtml::_('behavior.formvalidator');
|
||||||
JHtml::_('formbehavior.chosen', 'select');
|
JHtml::_('formbehavior.chosen', 'select', null, array('disable_search_threshold' => 0 ));
|
||||||
|
|
||||||
// Ignore Image fieldset for the layouts as we render it manually
|
// Ignore Image fieldset for the layouts as we render it manually
|
||||||
$this->ignore_fieldsets = array('images');
|
$this->ignore_fieldsets = array('images');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user