Symfony router with translated urls - annotations

I trying to build an router in Symfony with annotation where also the urls are translated. I would like to have all the following urls routed to the same controller:
/over-ons
/nl/over-ons
/en/about-us
I use the following annotation router:
/**
* #Route("/{_locale}/over-ons", defaults={"_locale": "nl|en"}, requirements={"_locale": "nl"}, name="about-us")
* #Route("/{_locale}/about-us", defaults={"_locale": "nl|en"}, requirements={"_locale": "en"}, name="about-us")
*/
But when I generate via path an url in Twig always the last #route is used instead of the one of the correct set _locate. Any advice would be helpful?
Would it also by wise from SEO poiunt of view to support .html behinde the urls?

If you're adding those 2 annotations on the same controller method, then of course only the last one is used because it overrides all the previous ones.
If you want good and solid internationalization support, I recommend using JMSI18nRoutingBundle.

Related

How to translate the URL with router enhancer

I have a customized extbase extension, which shows different contents based on the parameter.
class SiteController extends ActionController {
/**
* #param int $year
*/
protected function newsAction(int $year) {
......
}
}
And here is my routeEnhancers in the config.yaml.
routeEnhancers:
News:
type: Extbase
limitToPages: [6]
extension: Site
plugin: Pi1
routes:
- routePath: '/{year}',
_controller: 'Site:news'
However, it doesn't convert the URL http://landing.io/news?tx_site_pi1[year]=2018&cHash=f1a79b262f6567570dd78b6148b17554 to http://landing.io/news/2018, but I can visit http://landing.io/news/2018?cHash=f1a79b262f6567570dd78b6148b17554. So, I guess I missed something.
Could anyone help?
First of all, fix a typo in the config.yaml, it should be Site::news instead of Site:news.
After some debug, I finally solved this question.
According to the Routing Enhancers and Aspects, it's said
When creating extbase plugins, it is very common to have multiple controller/action combinations. The Extbase Plugin Enhancer is therefore an extension to the regular Plugin Enhancer, providing the functionality that multiple variants are generated, typically built on the amount of controller/action pairs.
in the Extbase Plugin Enhancer section.
However, if you want to have the extbase routing enhancers to work, you MUST have &tx_ext_pi1[controller]=CONTROLLER&tx_ext_pi1[action]=ACTION in your URLs, which is all the URLs do in the section but I didn't realize. Otherwise, you will get FALSE in \TYPO3\CMS\Extbase\Routing\ExtbasePluginEnhancer::verifyRequiredParameters() and never get your URLs translated. So, I think this point should be included in the doc, or at least highlight the last sentence starting from "typically".
Meanwhile, there is also a TypoScript setting in the EXT:extbase, called config.tx_extbase.features.skipDefaultArguments or plugin.tx_ext.features.skipDefaultArguments, which will remove the controller and/or action arguments if they are equal to the default controller/action of the target plugin. If it's enabled, it will also break the routing enhancers for the same reason. Unfortunately, I enabled this since very beginning to make the URLs short.
There is another setting, config.tx_extbase.mvc.callDefaultActionIfActionCantBeResolved, you may need to be care about, which might cause the same problem.
Anyway, the new routing feature is pretty great.

TYPO3 8, Form extension - best practice for custom yaml files

When generating forms with the form module the corresponding yaml files get stored in fileadmin/user_upload.
Now I want to integrate those yaml files into my sitepackage and thus into my CVS. Where is the correct place for them? In the example extension they are stored in Resources/... while I would think they have to go into Configuration/Yaml
And how do I configure the form extension to search them in that place?
While it's basically a matter of taste where exactly one saves his form definitions, I try to separate form configuration and form definitions.
From the official documentation:
[...] the form configuration allows you to define:
which form elements, finishers, and validators are available,
how those objects are pre-configured,
how those objects will be displayed within the frontend and backend.
In contrast, the form definition describes the specific form,
including
all form elements and their corresponding validators,
the order of the form elements within the form, and
the finishers which are fired as soon as the form has been submitted.
Furthermore, it defines the concrete values of each property of the mentioned aspects.
So, for more clarity I save all form configuration in a sitepackage under Configuration/Yaml/ and the form definitions under Resources/Private/Forms, neighbouring the templates.
I wrote a full tutorial how to use custom templates with EXT:form, which also includes the answers to your question.
In short:
Register YAML configuration with TypoScript in your extension root folder as ext_typoscript_setup.txt (as recommended1)
plugin.tx_form.settings.yamlConfigurations {
100 = EXT:my_extension/Configuration/Yaml/CustomFormSetup.yaml
}
module.tx_form.settings.yamlConfigurations {
100 = EXT:my_extension/Configuration/Yaml/CustomFormSetup.yaml
}
CustomFormSetup.yaml – setting up a new storage path
TYPO3:
CMS:
Form:
persistenceManager:
allowedExtensionPaths:
10: EXT:my_extension/Resources/Private/Forms/
allowSaveToExtensionPaths: true
allowDeleteFromExtensionPaths: true
1TypoScript inside an ext_typoscript_setup.txt is automatically loaded in both frontend and backend of your TYPO3 installation directly after installing your extension. This differs from other TypoScript files, which have to be included manually, e.g. as static templates. See official Form Framework documentation.
I'd suggest Resources/Private/Forms for your form definitions. The form extension clarifies how to register additional form definition paths.

