Typo3 Fluid detect Links in Text - hyperlink

This Code is showing a Textarea Input from the Backend in my Frontend:
<f:format.nl2br>{data.textfield}</f:format.nl2br>
Its possible there are Links in it as simple text for example:
http://www.example.com
Is it possible somehow to detect those links and wrap a linktag around it with Typo3 6 and Fluid?
Its rather easy in Javascript but if possible I prefer a Typo3/Fluid solution here.

why dont you use the RTE for your Textfield in the Backend and render it in Fluid with
<f:format.html>{data.textfield}</f:format.html>
If you do it like this, you have your line breaks rendered and all the Links, too. You enable the RTE features in your TCA-Configuration:
'textarea' => array(
'exclude' => 0,
'label' => 'your_label_from_locallang.xlf',
'config' => array(
'type' => 'text',
'cols' => 40,
'rows' => 15
),
'defaultExtras' => 'richtext[]'
),

Is the fluid used in context of an extension? If so make the check on php side and bind a boolean value to the view. You can then use something like this:
<f:if condition="isLink">
<f:then>
<f:link.external uri="{data.textfield}" target="_blank">{data.textfield}</f:link.external>
</f:then>
<f:else>
<f:format.nl2br>{data.textfield}</f:format.nl2br>
</f:else>
</f:if>
Unfortunately condition is very limited in what it can check on fluid side only so this won't help if you can't use php.
Another possibility would be to create a ViewHelper for that.

Related

ZF2 Form: How to provide field hints

I've been learning how to use ZF2 from the book Learn ZF2: Learning by Example by Slavey Karadzhov. In it, he shows how to build forms using annotations. One particularly helpful feature is the "pattern" attribute. If you add a pattern to the form, there's a really cool JavaScript function that checks does client-side validation. If a field's input doesn't match the desired pattern, a groovy little tooltip of sorts pops up pointing out the field(s) that have problems and telling you what needs to be fixed.
I was wondering: is there a similar system in ZF2 so that, when a field is highlighted, a similar tooltip pops up to give hints on what exactly needs to be entered into a field? For example, for a password field it could give the requirements for the password. And if this isn't built in, is there a module out there somewhere that does this? I've done a bunch of Googling on this subject, but I've come up empty so far.
Since zf2 come's with an Twitter Bootstrap implementation you could just use the Tooltip functionality.
I personally do not use anotation's in my forms for various reasons, one being the performance hit you take.
within your YourForm.php just set some data attributes and you should be good to go:
$this->add(array(
'name' => 'submit',
'type' => 'Submit',
'attributes' => array(
'value' => 'Save',
'id' => 'submitbutton',
'data-toggle' => 'tooltip',
'data-placement' => 'left',
'title' => 'Press me I am a button :D',
),
));
The annotation equivalent would be:
* #Annotation\Attributes({"data-toggle":"tooltip", "data-placement":"left", "title":"Press me I am a button :D"})
don't forget to initialize
$(function () {
$('[data-toggle="tooltip"]').tooltip();
})

Translate Form Error Messages

I've been using ZF2 since alpha so I'm not entirely new. However not to disturb my current project I setup a new SkeletonApp and it's working. I've added my Translations I needed for both English and German and they are working as expected. However, the Form Error Messages are not being translated to German, or any other language.
I've read the manual but it only covers how to setup Translations based on Factories and it has no details regarding how to set up inside of the module.config.php. Just like in ZF1, ZF2 also have a resources/languages folder which contains all the Form Validation Error Messages already translated. I'd like to use those! And this is where my problem is. I have no idea how to add the configuration to make this work with all my forms.
In my module.config.php file based on the SkeletonApp it already had support for translations, so I took that configuration and added another array, assuming this would have worked.
'translator' => array(
'locale' => 'en_US',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo'
),
array(
'type' => 'phparray',
'base_dir' => __DIR__ . '/../resources/languages',
'pattern' => '%s.php'
)
)
),
However to no avail has this worked. In my Controller I have an eventManager which is where I set my locale like this:
$self->getServiceLocator()->get('translator')->setLocale('en_US'); // change to de_DE for German
Doing this as I mentioned above does translate my text from English to German and so on.
What am I missing to make my Form Errors Translate? Thank you for any guidance you can share on this situation.
Both sources use the same text domain, with the gettext source having the higher priority. This means that it will load your locale from the gettext source and then stop, since the locale + text domain combination is already loaded.
Solution: Use different text domains for each source.

