Polylang: How does the linking of right page by changing the attribute "href" work? - polylang

I have a question about linking the right page with Polylang.
I have a hard-coded anchor, which is basically a “back home” link.
It looks like this:
<a href=“magazin” class=“article-type-inner”><?php pll_e(‘Close’); ?></a>
I have already implemented a string and it works fine in the posts in both languages, but how can I change the “Href” to the right language?
For example my default language is English and the other language is French. If I am on a french post I will return to the English page… Is there any solution?
Thank you.

Ideally you should not hardcode any strings or URL's, here is some options for you:
Use pll_home_url() if your intention is to redirect to the home page. pll_home_url() accepts optional parameter $slug (2-letters code of the language) to switch between languages if needed.
Use get_permalink(), the_permalink() or get_the_permalink(). You can pass page_id as first argument. Make sure post/pages/cpt's are linked properly. E.g. the_permalink(100).
Worst case scenario - use if/else in combination with pll_current_language(). Not recommended.

Related

How to work with the typo3 viewhelper documentation?

I found this example in the TYPO3 documentation:
<f:be.uri route="web_ts" parameters="{id: 92}"/>
Unfortunately the doc doesn't explain, what "route" is for.
"parameters" is for key-value-pairs (given to TYPO3 to work with), but unfortunately it isn't mentioned, how to add more than one and how they would become seperated.
Furthermore the doc is mentioning an argument "referenceType", which also isn't explained.
May I ask for some help/explanation for it?
Edit: The title of the question doesn't really reflect the nature of my question. stackoverflow wasn't allowing me to use a more precise one.
The documentation https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/BackendRouting/Index.html explains backend routes quite well.
Furthermore the backend module "Configuration" > Backend Routes lists all available routes.
The core itself is most of the time a good example how ViewHelpers can be used, so a random example which covers quite a lot is the following one
<a href="{f:be.uri(route:'site_redirects', parameters: '{action: \'overview\', demand: demand.parameters, page: 1}')}" title="{f:translate(extensionName: 'fluid', key:'widget.pagination.first')}">
<core:icon identifier="actions-view-paging-first" />
</a>
Checking the implementation, referenceType can either be url or absolute to change the type of urls generated. I don't see currently the need to set this, so I guess you won't need it as well.

CQ Dialog: Possible to provide placeholder in text?

We have a requirement wherein a section of a page will be part authorable and part dynamic. What I mean by this is "You have 6 visits left out of 16." The 6 and 16 in the sentence are coming from a REST service call but the text "You have...visits left out of.." has to be authorable through dialog. Also, we are using AEM 6.
Thanks in advance
Maybe this solution will help others looking for simple placeholder text for their dialog textfields (OP not so much). Use an emptyText attribute...
<dialogText fieldLabel="AEM CLassic UI Text" jcr:primaryType="cq:Widget"
name="./nameOfText" emptyText="THIS IS THE PLACEHOLDER" xtype="textfield"/>
Perhaps you can start by extending foundation/components/text, where the user would be expected to enter a valid formatable string (i.e. "You have %d visits left out of %d").
In your component you would be implementing text.jsp therefore overriding the default behavior of foundation/components/text, in which you can do something like
<cq:text property="text" escapeXml="true"
placeholder="<%= Placeholder.getDefaultPlaceholder(slingRequest, component, null)%>"
tagName="span"
tagClass="myformatedmessage" />
You use tagName and tagClass which will wind up putting the formattable text in a <span class="myformatedmessage">...</span>. Then use jQuery to find it and populate the format placeholders after getting the data via ajax. All that jQuery code you can probably put into a clientlib folder within the same component you extended.
Based on your description, I think you are looking for replacement or substitution instead of placeholders.
"placeholder" generally refers to display text inside a form input that is displayed until the user enters data in the field (such as hint data).
You generally have 3 options for replacing parts of the data:
Server-side (prevents page from being cacheable in dispatcher). Requires parsing authored content & replace some kind of tags with desired REST data, such as "You have ${x} visits left out of ${y} total". Other ways of "tagging" substitution data could look like "You have %x% visits left out of %y%"
client-side JavaScript DOM manipulation once REST data returns. ie $el.html(newDomContentString)
client-side JavaScript templates (handlebars, dust, etc). Takes more initial setup in JS, but generally scales better.

