UploadViewHelper
class UploadViewHelper extends AbstractFormFieldViewHelper (View source)
A view helper which generates an HTML element.
Make sure to set enctype="multipart/form-data" on the form!
If a file has been uploaded successfully and the form is re-displayed due to validation errors, this ViewHelper will render hidden fields that contain the previously generated resource so you won't have to upload the file again.
You can use a separate ViewHelper to display previously uploaded resources in order to remove/replace them.
= Examples =
<output>
<input type="file" name="file" />
</output>
<code title="Multiple Uploads">
<f:form.upload property="attachments.0.originalResource" />
<f:form.upload property="attachments.1.originalResource" />
<output>
<input type="hidden" name="file[originallySubmittedResource][__identity]" value="<someDefaultResource-UUID>" />
<input type="file" name="file" />
</output>
<code title="Specifying the resource collection for the new resource">
<f:form.upload name="file" collection="invoices"/>
Properties
protected RenderingContextInterface | $renderingContext | from AbstractViewHelper | |
protected ControllerContext | $controllerContext | Controller Context to use |
from AbstractViewHelper |
protected ObjectManagerInterface | $objectManager | from AbstractViewHelper | |
protected LoggerInterface | $logger | from AbstractViewHelper | |
protected bool | $escapeOutput | Disable escaping of tag based ViewHelpers so that the rendered tag is not htmlspecialchar'd |
from AbstractTagBasedViewHelper |
protected TagBuilder | $tag | Tag builder instance |
from AbstractTagBasedViewHelper |
protected string | $tagName | ||
protected PersistenceManagerInterface | $persistenceManager | from AbstractFormViewHelper | |
protected PropertyMapper | $propertyMapper |
Methods
No description
Injects the (system) logger based on PSR-3.
Register a new tag attribute. Tag attributes are all arguments which will be directly appended to a tag if you call $this->initializeTag()
Registers all standard HTML universal attributes.
Handles additional arguments, sorting out any data- prefixed tag attributes and assigning them. Then passes the unassigned arguments to the parent class' method, which in the default implementation will throw an error about "undeclared argument used".
Injects the Flow Persistence Manager
Prefixes / namespaces the given name with the form field prefix
Renders a hidden form field containing the technical identity of the given object.
Register a field name for inclusion in the HMAC / Form Token generation
No description
Shortcut for retrieving the request from the controller context
Get the name of this form element, without prefix.
Returns the current value of this Form ViewHelper and converts it to an identifier string in case it's an object The value is determined as follows:
- If property mapping errors occurred and the form is re-displayed, the last submitted value is returned
- Else the bound property is returned (only in objectAccessor-mode)
- As fallback the "value" argument of this ViewHelper is used
Checks if a property mapping error has occurred in the last request.
Get the form data which has last been submitted; only returns valid data in case a property mapping error has occurred. Check with hasMappingErrorOccurred() before!
Add additional identity properties in case the current property is hierarchical (of the form "bla.blubb").
Get the current property of the object bound to this form.
Returns the "absolute" property path of the property bound to this ViewHelper.
Internal method which checks if we should evaluate a domain object or just output arguments['name'] and arguments['value']
Add an CSS class if this view helper has errors
Get errors for the property and form name of this view helper
Renders a hidden field with the same name as the element, to make sure the empty value is submitted in case nothing is selected. This is needed for checkbox and multiple select fields
Renders the upload field.
Returns a previously uploaded resource, or the resource specified via "value" argument if no resource has been uploaded before If errors occurred during property mapping for this property, NULL is returned
Details
void
setRenderingContext(RenderingContextInterface $renderingContext)
No description
void
injectObjectManager(ObjectManagerInterface $objectManager)
No description
void
injectLogger(LoggerInterface $logger)
Injects the (system) logger based on PSR-3.
bool
isEscapingInterceptorEnabled()
No description
__construct()
Constructor
void
injectTagBuilder(TagBuilder $tag)
No description
void
initialize()
Sets the tag name to $this->tagName.
Additionally, sets all tag attributes which were registered in $this->tagAttributes and additionalArguments.
Will be invoked just before the render method.
protected void
registerTagAttribute(string $name, string $type, string $description, bool $required = false, mixed $defaultValue = null)
Register a new tag attribute. Tag attributes are all arguments which will be directly appended to a tag if you call $this->initializeTag()
protected void
registerUniversalTagAttributes()
Registers all standard HTML universal attributes.
Should be used inside registerArguments();
void
handleAdditionalArguments(array $arguments)
Handles additional arguments, sorting out any data- prefixed tag attributes and assigning them. Then passes the unassigned arguments to the parent class' method, which in the default implementation will throw an error about "undeclared argument used".
void
injectPersistenceManager(PersistenceManagerInterface $persistenceManager)
Injects the Flow Persistence Manager
protected string
prefixFieldName(string $fieldName)
Prefixes / namespaces the given name with the form field prefix
protected string
renderHiddenIdentityField(object $object, string $name)
Renders a hidden form field containing the technical identity of the given object.
protected void
registerFieldNameForFormTokenGeneration(string $fieldName)
Register a field name for inclusion in the HMAC / Form Token generation
void
initializeArguments()
No description
protected string
getName()
Get the name of this form element.
Either returns arguments['name'], or the correct name for Object Access.
In case property is something like bla.blubb (hierarchical), then [bla][blubb] is generated.
protected ActionRequest
getRequest()
Shortcut for retrieving the request from the controller context
protected string
getNameWithoutPrefix()
Get the name of this form element, without prefix.
Note: This is overridden here because the "value" argument should not have an effect on the name attribute of the tag In the original implementation, setting a value will influence the name, @return string name
protected mixed
getValueAttribute(bool $ignoreSubmittedFormData = false)
Returns the current value of this Form ViewHelper and converts it to an identifier string in case it's an object The value is determined as follows:
- If property mapping errors occurred and the form is re-displayed, the last submitted value is returned
- Else the bound property is returned (only in objectAccessor-mode)
- As fallback the "value" argument of this ViewHelper is used
protected bool
hasMappingErrorOccurred()
Checks if a property mapping error has occurred in the last request.
protected mixed
getLastSubmittedFormData()
Get the form data which has last been submitted; only returns valid data in case a property mapping error has occurred. Check with hasMappingErrorOccurred() before!
protected void
addAdditionalIdentityPropertiesIfNeeded()
Add additional identity properties in case the current property is hierarchical (of the form "bla.blubb").
Then, [bla][__identity] has to be generated as well.
protected mixed
getPropertyValue()
Get the current property of the object bound to this form.
protected string
getPropertyPath()
Returns the "absolute" property path of the property bound to this ViewHelper.
For
protected bool
isObjectAccessorMode()
Internal method which checks if we should evaluate a domain object or just output arguments['name'] and arguments['value']
protected void
setErrorClassAttribute()
Add an CSS class if this view helper has errors
protected Result
getMappingResultsForProperty()
Get errors for the property and form name of this view helper
protected void
renderHiddenFieldForEmptyValue()
Renders a hidden field with the same name as the element, to make sure the empty value is submitted in case nothing is selected. This is needed for checkbox and multiple select fields
string
render()
Renders the upload field.
protected PersistentResource|null
getUploadedResource()
Returns a previously uploaded resource, or the resource specified via "value" argument if no resource has been uploaded before If errors occurred during property mapping for this property, NULL is returned