Joomla: how can I use one form for frontend and backend view?

I am creating a Joomla 2.5 component. In the backend I created a model/view/controller 'Members' which shows a grid. I also created an MVC 'Member' which is used to add or edit a member from the grid. So far so good.
Now, I would like to add a frontend view that is very similar to the 'Member' view in the backend, but this one is meant for visitors so they can subscribe themselves. It has to look more user friendly than the backend form, so I will create a slightly different 'Member' view in the frontend, but I would really like to reuse the form file (/administrator/components/mycomponent/models/forms/member.xml) from the backend!
So, my question is how my frontend view can find and use that backend form?
You definitely have to load it in the model. Your model has to extend JModelAdmin and then the getForm function has to load the form
public function getForm($data = array(), $loadData = true) {
// Get the form.
JForm::addFormPath(JPATH_COMPONENT_ADMINISTRATOR . '/models/forms');
JForm::addFieldPath(JPATH_COMPONENT_ADMINISTRATOR . '/models/fields');
$form = $this->loadForm('com_dpattachments.attachment', 'attachment', array('control' => 'jform', 'load_data' => $loadData));
if (empty($form)) {
return false;
}
....
}
I'm using the same approach in my DPAttachments component, it is for Joomla 3.1 but the main code, to use the same model and form on the front and back, should also run on Joomla 2.5. Here is the link to the getForm function
https://github.com/Digital-Peak/DPAttachments/blob/master/com_dpattachments/admin/models/attachment.php#L102
If you are following Joomla MVC guidance your frontend should be able to pick-up the forms automatically.
In your view (though it should request it from the model actually) you can write:
$formsPath = JPATH_ADMINISTRATOR.DS.'components'.DS.'com_mycom'.DS.'models'.DS.'forms';
$this->form = JForm::getInstance('myform', $formsPath.DS.'myform.xml');
You can also look at the summer of code cm_config project which pulls the config forms and the templateDetails form to the front end using JSON. https://github.com/Buddhima/joomla-cms/tree/gsoc_com_config or the com_services branch.

How do i add a custom made TinyMCE form element to my Zend Project?

I have been working with Zend for a few months now and am at a stage where i'd like to add some fields to my form using TinyMce. What i want to achieve is to be able to just create a form extending Zend_form and just be able to say
$element = new TinyMce_Form_Element_Editor('element');
But i just do not have a single clue on how to achieve this. I have of course been looking around before asking this question and most sources just point me towards this site.
Wich seems to be aimed at people with alot of experiance with Zend. 2 months in it's not a big surprise i am not at the level this might have been intended for as i have tried following the instrucutions given and creating the file setup as shown by in the svn repositiry create by the writer of this article.
Aside from heading from one error into another i also do not uderstand what the code is doing exactly, i just have a vague guess at best when i run trough it.
Is there any kind of easy to follow simple tutorial explaining how to enable tinymce in a Zend Form?
Any advice or tips on how to achieve my goal will be well appreciated
Not best solution but you may find it useful:
class My_Form_Element_Tinymce extends Zend_Form_Element_Textarea
{
/**
* Element CSS class name
* #var string
*/
protected $class = 'tinyMCE';
public function init()
{
$this->getView()->headScript()->appendFile('path/to/tinymce.js');
$this->getView()->headScript()->appendFile('path/to/tinymce_config.js');
}
}
and in your tinymce_config.js add selector for tinyMCE class name
tinymce_config.js is your tinyMCE configuration file if you never used tinyMCE goto http://tinymce.com and you will find many examples with what you need.

Symfony 1.4 - are forms always in <table>?

I'm using sfDoctrineAllowPlugin. I need form which has Twitter's Bootstrap semantics. I looked into template and I found, that there is only $form, which is a <table>. How can I format it in my way? I don't want to use table, rows and cols.
There are plenty of render* functions available to display each item in your form.
renderRow
renderLabel
render
renderError
etc ...
But you can also define a decorator (a custom sfWidgetFormSchemaFormatter) for your form to define the way each item will be display. Check this example of adding * for each required field.