Files
kimai2/src/Form/TimesheetEditForm.php
Kevin Papst 3dc054b839 help text and link for form labels #138 (#143)
* added help for timesheet duration form field - fixes #138
* added label option to link to manual chapter
* created docu chapter "timesheet" and added duration mode docu
* allow field and form option "documentation" to link to chapters in the documentation
2018-06-21 18:25:11 +02:00

101 lines
3.0 KiB
PHP

<?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;
use App\Form\Type\DurationType;
use App\Form\Type\UserType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use App\Entity\Timesheet;
use App\Form\Type\ActivityGroupedWithCustomerNameType;
use App\Repository\ActivityRepository;
/**
* Defines the form used to manipulate Timesheet entries.
*/
class TimesheetEditForm extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
/** @var Timesheet $entry */
$entry = $options['data'];
$activity = null;
if ($entry->getId() !== null) {
$activity = $entry->getActivity();
}
if ($entry->getEnd() === null || !$options['duration_only']) {
$builder->add('begin', DateTimeType::class, [
'label' => 'label.begin',
'widget' => 'single_text',
'html5' => false,
'format' => 'yyyy-MM-dd H:m',
'with_seconds' => false,
'attr' => ['data-datetimepicker' => 'on'],
]);
}
if ($options['duration_only']) {
$builder->add('duration', DurationType::class);
} else {
$builder->add('end', DateTimeType::class, [
'label' => 'label.end',
'widget' => 'single_text',
'required' => false,
'html5' => false,
'format' => 'yyyy-MM-dd H:m',
'with_seconds' => false,
'attr' => ['data-datetimepicker' => 'on'],
]);
}
$builder
->add('activity', ActivityGroupedWithCustomerNameType::class, [
'label' => 'label.activity',
'query_builder' => function (ActivityRepository $repo) use ($activity) {
return $repo->builderForEntityType($activity);
},
])
->add('description', TextareaType::class, [
'label' => 'label.description',
'required' => false,
])
;
if ($options['include_user']) {
$builder->add('user', UserType::class);
}
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Timesheet::class,
'csrf_protection' => true,
'csrf_field_name' => '_token',
'csrf_token_id' => 'timesheet_edit',
'duration_only' => false,
'include_user' => false,
'documentation' => 'timesheet',
]);
}
}