Sonata Admin datetime picker returns wrong time - symfony

I'm new in Symfony, so excuse my ignorance.
I try to edit date and time of some event using Sonata Admin and 'sonata_type_datetime_picker' field type.
But sonata_type_datetime_picker return wrong time. It gives time for an hour less.
Here's a filled form field screenshot (time is 10:00):
Here's dump of form field value (time is 09:00):
Here's form field options:
->add('datebegin', 'sonata_type_datetime_picker', array(
'format' => 'dd.MM.yyyy HH:mm',
'label' => 'Event begins at...',
'dp_use_current' => false,
'model_timezone' => 'Europe/Moscow'
))
I'd like to note that this error exists only on the server. On my local machine everything is ok.
What could it be?
Thanks a lot in advance!

I've got this problem too. I think that you need to upgrade the software on your server (packet: tzdata etc).
See: https://en.wikipedia.org/wiki/Moscow_Time
If this doesn't help you, you can use this hack:
'view_timezone' => 'Europe/Minsk'
See:
https://en.wikipedia.org/wiki/Time_zone
https://en.wikipedia.org/wiki/UTC%2B03:00
https://en.wikipedia.org/wiki/Minsk (UTC+3)
For example:
->add('endTimestamp', 'sonata_type_datetime_picker', array(
'widget' => 'single_text',
'label' => 'sip_event_end_timestamp',
'dp_side_by_side' => true,
'dp_use_seconds' => false,
'model_timezone' => 'Europe/Moscow',
'view_timezone' => 'Europe/Minsk',
'format' => 'dd.MM.yyyy HH:mm'
)
)

Related

How to create table using .install file in Drupal 7

I am new to drupal, working on custom module, here is my .install file code, but its not creating table in database when I install module. can anyone please tell me where I am wrong
<?php
function make_application_schema()
{
$schema['make_master'] = array(
'description' => 'Make master table',
'fields' => array(
'make_id' => array(
'description' => 'make id primary key auto increment',
'type' => 'serial',
'not null' => TRUE,
),
'make_name' => array(
'description' => 'Make name',
'type' => 'varchar',
'length' => '100',
'not null' => TRUE,
),
'make_status' => array(
'description' => 'check make status',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
),
),
'primary key' => array('make_id'),
);
return $schema;
}
function make_application_install()
{
}
function make_application_uninstall()
{
}
What is the name of your module? When you are installing and you use hook_schema, you should name your function like this:
my_module.module
In my_module.install
function my_module_schema () ....
And... after that, this should be work :)
In order to install your database 'make_master' you have to call drupal_install_schema with your module name:
drupal_install_schema('make_application');
according to your question I think you have forgot to call drupal_install_schema function. Here are updated make_application_install and make_application_uninstall of your make_application.install.
function make_application_install() {
// Use schema API to create database table.
drupal_install_schema('make_master');
}
function make_application_uninstall() {
// Remove tables.
drupal_uninstall_schema('make_master');
}
NOTE
The tables won't install on module enable, they will only install on first-time install. First, disable the module, then click the 'uninstall' tab, select the module, and uninstall it (note: if your module doesn't have a hook_uninstall() function, it won't appear here - make sure you have added this function). Then, click the list tab, and re-enable your module. This is a first-time install, and the tables will install.
Either that or use the devel module, enable the development block and then use the 'reinstall modules' link in the block.
You can refer this link for more info : https://www.drupal.org/node/811594

How to disable HTML escaping of labels in KnpMenuBundle

