Saturday, December 14, 2013

Getting drush to work ( on flexwebhosting ) fixing "exec() has been disabled for security reasons" and "This configuration is incompatible with drush."

I run in a bit of trouble installing drush on a new webhost.
I just started following the tutorial on
Specific instructions for installing Drush on different platforms
Since I'm using CentOS I picked the Install Drush on CentOS (with H-Sphere)
But then when I tried to run drush after install I got some errors.
The first one I got was: "exec() has been disabled for security reasons"
After I fixed that one I got:
"The following restricted PHP modes have non-empty values: [error] disable_functions. This configuration is incompatible with drush."

Both errors can be fixed by putting this in the command line on the server:
# mkdir -p ~/.drush
# cp -i /usr/local/lib/php.ini ~/.drush/
# nano ~/.drush/php.ini

Then find the "disable_functions" string and make it is empty:
disable_functions =
save the php.ini file and drush should be working now :)

source articles:

Friday, July 12, 2013

Alter view and pager to display more items per page programmatically

I have 1 codebase for a multisite install. I needed to change the number of items per page on every page and didn't want to use the view ui and change every view. So I looked for a way to do this programmatically.

As it turns out this is quite simple.

I used hook_views_pre_build() to do this:

 * Implements hook_views_pre_build ()
function MODULENAME_views_pre_build(&$view) {
  if($view->name == "name_of_your_view") {
    $view->items_per_page = 30;

Friday, June 21, 2013

Treehouse learn to make ios apps, android apps, web design and programming.

Searching more for a way to pick up my design skills being a programmer and all I came across this treehouse site ( link is below )

Just started today so I won't have a deep review but here's what I like and dislike:
  • I like the why it is set up, building from the scratch up. Other sites I cant really find a start point and I and up not looking into the trainings. 
  • You can take a quiz or code challenge along the way. first of all for me it's checking if I already own those skills of if I should check in to this in a few seconds.
  • Second, you earn badges which may be a bit childish but I think it's fun. Also potential employers can see the badges you earned. And last it gives you hands on practice while you try out new stuff you just learned.
  • As you progress you can view on your dashboard where you are in the courses. So you can easily pick up any time where you left off.
  • There is a litte bit of humor in the video's which I think takes the edge of some things and makes it a nicer learning experience.
  • Now what I don't like I have to think about... Maybe it could have been a bit less childish ? If I come up with some thinks I'll add the likes and dislikes later to this post
The prices are ok I have to see if this is really for me but looked at a few and I must say I love it so far!
It starts from 25$ a month or 250$ if you pay annually ( 2 month discount ) for the silver account.
The gold account is a bit more pricier but I think you will have enough with the silver account.

Also you can earn 20% discount for every subscriber you refer, which is what I'm doing right now ;)
And I would appreciate It if you used my subscriber link. I'll give you the 20% discount I will be getting for the first year back if you contact me.
But other than that I still think it's a good think. Check out the free trial video's and see why I like it.

So check it out the link is in this join me on treehouse image below:

Create one time login link from the command line using drush no need to reset your password

I don't use this command as much but when I need it I always forget what this string of code was.

So I'll post it on my blog :)

The magic:
drush uli

Or if your targeting a specific user:
drush uli username

Using drush you can create a one time login link for a user or admin.
This is especially usefull if you want to login to the site without changing the password.
For example if you have a client with a drupal site that doesn't know the administrators pass or doesn't want to change it because you need it.
This can also be used to change the password if you don't know where the password reset link would be send or don't have access to the email address ( anymore )

Wednesday, June 19, 2013

Creating a link field programmatically for a profile2 user entity and deleting it upon disable or uninstall

In this example I have a profile2 profile called "werkgever"

The field I'm creating is a field used for that profile to input a website link.

required modules are

My module name is more_werkgever_fields

Using hook_enable I create the field:
 * Implementation of hook_enable().
function more_werkgever_fields_enable() {
  // Check if our field is not already created and if not create the field.
  if (!field_info_field('field_website')) {
    $field = array(
        'field_name' => 'field_website',
        'type' => 'link_field', // text

    // Create the instance on the bundle.
    $instance = array(
      'field_name' => 'field_website',
      'entity_type' => 'profile2',
      'label' => 'Website',
      'bundle' => 'werkgever',
      'required' => FALSE, // default: FALSE
      'settings' => array(
         // Here you inform either or not you want this field showing up on the registration form.
        'user_register_form' => 1,
      // 'widget' => array(
      //   'type' => 'link',
      // ),

This needs to be put in your modulename.install file

Also in the .install file you can implement a hook_disable or hook_uninstall
hook_disable is called when you disable the module. So this is handy if you are in a developing stage.
Just disable de module and your field should be gone.
An implementation of hook_disable:
 * Implements hook_disable
function more_werkgever_fields_disable(){
  // removes field when module is disabled
As said this goes into your module.install file as well
Finally there is the Implementation of hook_uninstall:
 * Implements hook_uninstall
function more_werkgever_fields_uninstall(){
  field_delete_field('field_website'); // removes field from the system
The uninstall hook is only called upon uninstalling the module. I recommend putting your delete field in here. Or don't delete your field. Depending if your your module can be reused by others and maybe causing problems if that field is to be deleted. In my case I don't want it to clutter my database so I put it in my uninstall hook.

Monday, April 22, 2013

Drupal 7 Create a block that's only visible on specific pages programmatically.

A better view of this post can be viewed here on stackexchange

1) Create a new module or copy an existing one and rename it.

2) Enable PHP filter module ( included in core )

3) Create a block using the hook_block_info() hook.
For example:

 * Implements hook_block_info().
function mymodule_block_info(){
  $blocks['mymodule_block_name'] = array(
    'info' => t('Block description'), //The name that will appear in the block list.
    'cache' => DRUPAL_CACHE_PER_ROLE, //Default
    'region' => 'sidebar_first', // assign block region
    'status' => 1, // enable the block
    'visibility' => BLOCK_VISIBILITY_PHP, // set visibility to use the result of pages code
    'pages' => '',
  return $blocks;
TIP: create a block using the block UI after enabling the PHP filter module so you can test your 'pages' PHP code before putting it in the module and prevent having to disable, uninstall and enable your module every time you change your php code.

4) Create the content of the block using hook_block_view():

 * Implements hook_block_view
function vacancies_block_view($delta = '') {
  switch ($delta) {
    case 'mymodule_block_name':
      $block['subject'] = 'Block title';
      $block['content'] = 'Hello world!';  
  return $block; // dont forget to the return the $block!

5) upload your code and enable the module
Or if you used an existing module disable, uninstall, enable the module

6) clear cache and check the result

Tuesday, October 30, 2012

Adding menu items to an drupal 7 install profile

using the .install file ( located here: <websitedir>/profiles/<profilename>/<profilename>.install )

You can add menu items by extending the array like in the standard install profile:

adding this will put the block main-menu in the menu_bar region:

      'module' => 'system',
      'delta' => 'main-menu',
      'theme' => $default_theme,
      'status' => 1,
      'weight' => 0,
      'region' => 'menu_bar',
      'pages' => '',
      'cache' => -1,
The trick was here setting the module to 'system' instead of 'menu' otherwise errors will show up after install. 
You can define the theme you want to apply this for or don't set it to apply on all themes. Since this is a system default location you should be fine not setting the theme.

Then let the following query run ( just like the standard.install file )

 $query = db_insert('block')->fields(array('module', 'delta', 'theme', 'status', 'weight', 'region', 'pages', 'cache'));
  foreach ($values as $record) {
Then creation the menu items like so:

// create menu
  $item = array(
    'link_title' => st('Home'),
    'link_path' => '<front>',
    'menu_name' => 'main-menu',

Optional you could do a menu_rebuild but I didn't see a difference while installing.
maybe this is only for modules so the menu gets 'cleared' after enabling a module.
since the whole site is just build it might not be necessary doing this in a profile .install file

Update the menu router information.