Powered By Blogger
Showing posts with label Drupal. Show all posts
Showing posts with label Drupal. Show all posts

Thursday, February 9, 2017

cURL in drupal 8 OR webservice in drupal

https://www.drupal.org/node/1838208


I have used both with good results drupal_http_request() is somewhat simpler to use in my opinion but cURL provides more options.
Here are two sample examples for a custom module.
drupal_http_request();
<?php 

DEFINE(MY_URL, 'http://test.com');

myfunction_init() {

    
  $data = array(
      'my_role' => test,
      'password' => 'test',
      'my_id' => test,
  
    );
    $options = array(
                'method' => 'POST',
                'data' => drupal_http_build_query($data),
                'timeout' => 15,
                'headers' => array('Content-Type' => 'application/x-www-form-urlencoded'),
    );
    $result = drupal_http_request(MY_URL, $options);

?>
cURL
<?php

function _custommodule_execute($email, $fname, $lname) {

    $id = '94sdf'; 
    $test = 'asdf343'; 

    $url = 'http://test_urlr';
    $query = sprintf('test1=%s&test2=1&test3=%s&test4=%s&test5=%s&test6=%s', $id, $test, $email, $fname, $lname);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_MAXREDIRS, 0);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

    $result = curl_exec($ch);
    $error = curl_error($ch);

    curl_close($ch);

}
?>

Friday, July 15, 2016

Drupal 8 Site Audit Steps

Steps

Step 1  Checking Quality of Code
     
    Here i used the coder modules for checking The "Quality of Code" and I have checking the code and Drupal coding standard manually.

Step 2  Checking Core Security Update

    I checked the any security updates available in core and contributed modules 

Step 3 hacked Core and Contributed Modules

      
   Here I checked the following things

   1. List of hacked modules by using "Hacked" module.
   2. List of update available modules.
   3. List of unused modules.
   4. List of unsupported modules.
   5. List of deprecated modules.
   6. List of sandbox modules which are  used in this site. 

Step 4 Custom Modules
      Here i checked, what are the custom modules used in this site. And checked those modules really required or not.

Step 5 Code Security
  
    I used the security_review modules for checking coding level of security. 

Step 6 Server Security

    Here i checked following points and suggested Cloudflare WAF for advanced server side security.

   => Checked the basic SSL
   => File access permission through FTP,SSH and Cpanel.
   => DB access permission 
  

Step 7 3rd Party Tools and Plugins

  
     Here I checked the any 3rd Party web service modules or Plugins installed in this site and is it have secured connection for request and response

Drupal security update

1. Command for Drupal security updates  (core and contributed)

drush up --security-only

2. command for drupal core update only

drush up drupal

Friday, May 27, 2016

user details update when user register

function lulzbot_verified_company_user_update(&$edit, $account, $category) {

$domain_name = substr(strrchr($edit[mail], "@"), 1);
$domain = explode('.', $domain_name);


$machine_name = 'companies';
  $v = taxonomy_vocabulary_machine_name_load($machine_name);
  $terms = taxonomy_get_tree($v->vid);
 
  foreach ($terms as $term) {

 if($term->name == $domain[0]){
  $edit[field_user_companies]['und'][0] = $term->tid;
  user_save($account, $edit);
 }
  }

get specific taxonomy below taxonomy in custom module in drupal 7

$machine_name = 'companies';
  $v = taxonomy_vocabulary_machine_name_load($machine_name);
  $terms = taxonomy_get_tree($v->vid);
  foreach ($terms as $term) {
    $options[$term->tid] = $term->name;
  }
  //return $options;
print_r( $options);exit;

Tuesday, January 12, 2016

How can I override field validation with a hook_alter_form

Let's say that I want to modify the validation of this field and display a different error message instead of the one shown above, something like "Please type your name" and I want this to happen only when using one particular theme. So I've added the code below into the file "template.php" that resides inside the theme's foder:
function mytheme_form_alter(&$form, &$form_state, $form_id) {
    if($form_id == 'forward_form') {

$form['#validate'][] = 'my_custom_validation';
    }
}

function my_custom_validation($form, &$form_state) {
       if (!$form_state['values']['name'] ) {
          form_set_error('name', t('Please type your name.'));
      }
}









//Implements hook_form_alter for resource under page webform validation error message change function globalfd_form_alter( &$form, &$form_state, $form_id) { if($form_id == 'webform_client_form_83') { unset($form['#validate'][0]); $form['#validate'][1] = 'my_custom_validation'; } } function my_custom_validation($form, &$form_state) { //get value from webform field $phone = $form_state['values']['submitted']['phone']; $email = $form_state['values']['submitted']['email']; //phone number validation if(preg_match("/^\(?(\d{3})\)?[-\. ]?(\d{3})[-\. ]?(\d{4})$/", $phone) || $phone == '') { // $phone is valid } else { form_set_error('phone', t('Not a valid 10-digit US phone number (Please use 1 of the following formats 999-999-9999 or 0001112222 )')); } //email validation if ($email != '') { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { form_set_error('phone', t('email is not a valid email address')); } }else{ form_set_error('phone', t('email address is required')); } }