Tamer Zoubi @ Drupal 8.1


Drupal expert | Programmer

variable_get and variable_set in Drupal 8

variable_get()/variable_set() and variable_del() API was removed from Drupal 8 in favor of Configuration API.

So in order to save a simple variable in your module firstly you need to decide on a config object name and a name for the settings. Simple settings can be stored in a config object named <module_name>.settings, while for more complex settings it is advisable to use sub-keys.

To get a variable in Drupal 7 you would use:

Tags
variable_get
variable_set
Drupal 8

How to retrieve site wide email address in Drupal 8

In Drupal 7 you would easily retrieve site wide email address through variable:

<?php 
$site_email = variable_get('site_mail', '');
?>

However in Drupal 8 variables are gone in favor of configuration objects. So the same functionality in Drupal 8 would be: 

<?php 
 $system_site_config = \Drupal::config('system.site');
 $site_email = $system_site_config->get('mail');
?>

 

Tags
Drupal 8
config
mail
variable_get

Drupageddon - Updating to Drupal 7.32 is not enough, your site may already be hacked!

Following up on the Drupageddon, I noticed something weird on one of my servers. While patching sites to Drupal 7.32, I noted that on some of the sites database.inc was already updated with todays date! I was sure nobody made the change so I went into investigating this more.

I made a diffcheck via git and discovered there was additional file on my server!

Tags
Drupageddon
Drupal 7
SA-CORE-2014-005

"You don't have permission to access /phpMyAdmin on this server" after upgrading to Yosemite

I upgraded my Mac to Mac OS X Yosemite.
I had a LAMP stack installed and it worked fine.

After upgrading to Yosemite, I got following problem:

when trying to load phpMyAdmin at http://localhost/phpMyAdmin I get the following error:

Forbidden. You don't have permission to access /phpMyAdmin on this server.

First thing I tried to do is to change file permissions in /phpMyAdmin folder to match those of www, but that didn't help.

Tags
LAMP
Mac
OS X
phpmyadmin
Yosemite

Customer Support via Twilio SMS with Zendesk v2

Recently I was challenged to integrate Twilio SMS channel via Zendesk. If you're not familiar with Zendesk, it's a helpdesk system that allows customers to create tickets by sending email which support staff can respond to and create certain workflows. More about Zendesk here.

For SMS part I decided to use Twilio since I am already familiar with their API. More about Twilio here.

Tags
php
twilio
zendesk

Drupal translate custom module

If you created your custom Drupal module and you wonder how to translate it in other language then you came to the right place!

In few simple steps I ll show you how to export translatable strings from your custom module and import them in Drupal translation interface.

Tags
.po files
.pot
Drupal
drupal module
multilingual
translate interface
translation

How to reset admin password in Drupal 7

Previously for Drupal 6 site, when you forgot or didn't know the admin password, you could easily change it via database by following query:

UPDATE users SET pass = MD5('mynewpassword') WHERE uid = 1; 

However if you tried that in Drupal 7 site you will see it doesn't work! Thats because Drupal 7 stores a salted SHA512 hash instead of MD5 hex hash. To get new password you must use the user_hash_password('mypassword') function (located in includes/password.inc), then paste it into the database.

Tags
Drupal 7
reset password database
restore admin password

Send SMS from VoIP Drupal

Considering you configured your VoIP Drupal with one of the providers, here is the sample code snippet that sends "Hello world" SMS:

<?php
$number = '+1234567890123'; //Number to send SMS to. Must be in E.164 format.
$call = new VoipCall();
$call->setDestNumber($number);
$text = 'Hello from VoIP Drupal';
voip_text($text, $call);
?>

Pretty cool, right?

Tags
php
sms
VoIP Drupal