Drupal form api select elements returning integers instead of string
I always have the same problem when using select forms, and I always forget the solution.
Instead of returning an array, like: return $competitions; you have to return a drupal_map_assoc, like this: return drupal_map_assoc($competitions);
Otherwise, when selecting the form in hook_submit you will get a number, instead of a human readable string.
[gist:5920064]
Customize a webform with
- Read more about Customize a webform with
- Log in or register to post comments
Convert dates from UNIXTIME in mysql
Reading a date in mysql can be frustrating, unless your brain is able to convert Dates from UNIXTIME formats. Let's see for example this scenario in Drupal:
SELECT * FROM `node` ORDER BY `node`.`created` DESC LIMIT 0 , 30
If you need to fetch, for example, when it was the last time that a node was created, this format doesn't help too much.
The solution is quite simple, FROM_UNIXTIME( field_with_date )
For example:
SELECT * , FROM_UNIXTIME( created ) FROM `node` ORDER BY `node`.`created` DESC LIMIT 0 , 30
- Read more about Convert dates from UNIXTIME in mysql
- Log in or register to post comments
Restart vhost conf without restarting Apache
Changing your vhost.conf and working with plesk? There is no need to restart your whole Apache server and bother your users:
/usr/local/psa/admin/sbin/httpdmng --reconfigure-domain domain.com
Tip of the weekend :-)
- Read more about Restart vhost conf without restarting Apache
- Log in or register to post comments
Using git in bitbucket without password
Look mom, without hands...
First, change this in your .git/config:
old url:
url = https://USER@bitbucket.org/hispamedios/PROJECT.git
new one:
url = ssh://USER.bitbucket.org/hispamedios/PROJECT.git
Edit your .ssh/config, in your local directory, and add this:
- Read more about Using git in bitbucket without password
- Log in or register to post comments
Deploying Drupal projects: git + capistrano
removing some folders from git, file .gitignore with these contents:
# Ignore paths that contain generated content.
cache/
files/
sites/*/files
sites/*/private
Using symbolic links for /files directory:
namespace:custom do
task:symlink do
run "ln -s /var/www/crucerista/sites/crucerista.net/files/ /var/www/crsta/current/sites/crucerista.net/"
run "echo 'finished'"
end
end
after "deploy","custom:symlink"
- Read more about Deploying Drupal projects: git + capistrano
- Log in or register to post comments
Optimizing a Drupal database: improving the performance
That is what you have when you don't optimize and maintenance properly your Drupal projects. A 4GB database which hits hugely the server performance. Just a couple of "magic tricks" and .... 194MB.
Magic? Not at all. If you have a problem with your server, with hangs up and things going very sloooow, check the cache. sessions and watchdog tables, and clear them.
It works like a charm :-)
Howto patch a Drupal module
Some contributtion to add to this Drupal module with which you have been working on?
Very easy, take note:
- Read more about Howto patch a Drupal module
- Log in or register to post comments
error: unable to create temporary sha1 filename ./objects/17: Permission denied
I have had this issue recently, with a git branch which did not want to to react to push. That's what a was having:
$ git pushgit@domain.net's password Counting objects: 5, done.
Delta compression using up to 2 threads.
ng objects: 100% (3/3), done.
Writing objects: 100% (3/3), 303 bytes, done.
Total 3 (delta 2), reused 0 (delta 0)
error: unable to create temporary sha1 filename ./objects/17: Permission denied
fatal: failed to write object
Drupal maintenance tasks
How important is having a database optimized. Doing some "basic" optimizations like clearing the cache, runing the Drupal cron and a couple of things more, your database can change from having 4 GB to just around 200MB... incredible? Not at all, the importance of maintenance tasks :-)
Which tasks? Mainly:
- Read more about Drupal maintenance tasks
- Log in or register to post comments