Skip to content

Commit

Permalink
EZP-29290: As an Editor, I want to have preconfigured "Author" sectio…
Browse files Browse the repository at this point in the history
…n while creating the content
  • Loading branch information
konradoboza committed Aug 13, 2018
1 parent 7135170 commit 5133add
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/FieldType/Mapper/AuthorFormMapper.php
Expand Up @@ -35,8 +35,8 @@ public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, Field
ChoiceType::class,
[
'choices' => [
'field_definition.ezauthor.default_user_empty' => Type::DEFAULT_VALUE_EMPTY,
'field_definition.ezauthor.default_user_current' => Type::DEFAULT_CURRENT_USER,
'field_definition.ezauthor.default_user_empty' => Type::DEFAULT_EMPTY,
],
'choices_as_values' => true,
'expanded' => true,
Expand Down
9 changes: 5 additions & 4 deletions lib/Form/Type/FieldType/AuthorFieldType.php
Expand Up @@ -8,6 +8,7 @@

use eZ\Publish\API\Repository\Exceptions\NotFoundException;
use eZ\Publish\API\Repository\Repository;
use eZ\Publish\Core\FieldType\Author\Type as AuthorType;
use eZ\Publish\Core\FieldType\Author\Author;
use eZ\Publish\Core\FieldType\Author\Value;
use EzSystems\RepositoryForms\Form\Type\FieldType\Author\AuthorCollectionType;
Expand Down Expand Up @@ -87,7 +88,7 @@ public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Value::class,
'default_author' => 1,
'default_author' => AuthorType::DEFAULT_VALUE_EMPTY,
])->setAllowedTypes('default_author', 'integer');
}

Expand All @@ -100,10 +101,10 @@ public function getViewTransformer(): DataTransformerInterface
{
return new CallbackTransformer(function (Value $value) {
if (0 === $value->authors->count()) {
if ($this->defaultAuthor === -1) {
$value->authors->append(new Author());
} else {
if ($this->defaultAuthor === AuthorType::DEFAULT_CURRENT_USER) {
$value->authors->append($this->fetchLoggedAuthor());
} else {
$value->authors->append(new Author());
}
}

Expand Down

0 comments on commit 5133add

Please sign in to comment.