I have a problem with a symfony form and a date field. When I view the field, the value retrieved from the database is subtracted a day when it is rendered as a widget single_text and I can not fix it.
For the project I use Symfony 2.6Beta for Bootstrap form support.
The field in form is defined:
$builder->add('natoIl', 'birthday', array(
'widget' => 'single_text',
'empty_value' => '',
'format' => 'dd/MM/yyyy',
'model_timezone' => 'Europe/Rome',
'view_timezone' => 'Europe/Rome'
));
I have this problem with MySQL and PostgreSQL.
Thank you very much
EDIT:
The problem occurs only with the 'widget' option set to "single_text". I need to see it as text input to add a datepicker field.
EDIT #2:
Doing various tests I found that the problem is when I work with the PHP web server. PHP version I use is 5.5.9-1ubuntu4.5 PC with linux mint.
Possibly you need to set your view and/or model timezone appropriately:
http://symfony.com/doc/current/reference/forms/types/date.html#view-timezone
This is a bug already fixed. The solution is then upgrading symfony.
https://github.com/symfony/symfony/issues/12808
Related
I have a MediaWiki 1.33.0 website with only one extension → ContactPage, with which I can have a simple contact form.
Using HTMLForms template engine (in which the default form-template for ContactPage is written), I have expanded the default form to include a selection menu.
My problem
Selection list array keys and values of this selection menu are written in English inside LocalSettings.php but my site isn't primarily in the LTR English, rather, it is in the RTL Hebrew and I would like them to appear in my site's native language for end users.
My own code pattern
wfLoadExtension( 'ContactPage' );
$wgContactConfig['default'] = array(
'RecipientUser' => 'Admin', // Must be the name of a valid account which also has a verified e-mail-address added to it.
'SenderName' => 'Contact Form on ' . $wgSitename, // "Contact Form on" needs to be translated
'SenderEmail' => null, // Defaults to $wgPasswordSender, may be changed as required
'RequireDetails' => true, // Either "true" or "false" as required
'IncludeIP' => false, // Either "true" or "false" as required
'MustBeLoggedIn' => false, // Check if the user is logged in before rendering the form
'AdditionalFields' => array(
'omgaselectbox' => [
'class' => 'HTMLSelectField',
'label' => 'Select an option',
'options' => [
'X' => 'X',
'Y' => 'Y',
'Z' => 'Z',
],
],
),
// Added in MW 1.26
'DisplayFormat' => 'table', // See HTMLForm documentation for available values.
'RLModules' => array(), // Resource loader modules to add to the form display page.
'RLStyleModules' => array(), // Resource loader CSS modules to add to the form display page.
);
possible solutions
1) Writing selection list array keys and values in Hebrew (which might be a bit messy due to LTR-RTL clashings):
'options' => [
'ס' => 'ס',
'ט' => 'ט',
'ז' => 'ז',
],
2) Translating English selection list array keys and values in client side JavaScript by some similar code:
document.getElementById('select').selectedIndex = 0;
document.getElementById('select').value = 'Default';
My desire
I desire an ordinal backend way to do so, and if there is one, than without an extension
In this discussion, a MediaWiki community member recommended using system message transclution but the chapter dealing with it was very unclear to me; I didn't understand what this is about and how can this help in my situation.
My question
What are the possible ways to translate in MediaWiki from "backend", without an extension?
The localisation system is working perfectly fine in the backend (php), as well in the frontend (JavaScript) parts of MediaWiki → staying with it backend is best as it is more minimal.
Assuming you take a backend only approach:
Translation with a predefined string
If your desired translations already exist in MediaWiki (e.g. on another page of form), you can "simply" re-use the key. So, let's assume, your current additional select field definition looks like this:
'Select' => [
'type' => 'select',
'options' => [
'The english message' => 'value'
]
],
Then, you would change it to something like this:
'Select' => [
'type' => 'select',
'options-messages' => [
'the-message-key' => 'test'
]
],
Please consider the changing of options into the options-messages key.
Also: Change the key the-message-key to the message key you want to reuse.
If you know a page where the message/string is used, you can just open that page with the GET option uselang and the value qqx, in order to see the message key. Example: If the string is used on the login page, simply open the login page with https://example.com/wiki/Special:Userlogin?uselang=qqx to show all the message keys used on the page.
However, one warning when doing that: It is mostly discouraged to re-use existing message keys, especially when they're used on other pages. The keys are translated to hundreds of languages with that specific context in mind. That could also mean, that a translation in a specific language does not fit when the string/message is used on the contact page. So I would suggest to use the second option below.
Translation without a predefined string
Usually it will be done by extension which can provide a specific directory where the JSON files with the message key translations are saved. However, as you're "just" customizing an extension, you need a way to put in the translations for your keys.
So, first of all, let's take over the changes from above. Change your select field definition to be something like:
'Select' => [
'type' => 'select',
'options-messages' => [
'my-fancy-key' => 'test'
]
],
Now, two ways to get the key translated:
On-Wiki
By saving the message on-wiki, the messages can also easily being changed simply by editing the respective page in the wiki. In our example, let's translate the key to english and hebrew:
English: Edit the page MediaWiki:My-fancy-key in your wiki and add the desired text.
Hebrew: Edit the page MediaWiki:My-fancy-key/he in your wiki and add the desired text.
As part of the deployed code
We need to register a directory with JSON files for the translations of these messages. We're using the same configuration variable as extensions would use as well, $wgMessagesDirs, even given that we don't create an extension. Add the following line to your LocalSettings.php:
$wgMessagesDirs['ContactPageCustomization'] = __DIR__ . '/customContactPage';
Now, create a directory customContactPage in the root folder of your MediaWiki installation and put in the following file with the following contents:
en.json
{
"my-fancy-key": "Default"
}
If you want to translate to another language, create a new file with the language code you want to translate to. In hebrew it should be he, so let's create a new language file:
he.json
{
"my-fancy-key": "ברירת מחדל"
}
If you then open the contact page, the message key my-fancy-key should be translated to the english Default and the same (at least based on Google Translate) for hebrew. This is a more stable way of adding custom translations, however, you now also need to take care of translating the keys into the languages you want to support on your own as well. If a key is not translated into the selected language of the user, the default language, english, is used.
I have to display some special information when my mouse is over a concrete point in a chart that is provided by Highcharts. I am using the Highcharts extension for Yii2.
My Code
'tooltip' => [
'enabled' => true,
'footerFormat' => true,
'formatter' => "js:function() {
return 'my special information';
}"
],
The data that comes from controller is correct.
However there is nothing different - tooltip is still the default
What am I doing wrong?
Sorry. My bad. All is working fine. I just duplicate 'tooltip' option. And my tooltip that i want to use was override by tooltip that i forgot to remove from my code)
I'm working on SF2 2.6.4 project.
I created a form and added a date type component (birthday field type to be precise).
I set it like that :
'widget' => 'choice',
'format' => 'ddMMMMyyyy',
Format output
18 March 2015
I would like to translate month.
During my research, I saw that Symfony\Component\Form\Extension\Core\Type\DateType class set a formatter with the hardcoded \Locale::getDefault() variable system.
So is there a way to do what I want ?
Is it a better idea to change my date format ?
Thx
Normally if you have your intl enabled in php (phpinfo) the form translate the months according to your locale configuration try setting locale like this before your form creation :
setlocale(LC_TIME, "fr_FR");
Another alternative if this doesn't help is this :
http://sonata-project.org/bundles/intl/master/doc/reference/datetime.html you can use the datetime helper
Im a TOTAL newbie to drupal development so please help me here, ok i have created a custom module which so far creates a custom database how do i go about creating a list page in the backend that i can use to manage each item in the DB and how do i go about creating a custom edit form to manage the insert/ edit / delete of each item
function rollover_res_schema() {
$rollover_res = array();
$rollover_res['rollover_res'] = array(
// Example (partial) specification for table "node".
'description' => 'Positioning for rollovers',
'fields' => array(
'rollover_res_id' => array(
'description' => 'The primary identifier for a node.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'rollover_res_actual' => array(
'description' => 'The main rollover plain text.',
'type' => 'text',
'length' => 255,
'not null' => TRUE,
),
),
'indexes' => array(
'rollover_res_id' => array('rollover_res_id'),
),
'primary key' => array('rollover_res_id'),
);
return $rollover_res;
}
If you're a total newbie to Drupal development you should not be writing ANY code for the first month or two and you shouldn't do custom database code the first 6 months.
Start with learning about Fields and Views and once you grasp these you can add one of Display Suite, Context or Panels.
The key to learning how to do things in drupal is:
1) google search how
2) see how other modules do it. In this case, look at some core modules, such as the block module. In there you'll see the schema in .install, and you'll see some functions that create forms for saving new blocks, such as block_add_block_form. You'll need to read up on the form API. But basically, you'll create a form hook to display a form, a menu hook to create a page to hold the form, and a hook to submit the form. If you grep through your code base, you'll see many of examples that you can copy. In fact, there are drupal example modules you can download that cover most of the basics: https://www.drupal.org/project/examples
But to learn how to interact with the database, you could find a module that does something similar to what you're doing and look at how it uses hook_menu to set up page callbacks, forms for editing data.
I'm trying to run this code:
if(!$this->isChild()) {
$formMapper->add('post', 'sonata_type_model', array(), array('edit' => 'list'));
From this tutorial: http://sonata-project.org/bundles/doctrine-orm-admin/2-1/doc/tutorial/creating_your_first_admin_class/defining_admin_class.html
I'm aware that you have to use sonata_type_model_list as of 2.1
sonata_type_model_list : this type replaces the option edit = list provided as a 4th argument on the sonata_type_model
The problem is that I have absolutely no idea how to do that. I have found ZERO examples anywhere after a whole day of google searches. All I want to do is replace the edit=>list with sonata_type_model_list.
Can you please tell me how to do that in the code above?
This is how I used it in my code. However it's not working in all browsers. When I select the taget entity the form value in the parent view doesn't get updated (FireFox and IE).
$formMapper->
...
->add('image', 'sonata_type_model_list',
array(
'compound' => true,
'by_reference' => true
)
)
...
I also find it very hard to find some tutorials/examples on how to use this type. Best thing you can do is to go through their source code. Which is awful time consuming.
One way I found out how to configure these form types is to provide a wrong argument.
e.g. 'my_compound' => true,
This will result in an error telling you that 'my_compound' isn't a valid parameter and also will show you a list of valid parameters.
Hope this helps!