Wednesday, December 2, 2015

Bulk Content Import Drupal 7 (Feeds Module)

Required modules:
Set up CSV:
Prepare the Excel file that you will convert to CSV - open up Excel and in the first row add the headers. Feeds importer requires a global ID to uniquely identify nodes. So the first column should contain this unique identifier. Name this column "guid". The other column headers can be anything you like. For example, if you want to import a list of files with title; you can name your columns filename, title, description etc. The column headers do not have to match content type fields.
Add data to the Excel file:
  • guid: make sure each row has a unique number.
  • filename: You will have to upload all the files you want to migrate, into your Drupal root directory. So put all your files in a directory called import-uploads and upload them to your Drupal root. Make sure that the filenames have the path from your Drupal root. So each filename should have "import-uploads/" prepended. E.g. "import-uploads/file1.pdf", "import-uploads/file2.avi", etc.
  • title/description: should have text, make sure that your title is less than 256 characters.
Save as CSV - save the Excel file in CSV format - make sure to quote all cells. Otherwise you will run into errors if any of the text (e.g. description) contains commas.
Set up Feeds Importer:
  • Navigate to Structure -> Feeds Importer -> Add Importer.
  • Give your importer a meaningful name like "bulk file upload" and click Submit.
On the next screen follow these directions:
  • Basic Settings: leave as is, no changes needed.
  • Fetched: click "change" and select the "File Upload" option and click save.
  • Fetched Fileupload: click settings, make sure to add all the file extentions you want to add, e.g. pdf, wav, doc, docx etc.
  • Parser: click "change", select the "CSV Parser" option and save.
  • CSV Parser: leave as is.
  • Processor: leave as is (Node Processor).
  • Node Processor: click settings, select "Replace existing node" for "Update exisiting node", select the Content Type you want to use for this import. You may choose to use an existing user as the author.
  • Click Save.
  • Node Processor Mapping: This is where you will map your CSV file headers to the Content Type fields. One by one, add the column headers of the CSV file to the mapping and choose the appropriate Content Type field to map to.
  • Click Save.
Run the import:

  • Navigate to Structure -> Feeds Importer, and click on the "import" link.
  • Click on the Bulk File Upload link.
  • Upload your CSV file into your sites/default/files folder.
  • Upload your import-upload folder, containing all the files to be imported into your Drupal root.
  • Enter your CSV file's name in the File text field.
  • Click on the Import Button.

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...