Can not output image title and description for TYPO3 extension DCE images - typo3

I created in TYPO3 extension DCE an image field that allows to input an image with caption and title field in the backend. But I couldn't access the value of these fields to input in the alt-tag in source. No values are shown by f:debug, how can I access these values and output?

The fastest solution would be having a look into the Class Reference of TYPO3\CMS\Core\Resource\FileReference. There are many getters for the properties. They access (and are allowed to access) the mergedProperties-array. In your special case getDescription() is, what you are looking for.
So for getting description a simple {field.imageDesktop.{i}.description} should work (if field.imageDesktop.{i} is a FileReference).

Related

TYPO3 - How to add a placeholder to an input field?

In TYPO3 (7.2.0) using the standard template engine, is there a way to add a placeholder attribute to the standard mail form text input?
At the moment I am using JavaScript to convert the labels into placeholders, but I am open to suggestions on a better way to do this...
The suggested solution of #biesior does only work for EXT:form 7.4 and higher (see changelog). The supplied picture shows the form wizard of TYPO3 7.5 or 7.6. In 7.2 you won't find any placeholder attribute in the wizard.
I recommend updating to TYPO3 7.6 since this version includes a major rewrite of EXT:form. You will be able to use fluid templates to customize your forms. Furthermore HTML5 attributes are possible. Before the rewrite the set of allowed attributes was quite limited. Now you are able to add all attributes you can think of (for example "data-"). See changelog.
If you have any questions regarding EXT:form join the channel on Slack. If you don't know Slack yet, check out the invite function.
During form fields editing you have many properties, also Placeholder
in text version it will be:
10 = TEXTLINE
10 {
type = text
class = foo-class
id = foo-id
name = foo
placeholder = Hmmm?
required = required
label {
value = My Field
}
}

Configure symfony2 automatic form label generation

I'd like to know if there is a way to configure, disable or otherwise override the way Symfony handles automatically generating form labels for entity properties.
We also use the Sonata Admin Bundle and Symfony native and Sonata do not always produce the same label for complex form fields based on a given entity property, specifically when adding related entity properties e.g. something.somethingRelated. Sometimes it seems there is an extra space added to the label string (where the "dot" is) so we end up with two different labels being generated for the exact same property in two different forms.
Sonata has a configuration that allows some control over how the label is generated; e.g underscores, native, do nothing, etc.
We are trying to get our translations under control but still use the automatic generation of form labels rather than having to add a label (key) to each form field.
Right now I think my best alternative is to just turn it off in Symfony and let the actual property name be the "string" that is generated without any processing on it. So, thisIsTheProperty would have an automatically generated label string "thisIsTheProperty", not "This Is The Property" or whatever.

Get the properties of reference pages - Kentico

I have a page where I need to display testimonials, In that page document type I have a field to assign testimonials by using page selection, so It will save the GUID of selected testimonial in the database,
I have used following code to display the description of Testimonial, But is there any other way to get the document fileds by passing the GUID,
One option I can use is write a custom macro.
{% Documents["/Page-Resource/Testimonial/Testimonial"].getValue("Description") #%}
Note: I have used the text/xml type transformation
Well it's not that easy but there is one way and that is to use loops:
r = ""; foreach (i in CMSContext.Current.Documents) {if(i.NodeGUID == "a88f82be-bb76-4b82-8faf-5253209f0f75"){r = i}}; r.Description
Notes:
Use NodeGUID or DocumentGUID based on what you store in your custom field.
Replace the hardcoded guid with something like CMSContext.Current.CurrentDocument.YourDescriptionFieldWithGuid
See the documentation if you have any doubts about K# syntax

Images in Extbase - Fluid

I have an standard image upload in TYPO3 Backend, that allows more than 1 image upload.
So I have an image database field with data like that: "image1.jpg,image2.jpg".
In Frontend, I can explode the field, send the array to fluid, and output it in a fluid:for each like that:
<f:image src="uploads/tx_myext/{image}" />
First question is: is there maybe some fancy new Extbase or Fluid Magic, that creates image objects right from database?
Second question: if I have a huge 2MB image and make a fluid:image output with width=100, is it just scaled in browser, or is it really downsized using ImageMagick?
Comma list to array:
Unfortunately as I can see in Extbase 4.7 there is still no ViewHelper for iterating comma separated strings. You have two options: write custom ViewHelper or stay with the way you are using.
TIP: To avoid passing additional params (especially when you have many comma separated fields there and/or using many Partials for rendering the view) I'm adding a public field to my model. Without representation in TCA it will be considered as transient, ie:
/**
* #var array
*/
public $imagesArray;
and then just filling it in controller right before assigning so I can access it as {project.imagesArray} in the view:
public function showAction(Tx_Myext_Domain_Model_Project $project) {
$project->imagesArray = explode(',', $project->getImage());
$this->view->assign('project', $project);
}
view
<f:for each="{project.imagesArray}" as="image">
<f:image src="uploads/tx_myext/{image}" width="200" height="200m" alt="" />
</f:for>
Most probably you are using quite similar approach...
Image resizing:
It's easiest just to ... check. ImageMagick hashes the name of the resized image and stores it in the temp folder by default, so if in code preview you see the path like: typo3temp/pics/cd27baa408.jpg instead of uploads/tx_myext/photo123.jpg that means it was converted with IM. And yes, image ViewHelper uses the IM.
You can even add perform simple calculations by giving value as width="200m" or width="200c" from viewhelper's phpdoc: See imgResource.width for possible options
Now I created a ViewHelper in Typo3 Forge as I think processing of images as they come from database would be quite usefull.
And I added imageLinkWrap for JS Window.
http://forge.typo3.org/issues/46218

Parsing comma separated string into multiple database entries (eg. Tags)

I want to create a Symfony 2 Form for a Blog Post. One of the fields that I am wondering how might I implement is the tags field. Post has a many-to-many relationship with Tag. I want my Form to have 1 text box where users enter in a comma separated list of tags. Which will then be converted into multiple Tag's.
How should I implement it? Do I:
Have a tagsInput field (named differently from in the Entity where $tags should be an ArrayCollection)
On POST, I split the tags and create/get multiple tags. Then validate the tags (eg. MaxLength of 32)
I think you are already on the right way since I saw your other question about the form type. I will just comfort you with your choice.
A form type is probably the best way to go. With the form type, you will be able to display a single text field in your form. You will also be able to transform the data into a string for display to the user and to an ArrayCollection to set it in your model. For this, you use a DataTransformer exactly as you are doing in your other question.
With this technique, you don't need an extra field tagsInput in your model, you can have only a single field named tags that will an ArrayCollection. Having one field is possible because the you form type will transform that data from a string to an ArrayCollection.
For the validation, I think you could use the Choice validator. This validator directive seems to be able to validate that an array does not have less than a number of item and not more than another number. You can check the documentation for it here. You would use it like this:
// src/Acme/BlogBundle/Entity/Author.php
use Symfony\Component\Validator\Constraints as Assert;
class Post
{
/**
* #Assert\Choice(min = 1, max = 32)
*/
protected $tags;
}
If it does not work or not as intended, what you could do is to create a custom validator. This validator will then be put in your model for the tags field. This validator would validate the an array have a maximum number of element no greater than a fixed number (32 in your case).
Hope this helps.
Regards,
Matt