Skip to content

Commit

Permalink
Merge pull request joomla#50 from Lemings/patch-3
Browse files Browse the repository at this point in the history
Thiis adds nested tag form field to administrator/tag view.
  • Loading branch information
elinw committed Mar 4, 2013
2 parents f5491e4 + 5575898 commit 8b1ec57
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
2 changes: 1 addition & 1 deletion administrator/components/com_tags/models/forms/tag.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<field
name="parent_id"
type="tag"
type="tagnested"
label="COM_TAGS_FIELD_PARENT_LABEL"
description="COM_TAGS_FIELD_PARENT_DESC"
validate="notequals"
Expand Down
77 changes: 77 additions & 0 deletions libraries/cms/form/field/tagnested.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_tags
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('JPATH_BASE') or die;

JFormHelper::loadFieldClass('tag');

/**
* Form Field class for the Joomla Framework.
*
* @package Joomla.Administrator
* @subpackage com_tags
* @since 3.1
*/
class JFormFieldTagNested extends JFormFieldTag
{
/**
* A flexible tag list that respects access controls
*
* @var string
* @since 3.1
*/
public $type = 'TagNested';

/**
* An array of tags
*
* @var string
* @since 3.1
*/
public $tags;

/**
* Method to get the field input for a tag field.
*
* @return string The field input.
*
* @since 3.1
*/
protected function getInput()
{
// This value is replaced with JTags object to fake parent tag formfield, othervise it is set to array ()
$newValue = new JTags;
$newValue->tags = $this->value;
$this->value = $newValue;

$input = parent::getInput();

return $input;
}

/**
* Method to get a list of tags
*
* @return array The field option objects.
* @since 3.1
*/
protected function getOptions()
{
$options = parent::getOptions();

// Add "-" before nested tags, depending on level
foreach ($options as &$option)
{
$repeat = (isset($option->level) && $option->level - 1 >= 0) ? $option->level - 1 : 0;
$option->text = str_repeat('- ', $repeat) . $option->text;
}

return $options;
}
}

0 comments on commit 8b1ec57

Please sign in to comment.