Thursday, September 17, 2015

How to add extra fields to user profile in Drupal?

Step 1. - Create custom module -For Example My custom module name is extra_user_profile
Folder Name - extra_user_profile
Files - extra_user_profile.nfo, extra_user_profile.module, extra_user_profile.install

Step 2.
extra_user_profile.nfo file:-
name = Extra User Profile
description = Add new field in user profile
core = 7.x
version = "7.x-2.5"
core = "7.x"

Step 3.
extra_user_profile.module file:-
<?php

Step 4.
extra_user_profile.install file:-
<?php

/**
 * Implementation of hook_enable().
 */
function extra_user_profile_enable() {
  // Check if our field is not already created.
  if (!field_info_field('field_nickname')) {
    $field = array(
        'field_name' => 'field_nickname', 
        'type' => 'text', 
    );
    field_create_field($field);

    // Create the instance on the bundle.
    $instance = array(
        'field_name' => 'field_nickname', 
        'entity_type' => 'user', 
        'label' => 'Nick Name', 
        'bundle' => 'user',
        'required' => TRUE,
        'settings' => array(
            'user_register_form' => 1,
        ),
        'widget' => array(
            'type' => 'textfield',
            'weight' => '1',
        ), 
    );
    field_create_instance($instance);
  }
}

Step 5 Enable Module

Now Nickname field is available in User profile page
Enjoy....!!!!

only show translated menu items into current language (Drupal 8)

function MY_THEME_preprocess_menu(&$variables) {   if ($variables['menu_name'] == 'brancott-header-menu') {    $langu...