added option to use only pre-defined tags (#1463)
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
namespace App\Form\API;
|
||||
|
||||
use App\Form\TimesheetEditForm;
|
||||
use App\Form\Type\TagsInputType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
@@ -29,6 +30,19 @@ class TimesheetApiEditForm extends TimesheetEditForm
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method added to prevent API BC breaks.
|
||||
*
|
||||
* @param FormBuilderInterface $builder
|
||||
*/
|
||||
protected function addTags(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder
|
||||
->add('tags', TagsInputType::class, [
|
||||
'required' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
parent::configureOptions($resolver);
|
||||
|
||||
@@ -15,7 +15,7 @@ use App\Entity\Project;
|
||||
use App\Form\Type\ActivityType;
|
||||
use App\Form\Type\CustomerType;
|
||||
use App\Form\Type\ProjectType;
|
||||
use App\Form\Type\TagsInputType;
|
||||
use App\Form\Type\TagsType;
|
||||
use App\Repository\ActivityRepository;
|
||||
use App\Repository\CustomerRepository;
|
||||
use App\Repository\ProjectRepository;
|
||||
@@ -29,6 +29,7 @@ use Symfony\Component\Form\FormEvents;
|
||||
|
||||
/**
|
||||
* Defines the form used to manipulate Timesheet entries.
|
||||
* @internal
|
||||
*/
|
||||
trait FormTrait
|
||||
{
|
||||
@@ -148,12 +149,7 @@ trait FormTrait
|
||||
protected function addTags(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder
|
||||
->add('tags', TagsInputType::class, [
|
||||
// documentation is for NelmioApiDocBundle
|
||||
'documentation' => [
|
||||
'type' => 'string',
|
||||
'description' => 'Comma separated list of tags',
|
||||
],
|
||||
->add('tags', TagsType::class, [
|
||||
'required' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ use App\Form\Type\CustomerType;
|
||||
use App\Form\Type\FixedRateType;
|
||||
use App\Form\Type\HourlyRateType;
|
||||
use App\Form\Type\ProjectType;
|
||||
use App\Form\Type\TagsInputType;
|
||||
use App\Form\Type\TagsType;
|
||||
use App\Form\Type\UserType;
|
||||
use App\Form\Type\YesNoType;
|
||||
use App\Repository\ActivityRepository;
|
||||
@@ -180,7 +180,7 @@ class TimesheetMultiUpdate extends AbstractType
|
||||
]
|
||||
]);
|
||||
|
||||
$builder->add('tags', TagsInputType::class, [
|
||||
$builder->add('tags', TagsType::class, [
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
|
||||
@@ -15,8 +15,7 @@ use App\Form\Type\DateRangeType;
|
||||
use App\Form\Type\PageSizeType;
|
||||
use App\Form\Type\ProjectType;
|
||||
use App\Form\Type\SearchTermType;
|
||||
use App\Form\Type\TagsInputType;
|
||||
use App\Form\Type\TagsSelectType;
|
||||
use App\Form\Type\TagsType;
|
||||
use App\Form\Type\UserRoleType;
|
||||
use App\Form\Type\UserType;
|
||||
use App\Form\Type\VisibilityType;
|
||||
@@ -225,20 +224,11 @@ abstract class AbstractToolbarForm extends AbstractType
|
||||
|
||||
protected function addTagInputField(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder->add('tags', TagsInputType::class, [
|
||||
$builder->add('tags', TagsType::class, [
|
||||
'required' => false
|
||||
]);
|
||||
}
|
||||
|
||||
// TODO add a system setting to control if tags can be created on the fly
|
||||
protected function addTagSelectField(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder->add('tags', TagsSelectType::class, [
|
||||
'required' => false,
|
||||
'multiple' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
protected function addSearchTermInputField(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder->add('searchTerm', SearchTermType::class);
|
||||
|
||||
@@ -58,6 +58,11 @@ class TagsInputType extends AbstractType
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
// documentation is for NelmioApiDocBundle
|
||||
'documentation' => [
|
||||
'type' => 'string',
|
||||
'description' => 'Comma separated list of tags',
|
||||
],
|
||||
'label' => 'label.tag',
|
||||
'attr' => [
|
||||
'data-autocomplete-url' => $this->router->generate('get_tags'),
|
||||
|
||||
@@ -28,6 +28,7 @@ class TagsSelectType extends AbstractType
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'multiple' => true,
|
||||
'class' => Tag::class,
|
||||
'label' => 'label.tag',
|
||||
'choice_label' => function (Tag $tag) {
|
||||
|
||||
38
src/Form/Type/TagsType.php
Normal file
38
src/Form/Type/TagsType.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Form\Type;
|
||||
|
||||
use App\Configuration\ThemeConfiguration;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
|
||||
class TagsType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* @var ThemeConfiguration
|
||||
*/
|
||||
private $configuration;
|
||||
|
||||
public function __construct(ThemeConfiguration $configuration)
|
||||
{
|
||||
$this->configuration = $configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
if ($this->configuration->isAllowTagCreation()) {
|
||||
return TagsInputType::class;
|
||||
}
|
||||
|
||||
return TagsSelectType::class;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user