I want to render an HTML label like:
$menu->addChild('Dashboard', array(
'route' => 'dashboard',
'label' => '<i class="fa-icon-bar-chart"></i><span class="hidden-tablet"> Dashboard</span></a>',
'extra' => array('safe_label' => true)
)
);
And I've pass the proper option while rendering:
{{ knp_menu_render('WshCmsHtmlBundle:Builder:mainMenu', {'allow_safe_labels': true} ) }}
But my label is still being escaped. What am I doing wrong?
Ok, the answer is!
You set up extra items on menu item not by 'extra' key but by 'extras' key.
So when you setup the item like this:
$menu->addChild('Dashboard', array(
'route' => 'dashboard',
'label' => '<i class="fa-icon-bar-chart"></i><span class="hidden-tablet"> Dashboard</span></a>',
'extras' => array('safe_label' => true)
)
);
it works fine!
There's two steps to achieve this.
1. MenuBuilder
You have to set safe_label to true in extras. Note that you can now write HTML in your label.
$menu->addChild('Home<i><b></b></i>', array(
'route' => 'homepage',
'extras' => array(
'safe_label' => true
),
));
2. Twig
You have to filter the output of knp_menu_render() so that it prints raw HTML (see documentation).
{{ knp_menu_render('main', {'allow_safe_labels': true}) | raw }}
Warning
Please be aware that this may be dangerous. From the documentation:
Use it with caution as it can create some XSS holes in your application if the label is coming from the user.
I used FyodorX's method to add a strong tag. It works like a charm but I must say that the raw filter is not necessary

How can I add subtitles to movie using flowplayer module?

I'm using flowplayer module to play videos on my site. I would like to add sutitles to some of the movies. How can I do it in Drupal?
I tried to add them like this:
$flowplayer = array(
'clip' => array(
'url' => str_replace('sites/default/files/videos', 'http://www.mysite.com/sites/default/files/videos', $node->field_video[0]['filepath']),
'captionURL' => str_replace('sites/default/files/videos', 'http://www.mysite.com/sites/default/files/videos', $node->field_caption[0]['filepath'])
),
....
Then the output is:
<param value="config={"clip":{"url":"http://www.mysite.com/sites/default/files/videos/video.flv","captionURL":"http://www.mysite.com/sites/default/files/videos/subtitles.srt","scaling":"fit"},...
However it says no stream found. When I erase "clip", the video is found.But how can I add subtitles?
I wonder if I need some plugin or what is wrong in my code?
Thanks.
Are you going to have more than one video? You might try using the playlist param which has support for titles. I'm not sure how you would display them (i'm doing something very similar at the moment, hopefully this is helpful). I'm using the Flowplayer API module but the js syntax should be similar.
$player = theme('flowplayer',array(
'clip' => array(
'duration' => 5,
'autoPlay' => true
),
'playlist' => array(
array('url' =>'http://localhost/episode_18.mp4','title' => 'Episode 18'),
array('url' =>'http://localhost/episode_19.mp4','title' => 'Episode 19'),
array('url' =>'http://localhost/6.jpg','title' => 'Image')
),
'plugins' => array(
'controls' => array(
'playlist' => true
)
)
)
);
return $player;

Weird problem with hook_view drupal

