Skip to content

Commit 294af9f

Browse files
authored
Merge pull request #7 from styleflasher/admin-ui-integration
make content types containing enhancedbinaryfile field type(s) editable in ezplatform admin ui
2 parents 6ee74c7 + 519a8eb commit 294af9f

File tree

10 files changed

+88
-5
lines changed

10 files changed

+88
-5
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Netgen\Bundle\EnhancedBinaryFileBundle\Core\FieldType\EnhancedBinaryFile;
4+
5+
use EzSystems\RepositoryForms\Data\FieldDefinitionData;
6+
use EzSystems\RepositoryForms\FieldType\FieldDefinitionFormMapperInterface;
7+
use EzSystems\RepositoryForms\FieldType\Mapper\BinaryFileFormMapper;
8+
use Symfony\Component\Form\Extension\Core\Type\TextType;
9+
use Symfony\Component\Form\FormInterface;
10+
11+
class FormMapper extends BinaryFileFormMapper
12+
{
13+
public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $data)
14+
{
15+
parent::mapFieldDefinitionForm($fieldDefinitionForm, $data);
16+
17+
$fieldDefinitionForm
18+
->add(
19+
'allowedTypes',
20+
TextType::class,
21+
[
22+
'required' => false,
23+
'property_path' => 'fieldSettings[allowedTypes]',
24+
'label' => 'field_definition.enhancedbinaryfile.allowedTypes',
25+
'translation_domain' => 'messages',
26+
]
27+
);
28+
}
29+
}

bundle/Core/Persistence/Legacy/Content/FieldValue/Converter/Converter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefin
6262
'FileSizeValidator' => array(
6363
'maxFileSize' => (0 !== $storageDef->dataInt1
6464
? $storageDef->dataInt1
65-
: false),
65+
: null),
6666
),
6767
),
6868
'fieldSettings' => new FieldSettings(array(

bundle/DependencyInjection/NetgenEnhancedBinaryFileExtension.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,31 @@
33
namespace Netgen\Bundle\EnhancedBinaryFileBundle\DependencyInjection;
44

55
use Symfony\Component\Config\FileLocator;
6+
use Symfony\Component\Config\Resource\FileResource;
67
use Symfony\Component\DependencyInjection\ContainerBuilder;
8+
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
79
use Symfony\Component\DependencyInjection\Loader;
810
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
11+
use Symfony\Component\Yaml\Yaml;
912

10-
class NetgenEnhancedBinaryFileExtension extends Extension
13+
class NetgenEnhancedBinaryFileExtension extends Extension implements PrependExtensionInterface
1114
{
15+
/**
16+
* Preprend ezpublish configuration to make the field templates
17+
* visibile to the admin template engine
18+
*
19+
* @param ContainerBuilder $container
20+
*/
21+
public function prepend( ContainerBuilder $container )
22+
{
23+
$fileName = "ez_field_templates.yml";
24+
$configFile = __DIR__ . '/../Resources/config/' . $fileName;
25+
$config = Yaml::parse(file_get_contents($configFile));
26+
27+
$container->prependExtensionConfig("ezpublish", $config);
28+
$container->addResource(new FileResource($configFile));
29+
}
30+
1231
/**
1332
* {@inheritdoc}
1433
*/

bundle/Form/FieldTypeHandler/EnhancedFile.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use eZ\Publish\SPI\FieldType\Value;
99
use Netgen\Bundle\EzFormsBundle\Form\FieldTypeHandler;
1010
use Netgen\Bundle\EnhancedBinaryFileBundle\Core\FieldType\EnhancedBinaryFile\Value as EnhancedFileValue;
11+
use Symfony\Component\Form\Extension\Core\Type\FileType;
1112
use Symfony\Component\Form\FormBuilderInterface;
1213
use Symfony\Component\HttpFoundation\File\UploadedFile;
1314
use Symfony\Component\Validator\Constraints;
@@ -68,10 +69,10 @@ protected function buildFieldForm(
6869
$maxFileSize = $fieldDefinition->validatorConfiguration['FileSizeValidator']['maxFileSize'];
6970
$allowedExtensions = $fieldDefinition->fieldSettings['allowedTypes'];
7071

71-
if (false !== $maxFileSize || !empty($allowedExtensions)) {
72+
if (null !== $maxFileSize || !empty($allowedExtensions)) {
7273
$constraints = array();
7374

74-
if (false !== $maxFileSize && !empty($maxFileSize)) {
75+
if (null !== $maxFileSize && !empty($maxFileSize)) {
7576
$constraints['maxSize'] = strval($maxFileSize) . "M";
7677
}
7778

@@ -94,6 +95,6 @@ protected function buildFieldForm(
9495
// EnhancedBinaryFile should not be erased (updated as empty) if nothing is selected in file input
9596
$this->skipEmptyUpdate($formBuilder, $fieldDefinition->identifier);
9697

97-
$formBuilder->add($fieldDefinition->identifier, 'file', $options);
98+
$formBuilder->add($fieldDefinition->identifier, FileType::class, $options);
9899
}
99100
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
system:
2+
default:
3+
fielddefinition_edit_templates:
4+
- template: "NetgenEnhancedBinaryFileBundle:admin:field_types.html.twig"
5+
field_templates:
6+
- template: "NetgenEnhancedBinaryFileBundle:content_fields.html.twig"

bundle/Resources/config/fieldtypes.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,11 @@ services:
1212
class: eZ\Publish\Core\FieldType\BinaryFile\BinaryFileStorage\Gateway\LegacyStorage
1313
tags:
1414
- { name: ezpublish.fieldType.externalStorageHandler.gateway, alias: enhancedezbinaryfile, identifier: LegacyStorage }
15+
16+
ezpublish.fieldType.enhancedezbinaryfile.form_mapper:
17+
class: Netgen\Bundle\EnhancedBinaryFileBundle\Core\FieldType\EnhancedBinaryFile\FormMapper
18+
arguments:
19+
- "@ezpublish.api.service.field_type"
20+
- "@ezrepoforms.config_resolver.max_upload_size"
21+
tags:
22+
- { name: ez.fieldFormMapper.definition, fieldType: enhancedezbinaryfile }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
field_definition.enhancedbinaryfile.allowedTypes: Erlaubte Dateiformate (komma-separiert)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
field_definition.enhancedbinaryfile.allowedTypes: Allowed file types (comma separated)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{% extends 'EzSystemsRepositoryFormsBundle:ContentType:field_types.html.twig' %}
2+
{% block enhancedezbinaryfile_field_definition_edit %}
3+
<div class="enhancedezbinaryfile-validator max-file-size{% if group_class is not empty %} {{ group_class }}{% endif %}">
4+
{{- form_label(form.maxSize) -}}
5+
{{- form_errors(form.maxSize) -}}
6+
{{- form_widget(form.maxSize) -}}
7+
</div>
8+
9+
<div class="enhancedezbinaryfile-validator allowed-file-types{% if group_class is not empty %} {{ group_class }}{% endif %}">
10+
{{- form_label(form.allowedTypes) -}}
11+
{{- form_errors(form.allowedTypes) -}}
12+
{{- form_widget(form.allowedTypes) -}}
13+
</div>
14+
{% endblock %}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{% extends "EzPublishCoreBundle::content_fields.html.twig" %}
2+
{% block enhancedbinaryfile_field %}
3+
{{ block('ezbinaryfile_field') }}
4+
{% endblock %}

0 commit comments

Comments
 (0)