Alter input of form before it is submitted

I'm creating a multilingual Drupal site and trying to implement a search function, that only displays results in the current language, that the user is viewing the site through.
Using Drupals own searchfunction at /search/node it is possible to select which language to search for through the "Advanced search" options, and it works perfectly. However, I dont want to expose these language selectboxes, I just want it to only search in the current language automatically.
What's the best option to do this?
I have one solution where I create a hook_form_alter function, that sets the #default_value in the language selectboxes to the current language, and then I hide the whole "advanced options" with in css. This doesnt seem very right though.
I think the most clean solution would be to hook into Drupals form-processing process and append ex "language:en" to the input text, but I cannot get this to work.
Does anyone know if it is possible via one of the Drupal form related alter functions, to get a hold of the input text and alter it before drupal does its final processing of it?
To answer your question specifically, while using 'hook_form_alter', you have a referenced variable called '$form_state'. This stores the values in the form, and any change there will be passed further.
Also,
I think setting a default value and hiding the field is a good solution as any, only, if you are hiding it you should do it server side, while altering the form. The same field you are setting the default value to. like this:
$fieldname['#type'] = 'hidden'.

javascript in zend_Form_Element_Text

I have an autocompexion app. that works. Server side written in php (search.php)
. Client side in javascript (autocomplexion.js).
In a text field this helps to enter town name by giving towns names that starts with the same letters that are entered in the field.
search.php sort a list of towns in towns.txt and choose the ones that match.
autocomplexion.js helps to select among those proposed towns.
My issue :
In Zend i would use this in a form (zend_Form) in a text field created with Zend_Form_Element_Text.
How do i link this field with autocomplexion.js and search.php.
where do i put search.php and autocomplexion.js
Thanks for your answer
Patrick
Write the PHP search function in an Action in an appropriate controller. Point the JS to this action and I think you are done.

Zend Framework Filter Input StripTags and "<3"

I'm currently using Zend_Filter_StripTags in a commenting system, but stuff kinda breaks when '<3' is entered. StripTags doesn't seem to be smart enough to realize that it's not an HTML tag, and creating the filter as "new Zend_Filter_StripTags(array('3'))" doesn't seem to work either.
Should I pass the input through a regexp first, or is there a way to get Zend_Filter_StripTags to straighten up and fly right?
Ended up writing a Zend_Filter class that was basically a wrapper for HTMLPurifier. Works perfectly, because HTMLPurifier is a LOT smarter than striptags.
I'm not familiar with Zend much, but if you want stuff like <3 to be allowed, just do htmlspecialchars instead of strip_tags on it.
What you want is Zend_Filter_HtmlEntites most likely.
See: Zend_Filter_HtmlEnties
The problem with htmlspecialchars and Zend_Filter_HtmlEntities is that if you're trying to strip out all html tags ( like 'a' and 'img', etc ), then instead of stripping them, you end up with that markup in your output.
Take comments on a blog for example. If you use htmlspecialchars or Zend_Filter_HtmlEntities, in a comment where someone tries to use html to enter a link you end up with that markup showing up when you display the comment. But if you use strip_tags or Zend_Filter_StripTags you end up mangling the comment, as neither is smart enough to realize that '<3' isn't a tag, and just strips everything from '<3' until the end of the comment ( or until it finds '>' ).
It would be nice if Zend had something like HTMLPurifier, where it actually checks and validates the input before stripping tags. This means that stuff like '<3' gets left alone, where as stuff like 'Awesome Site' becomes 'Awesome Site'.
This is a problem I'm trying to work around, and at the moment it seems like I'm going to end up writing my own Zend_Filter class that's basically a wrapper for HTMLPurifier.