I'm having a weird problem with hook_view. The problem is, hook_view isn't invoked unless hook_load returns invalid value such as empty variable. I don't know what causes this to happen and I'm at my wit's end. I'm very much appreciate your help. For what is worth, I have image attach module installed.
Drupal 6.x
UPDATE
function mymodule_node_info(){
return array(
'nodetype1' => array(
'name' => t('nodetype1'),
'module' => 'mymodule_nodetype1',
'description' => t('....'),
'has_title' => TRUE,
'title_label' => t('Title'),
'has_body' => TRUE,
'body_label' => t('Body'),
),
'nodetype2' => array(
......
'module' => 'mymodule_nodetype2',
......
),
'nodetype3' => array(
......
'module' => 'mymodule_nodetype3',
......
),
'nodetype4' => array(
......
'module' => 'mymodule_nodetype4',
.......
),
);
}
function mymodule_nodetype1_load($node){
$query = 'SELECT f1,f2,...,f10 FROM {tb1} INNER JOIN {tb2} ON {tb1}.vid = {tb2}.vid WHERE {tb1}.vid = %d';
$result = db_query($query,$node->vid);
return db_fetch_object($result);
}
function mymodule_nodetype1_view($node, $teaser = FALSE, $page = FALSE){
$node = node_prepare($node, $teaser); // get it ready for display
$f1 = check_markup($node->f1);
..............
$f10 = check_markup($node->f10);
// Add theme stuff here
$node->content['mycontent'] = array(
'#value' => theme('defaultskin', $f1,...,$f10),
'#weight' => 1,
);
return $node;
}
function mymodule_theme(){
return array(
'defaultskin' => array(
'template' => 'node-defaultskin',
'arguments' => array(
'f1' => NULL,
......
'f10' => NULL,
),
),
);
}
I found the culprit. Just in case somebody run into same problem I did, here's why - I named one field as "TYPE" and, when I retrieved recordset inside hook_load with drupal_fetch_object, I believe, the resulted object's member name "type" might have caused some naming conflict with drupal core member. As a result, this causes it to not invoke hook_view. After I renamed my field to something different, it works like charm. So, never name field as "Type". You guys might have knew that too but, due to my intention to make code easier to read, I renamed those fields to much simpler ones (f1,...f10). Sorry for the trouble. And thanks everyone for your effort.
cheers
This hook is meant for usage in a node module(so a module that itself creates a new node type), I assume you're using it for nodes defined by Drupal or CKK or another module, if so, use hook_nodeapi() instead with the view argument.
http://api.drupal.org/api/function/hook_nodeapi/6

Please Explain Drupal schema and drupal_write_record

1) Where is the best place to populate a new database table when a module is first installed, enabled? I need to go and get some data from an external source and want to do it transparently when the user installs/enables my custom module.
I create the schema in {mymodule}_schema(), do drupal_install_schema({tablename}); in hook_install. Then I try to populate the table in hook_enable using drupal_write_record.
I confirmed the table was created, I get no errors when hook_enable executes, but when I query the new table, I get no rows back--it's empty.
Here's one variation of the code I've tried:
/**
* Implementation of hook_schema()
*/
function ncbi_subsites_schema() {
// we know it's MYSQL, so no need to check
$schema['ncbi_subsites_sites'] = array(
'description' => 'The base table for subsites',
'fields' => array(
'site_id' => array(
'description' => 'Primary id for site',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
), // end site_id
'title' => array(
'description' => 'The title of the subsite',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
), //end title field
'url' => array(
'description' => 'The URL of the subsite in Production',
'type' => 'varchar',
'length' => 255,
'default' => '',
), //end url field
), //end fields
'unique keys' => array(
'site_id'=> array('site_id'),
'title' => array('title'),
), //end unique keys
'primary_key' => array('site_id'),
); // end schema
return $schema;
}
Here's hook_install:
function ncbi_subsites_install() {
drupal_install_schema('ncbi_subsites');
}
Here's hook_enable:
function ncbi_subsites_enable() {
drupal_get_schema('ncbi_subsites_site');
// my helper function to get data for table (not shown)
$subsites = ncbi_subsites_get_subsites();
foreach( $subsites as $name=>$attrs ) {
$record = new stdClass();
$record->title = $name;
$record->url = $attrs['homepage'];
drupal_write_record( 'ncbi_subsites_sites', $record );
}
}
Can someone tell me what I'm missing?
If ncbi_subsites_get_subsites() is not in the .install file, you need to include whatever file its in with your module. Otherwise, it's returning nothing, in which case try dumping $subsites and exiting.
I think the answer is that drupal_write_record is not meant for install or enable hooks. I think when enabling or installing, you have to write SQL. That is the impression I am getting from reading some posts that mention that the schema is not available in these hooks.
First of all (assuming Drupal 6), drupal_write_record() cannot be called from hook_install() because Drupal would not find the database schema defined from the module, which is still going to be installed, and enabled.
Instead you need to use db_query() function. (the comments are speaking of a way to include default data by prviding it to hook_schema() serialized, but i've found no documentation on this.)
However, would you be using (the development version of) Drupal 7, you want to look at the db_insert() function instead.

Resources