Setting hint text in a text field in Ruby on Rails

Can some one suggest the best way for setting hint text(not default text) for a text field in Ruby on Rails. Currently I am using this:
<%= text_field_with_auto_complete
"customer",
:contact_person, {
:value => 'last, first',
:style => 'color:#aaa;width:11em;',
:onfocus => "if(this.getValue()=='last, first'){this.clear();this.style.color = '#000';}",
:onblur => "if(this.getValue()==''){this.setValue('last, first');this.style.color = #aaa';}"
} %>
The text field is attached to a model and in turn to a value in a database. Also, the same html that is used in index.html is also used in edit.html and hence when I try to edit the field, the default value shows up instead of the value from the database. What is the correct way to do this?
Note: I am not trying to set a default value but just a hint to what needs to be entered in the text box.
Thanks,
Raja Ram
I'd recommend using the HTML 5 placeholder attribute, and then using a jQuery plugin to make it work on older browsers (like this one, but there are many others on Google).
You can see this technique used in production here.
Try this jquery plugin
http://plugins.jquery.com/project/hint
or choose here:
http://plugins.jquery.com/plugin-tags/hint
For prototype
http://davidchambersdesign.com/autopopulating-input-fields-with-prototype/

Is it possible to drag and drop an element from a different page to a Droppable?

I am trying to get the following requirement to work. I have a test page that has a Droppable area.
<%= drop_receiving_element(
"basket",
:onDrop => "function(element) { alert(element) }",
:url => { :action => "create" }
)%>
What I want to achieve, is to be able to drop any links from another browser tab/window onto the Droppable and record that link. Bear in mind that these links will be arbitrary and out of my control so I can't decorate them as Draggable. Is this achievable or am I barking up the wrong tree?
TIA
Not possible I'm afraid. Two browsers = two doms. Maybe possible with google gears, silverlight, and java but not js.
http://www.w3schools.com/htmldom/default.asp

How to extend page module in contao?

I want to insert image in page module. Anybody have idea how to extend page in contao ?
See screen for more clarification.
http://screencast.com/t/JXk5thjlvHv
See attached screen .. my idea is like this.
You could do that by giving the pages specific CSS classes in their settings. This CSS class will also be used in the regular navigation modules. This way you can define the page's icon in your own stylesheets.
That actually depends how much you want to do.. the easy way: define classes... But thats not the most flexible one.
Lets say you have a custom icon font. Or maybe just FontAwesome. And you want to use these Icons to be shown. In this case, I would install the IconPicker Module by Rocksolid and write a custom module:
/system/modules/z-customs/dca/tl_page.php
$GLOBALS['TL_LANG']['tl_page']['icon']=array('Pageicon', 'Set an Icon for the Page');
$GLOBALS['TL_DCA']['tl_page']['fields']['icon'] = array(
'label' => &$GLOBALS['TL_LANG']['tl_page']['icon'],
'exclude' => true,
'inputType' => 'rocksolid_icon_picker',
'eval' => array(
'fieldType'=>'radio',
'tl_class'=>'w100 clr',
'iconFont' => 'files/fonts/fontawesome-webfont.svg',
),
'sql' => "varchar(100) NOT NULL default ''",
);
/templates/nav_default.html5
<?php if($item['icon']): ?>data-icon="&#x<?= $item['icon']; ?>"<?php endif; ?>
This part can be added to the <li> or the <strong> or a. You may also add a class to the element, to make sure only the elements that have an Icon get the appropriate style.
To get the Icon into the CSS you would just do something like this:
a:before {
content: attr(data-icon);
font-family: "FontAwesome";
}

Resources