Dec 08 2016
Dec 08

In my last blog post, I outlined the best practices to manage the configuration management for the site. If you have read the previous post and wanted to follow the same on your site, this post will show you how to do Switching from file system configuration management to features on existing drupal site easily.

There's not any hard and fast way to change the configuration management for an existing Drupal site. Here are the steps in brief involved in to do the following:

  • Delete all of the old configuration except user roles and permissions
  • Export all configuration using features
  • Add update hooks to start using features

Delete all of the old configuration: Delete all the configuration which is present in your $config['sync'] directory except the user roles configuration.

Export all configuration using features: Export your configuration with features and make sure to leave the user roles and permissions and manage your user roles and permissions configuration via the Filesystem.

Add update hooks to start using features: Add update hooks to enable the new features.See the same hook_update_n below.

/**
 * Install features based config.
 */
function xyz_core_update_8017() {
  $features = [
    'xyz_f_alert',
    'xyz_f_appointment_request',
    'xyz_f_page',
    'xyz_f_blog',
    'xyz_f_career_area',
    'xyz_f_careers_landing_page',
    'xyz_f_common_formats',
    'xyz_f_doctor',
    'xyz_f_education_research',
    'xyz_f_event',
    'xyz_f_foundation',
    'xyz_f_job',
    'xyz_f_location',
    'xyz_f_news',
    'xyz_f_paragraphs',
    'xyz_f_person',
    'xyz_f_procedure',
    'xyz_f_related',
    'xyz_f_search',
    'xyz_f_site',
    'xyz_f_testimonial',
    'xyz_f_user',
  ];

  \Drupal::service('module_installer')->install(['features', 'config_update']);
  \Drupal::service('module_installer')->install(['xyz_bundle']);
  \Drupal::service('module_installer')->install($features);
}
Dec 07 2016
Dec 07

Breadcrumb

  1. Home /
  2. Blog /
  3. Manage drupal 8 site configuration with features

Published 1 month ago

Last updated 1 month ago

There are several ways to manage the drupal site configuration in Drupal 8 either by keeping it in the database or managing it at from the file system or managing with features.

I have launched couple of sites with the combination of the following best practices with managing features and configuration in file system

User Roles and Permissions are being managed by the Configuration Management because features does not export the permissions with the Roles
Using features for managing the other entities and rest of the stuff.

Below the screenshot of attached site structure of one my project

Khalsa Security Com

Dec 06 2016
Dec 06

In one of my recent client project, we had the requirement to move to lightning profile from custom installation profile, so that they would be able to use the lightning features OOTB. During the POC we found different approaches of using/consuming the lightning features, but we planned to use the lightning extend approach.

In Drupal7, there was pretty easy way to do was to update the install_profile variable

$ drush vset --exact -y install_profile standard

There is an alternate way of doing this is directly is updating the variable name directly in the schema.

In Drupal8, there was not any module that allows to switch the profile like in Drupal 7 there's the profile_switcher module. 

In Drupal 8, the installation profile information has been moved from config to key value store

drush sqlq "DELETE FROM key_value WHERE collection='system.schema' and name='lightning'"
drush sqlq "INSERT INTO key_value (collection, name, value) VALUES ('system.schema', 'lightning', X'733A343A2238303036223B');"

Note: For the second query, The value column data should contain your lightning release information.So use the appropriate information of profile as per your codebase.The above command contains the information of lightning-8.x-2.02

Now, Enable the lightning profile.

drush cset core.extension module.lightning 0

Here the list of things that should be taken care before switching the profile on existing Drupal site:

  • All the enabled modules should be present in the new installation profile, if the modules would not be there then there would be issues come up
  • Do the clear the cache

Related Issues:

  1. https://www.drupal.org/node/2841724

Next article:  Switching to Features from Configuration Management

Nov 09 2016
Nov 09

Breadcrumb

  1. Home /
  2. Blog /
  3. Hack Proof your drupal site

Published 2 months ago

Last updated 2 months ago

Security of the Drupal website is a important stuff for the site owners, site developers.This blog post has my presentation at the Drupal Camp Mumbai that  intended for Drupalers who want to avoid security loop holes while writing code or architecting solutions. We delved into common security issues that ails custom code and has both vulnerable and secure code snippets.This is mostly about my encounters and experience after doing 50+ project application reviews and also a good guideline for new contributors.

Hack Proof Your Drupal Site from Naveen Valecha

Next article:  A guide to review Project Applications.

Dec 09 2015
Dec 09
DrupalCamp is the distribution, for spinning up camp sites.  Lately, as always :), I was part of the site building team at a local camp in India and after working with the team, found that all the sites were/are having similar content architecture e.g. content types, listing pages etc., except their themes and designs.
While sprinting at DrupalCamp Pune, we decided to build a site for DrupalCamp Delhi. While sprinting we realised we need  a common code/feature base for camp sites. And there we started building distribution in D8. The time we started making this distribution profile Drupal 8 was in beta 16 and we are hoping to make first release candidate soon.
Drupalcamp comes up with the 2 contributed modules fb_likebox, twitter_block for the facebook and twitter share blocks in sidebar.
Configurations that this installation profile provides are:
  1. Content types
    1. Basic Page :  For creating basic pages like about us,etc. on the site.
    2. Session : This is used for creating/submitting sessions.
    3. Sponsor : This is used to keep information about the sponsors.
  2. Listings (Views):
    1. Accepted Sessions
    2. Proposed Sessions
    3. Sponsors
    4. Students.
  3. Social sharing buttons:
    1. facebook
    2. twitter
  4. Blocks:
    1. facebook
    2. twitter

We need to just use the drupalcamp profile and theme the site.
Challenges that came up while building this profile :
  1. Contributed modules : The contributed modules stable release was not out so ported the fb_likebox, twitter_block module to drupal 8 and created the stable release of fb_likebox. Special thanks to the maintainer baekelandt for quick promptness.
  2. There was no tool available which will provide the boilerplate code, so we started with forking the standard profile and used the config-export to export the configurations. Now with the drupalconsole 0.9.9 we have generate profile command available to  generate the boilerplate code. Used the phing to automate the testing as sam specified in its blog.

Thanks to the entire Drupalcamp Distribution Team!
What's Next ?
Please join hands to release the stable version for twitter_block and include this stable release in the drupalcamp distribution.

Dec 08 2015
Dec 08

DrupalCamp is the distribution, for spinning up camp sites.  Lately, as always :), I was part of the site building team at a local camp in India and after working with the team, found that all the sites were/are having similar content architecture e.g. content types, listing pages etc., except their themes and designs.

While sprinting at DrupalCamp Pune, we decided to build a site for DrupalCamp Delhi. While sprinting we realised we need  a common code/feature base for camp sites. And there we started building distribution in D8. The time we started making this distribution profile Drupal 8 was in beta 16 and we are hoping to make first release candidate soon.

Drupalcamp comes up with the 2 contributed modules fb_likebox, twitter_block for the facebook and twitter share blocks in sidebar.

Configurations that this installation profile provides are:

  1. Content types

    1. Basic Page :  For creating basic pages like about us,etc. on the site.

    2. Session : This is used for creating/submitting sessions.

    3. Sponsor : This is used to keep information about the sponsors.

  2. Listings (Views):

    1. Accepted Sessions

    2. Proposed Sessions

    3. Sponsors

    4. Students.

  3. Social sharing buttons:

    1. facebook

    2. twitter

  4. Blocks:

    1. facebook

    2. twitter

We need to just use the drupalcamp profile and theme the site.

Challenges that came up while building this profile :

  1. Contributed modules : The contributed modules stable release was not out so ported the fb_likebox, twitter_block module to drupal 8 and created the stable release of fb_likebox. Special thanks to the maintainer baekelandt for quick promptness.

  2. There was no tool available which will provide the boilerplate code, so we started with forking the standard profile and used the config-export to export the configurations. Now with the drupalconsole 0.9.9 we have generate profile command available to  generate the boilerplate code. Used the phing to automate the testing as sam specified in its blog.

Thanks to the entire Drupalcamp Distribution Team!

What's Next ?

Please join hands to release the stable version for twitter_block and include this stable release in the drupalcamp distribution.

Mar 07 2015
Mar 07

Breadcrumb

  1. Home /
  2. Blog /
  3. Tips to become a git administer at drupal.org

Published 1 year ago

Last updated 2 months ago

Previously we read how to be a webmaster at drupal.org , Now I became the git administer at drupal.org. So I think to write a blog post so that others can benefit and also get to know how to become git administer.
In simple words: "Start Contributing". Git Administer privileges are granted to the users with proven record of contributions in the Project Applications issue queue. A solid history of consistent contributions on drupal.org is a must to get consideration for an elevated role.

How to start contributing & where you can contribute :

  1. Join the code review group
  2. Read How to review full project applications
  3. Some helpful tools for reviewing :
  4. Learning Sources : 
  5. if you found any problem while contributing,just comment on the below post/ if you need immediate answer you can try and find one of the git administer on IRC - #drupal-codereview IRC channel on Freenode.


Benifits of becoming git administer :

  1. You will see a new challenging case in every new project application.
  2. Your drupal apis knowledge will become sharp.
  3. Many more....

I would encourage you to learn more about that process and join the group of reviewers.

Next article:  A guide to review project applications

Mar 07 2015
Mar 07

Previously we read how to be a webmaster at drupal.org , Now I became the git administer at drupal.org. So I think to write a blog post so that others can benefit and also get to know how to become git administer.

In simple words: "Start Contributing". Git Administer privileges are granted to the users with proven record of contributions in the Project Applications issue queue. A solid history of consistent contributions on drupal.org is a must to get consideration for an elevated role.

How to start contributing & where you can contribute :

  1. Join the code review group
  2. Read How to review full project applications
  3. Some helpful tools for reviewing :
  4. Learning Sources : 
  5. if you found any problem while contributing,just comment on the below post/ if you need immediate answer you can try and find one of the git administer on IRC - #drupal-codereview IRC channel on Freenode.

Benifits of becoming git administer :

  1. You will see a new challenging case in every new project application.
  2. Your drupal apis knowledge will become sharp.
  3. Many more....

I would encourage you to learn more about that process and join the group of reviewers.
Next article:  A guide to review project applications
Feb 23 2015
Feb 23

Security of the Drupal website is a important stuff for the site owners, site developers.This blog post has my presentation at the Drupal Camp Mumbai that  intended for Drupalers who want to avoid security loop holes while writing code or architecting solutions. We delved into common security issues that ails custom code and has both vulnerable and secure code snippets.This is mostly about my encounters and experience after doing 50+ project application reviews and also a good guideline for new contributors.

[embedded content]

Hack Proof Your Drupal Site from Naveen Valecha

Next article:  A guide to review Project Applications.


Jan 28 2015
Jan 28

Breadcrumb

  1. Home /
  2. Blog /
  3. Tips to become a webmaster on drupal.org

Published 1 year ago

Last updated 2 months ago


As recently I became the webmaster on the drupal.org and few people started asking me about how to become a webmaster and where to start. So I write a blog post so that others can benefit.

In simple words: "Start Contributing". Webmaster privileges aren't granted lightly for obvious reasons. A solid history of consistent contributions on drupal.org is a must to get consideration for an elevated role.


How to start contributing & where you can contribute :

  1. Help out in the content queue, especially reviewing Service Listing requests .Marketing guidelines for reviewing the service listing requests.
  2. Training Listing requestsMarketing guidelines to review training listing requests.
  3. Help out in the webmasters queue, Textual improvements requests.
  4. Depending on your skills, you can also contribute to drupal customizations as well.
  5. if you found any problem while contributing to above sections,just comment on the below post/ if you need immediate answer you can try and find one of the webmasters on IRC - #drupalorg IRC channel on Freenode.

If you need guidance, join the #drupalorg IRC channel and find dddavelizzjoytvn or myself. A general overview about the various ways to contribute to Drupal.org can be found in the documentation.

If you have good coding skills, you are more than welcome to help reviewing project applications. I encourage you to learn more about that process and join the group of reviewers.

Next article:  We will look at how to be a git administrator on drupal.org

Jan 28 2015
Jan 28

As recently I became the webmaster on the drupal.org and few people started asking me about how to become a webmaster and where to start. So I write a blog post so that others can benefit.
In simple words: "Start Contributing". Webmaster privileges aren't granted lightly for obvious reasons. A solid history of consistent contributions on drupal.org is a must to get consideration for an elevated role.

How to start contributing & where you can contribute :

  1. Help out in the content queue, especially reviewing Service Listing requests .Marketing guidelines for reviewing the service listing requests.
  2. Training Listing requests, Marketing guidelines to review training listing requests.
  3. Help out in the webmasters queue, Textual improvements requests.
  4. Depending on your skills, you can also contribute to drupal customizations as well.
  5. if you found any problem while contributing to above sections,just comment on the below post/ if you need immediate answer you can try and find one of the webmasters on IRC - #drupalorg IRC channel on Freenode.
If you need guidance, join the #drupalorg IRC channel and find dddave, lizzjoy, tvn or myselfA general overview about the various ways to contribute to Drupal.org can be found in the documentation.
If you have good coding skills, you are more than welcome to help reviewing project applications. I encourage you to learn more about that process and join the group of reviewers.
Next article:  We will look at how to be a git administrator on drupal.org

Jan 23 2015
Jan 23

Was looking out some good English Speaking training course website for my cousin to become a fluent English speaker.

On opening the homepage I found the section "Free trial".

DailyStep free trial

I did the same thing as all guys do.Click on the Free trial link,created my account.I personally feeling happy to get the 5 free audio English lessons.

I clicked on one of my lessons link and come to the page, found the download link of the audio file.

DailyStep download link

 

Copied and pasted the url in the browser and the downloaded the file.

https://www.dailystep.com/en/download/file/fid/13531

Just change the fid in the url and tried to download some random file with file id.

I thought what the Shit!  

I then look around which drupal module has provided this route.After checking I got to know that this is the download file module which provides this route.After checking I assume that it might be permission stuff problem.

I found the similar permission problem on the drupal.org as well https://www.drupal.org/node/2394993

Trust is the Major Strategy in Security of any web application.We should be sure which user role we should assign which permissions.

Note: Published the post after suggesting the fix to the site owner Jane

Jan 23 2015
Jan 23

Was looking out some good English Speaking training course website for my cousinto become a fluent English speaker.


On opening the homepage I found the section "Free trial".

I did the same thing as all guys do.Click on the Free trial link,created my account.I personally feeling happy to get the 5 free audio English lessons.
I clicked on one of my lessons link and come to the page, found the download link of the audio file.



Copied and pasted the url in the browser and the downloaded the file. https://www.dailystep.com/en/download/file/fid/13531 Just change the fid in the url and tried to download some random file with file id. I thought what the Shit!   I then look around which drupal module has provided this route.After checking I got to know that this is the download file module which provides this route.After checking I assume that it might be permission stuff problem.
I found the similar permission problem on the drupal.org as well https://www.drupal.org/node/2394993
Trust is the Major Strategy in Security of any web application.We should be sure which user role we should assign which permissions.
Note: Published the post after suggesting the fix to the site owner Jane
Nov 10 2014
Nov 10

Breadcrumb

  1. Home /
  2. Blog /
  3. Awesome weekend by porting a drupal 7 module to drupal 8

Published 2 years ago

Last updated 1 month ago

 have recently joined QE42 pune, As the drupal 8 module port code sprint will happen in
QED42 on 8 November,2014 https://groups.drupal.org/node/448748 and It was postponed later and I was unaware of that.
So I decided to port a module, so I picked a random project from the code reviews done by me from project applications.
So I picked Anonymous suggestion box and ported the module code to drupal 8 and created its meta in the module issue queue https://www.drupal.org/node/2371803

After that I have the time left for code writing so I decided to pick another one jquery carousel and ported half of its code to drupal 8 https://www.drupal.org/node/2371855
If anyone wants to join hands while porting this module then tweet me over twitter lets finish this before this week end and will take another one for next week end.

Waiting for the postponed sprint to meet #pune drupalers over there.

Nov 10 2014
Nov 10

I have recently joined QE42 pune, As the drupal 8 module port code sprint will happen in
QED42 on 8 November,2014 https://groups.drupal.org/node/448748 and It was postponed later and I was unaware of that.
So I decided to port a module, so I picked a random project from the code reviews done by me from project applications.
So I picked Anonymous suggestion box and ported the module code to drupal 8 and created its meta in the module issue queue https://www.drupal.org/node/2371803

After that I have the time left for code writing so I decided to pick another one jquery carousel and ported half of its code to drupal 8 https://www.drupal.org/node/2371855
If anyone wants to join hands while porting this module then tweet me over twitter lets finish this before this week end and will take another one for next week end.

Waiting for the postponed sprint to meet #pune drupalers over there.

Oct 29 2013
Oct 29

Breadcrumb

  1. Home /
  2. Blog /
  3. Drupal site Performance tips

Published 3 years ago

Last updated 1 month ago

Here are some of the Performance tips for the Drupal site.

  1. APC : APC (Alternative PHP Cache) is a PHP OP code cache. It is a very quick win when working with PHP and can offer a great performance boost when using Drupal. It is very much a “set it and forget it” type of application which can just be installed, enabled and left to do it’s thing.
  2. Memcache : Drupal's support for memcache is really good and easy to implement.There is a memcache drupal module(https://drupal.org/project/memcache) to integerate the memcache on the site.
  3. Varnish : When you have a lot of anonymous users reverse proxy cache can save you a lot of server load. Varnish is one of the more popular solutions within the Drupal world. Varnish sits in front of your web server application, for example Apache, Nginx or lighttpd, and can run on the same server or a remote server.Use the varnish module to integrate the varnish on your site https://drupal.org/project/varnish
  4. Boost : Boost provides static page caching for Drupal enabling a very significant performance and scalability boost for sites that receive mostly anonymous traffic. For shared hosting this is your best option in terms of improving performance. On dedicated servers, you may want to consider Varnish instead. When the page is then requested it is loaded quickly, because it is coming straight from the disk and no PHP or MySQL processing is needed.See the Boost module here https://drupal.org/project/boost
  5. CDN : A CDN is used to distribute static assets such as images, documents, CSS and JavaScript across many locations.The goal of a CDN is to serve content to end-users with high availability and high performance.There is a CDN drupal module(https://drupal.org/project/cdn) to use the Content delivery Network.
  6. Disable Database logging module : This module logs the action performed on the site to the database.Use syslog module which is also in drupal core.Using syslog you can also write the more technical log entires to the server's standard log on the file system and save the database queries.
  7. Enable Page & Block Cache : Enable Drupal caching (Administer > Configuration > Performance). When enabled, Drupal will render the page and associated blocks once, and then save that result in the database. This can drastically reduce the number of database calls run on a page since the results are pre-rendered. Drupal’s caching engine is most effective for anonymous visitors – if your site is mostly “read only” and doesn’t have visitors logging in, caching can make a dramatic improvement in site load speed.
  8. Increase Cache Lifetime : An option for some sites may be to increase the cache lifetime. This determines how long Drupal will hold onto a cached result before it will re-generate the page. If you have frequently changing content, you may want to set the cache lifetime to only 5 minutes, but if your content doesn’t change often, an acceptable value may be several hours.The cache lifetime depends on your site usage.
  9. Optimize JavaScript and CSS Files : Enable the option of optimize javascript and CSS files in the performance settings. When enabled, Drupal will consolidate all CSS and JS files included on each page into a minimum files, and compress the code by removing whitespace. This will reduce the overall file size and improve page load speeds.if you need more aggeration of css and js files then use Advanced CSS/JS Aggregation module https://drupal.org/project/advagg
  10. Disable Un-used Modules from the site .

if you have done all the performance tips written above and you are still getting the performance problems then either get the suggestions from the High performance drupal group https://groups.drupal.org/high-performance

There are also some of the related performance related articles.See there links below

  1. http://www.creativebloq.com/web-design/drupal-performance-tips-9122837
Oct 29 2013
Oct 29
Here are some of the Performance tips for the Drupal site.

  1. APC : APC (Alternative PHP Cache) is a PHP OP code cache. It is a very quick win when working with PHP and can offer a great performance boost when using Drupal. It is very much a “set it and forget it” type of application which can just be installed, enabled and left to do it’s thing.
  2. Memcache : Drupal's support for memcache is really good and easy to implement.There is a memcache drupal module(https://drupal.org/project/memcache) to integerate the memcache on the site.
  3. Varnish : When you have a lot of anonymous users reverse proxy cache can save you a lot of server load. Varnish is one of the more popular solutions within the Drupal world. Varnish sits in front of your web server application, for example Apache, Nginx or lighttpd, and can run on the same server or a remote server.Use the varnish module to integrate the varnish on your site https://drupal.org/project/varnish
  4. Boost : Boost provides static page caching for Drupal enabling a very significant performance and scalability boost for sites that receive mostly anonymous traffic. For shared hosting this is your best option in terms of improving performance. On dedicated servers, you may want to consider Varnish instead. When the page is then requested it is loaded quickly, because it is coming straight from the disk and no PHP or MySQL processing is needed.See the Boost module here https://drupal.org/project/boost
  5. CDN : A CDN is used to distribute static assets such as images, documents, CSS and JavaScript across many locations.The goal of a CDN is to serve content to end-users with high availability and high performance.There is a CDN drupal module(https://drupal.org/project/cdn) to use the Content delivery Network.
  6. Disable Database logging module : This module logs the action performed on the site to the database.Use syslog module which is also in drupal core.Using syslog you can also write the more technical log entires to the server's standard log on the file system and save the database queries.
  7. Enable Page & Block Cache : Enable Drupal caching (Administer > Configuration > Performance). When enabled, Drupal will render the page and associated blocks once, and then save that result in the database. This can drastically reduce the number of database calls run on a page since the results are pre-rendered. Drupal’s caching engine is most effective for anonymous visitors – if your site is mostly “read only” and doesn’t have visitors logging in, caching can make a dramatic improvement in site load speed.
  8. Increase Cache Lifetime : An option for some sites may be to increase the cache lifetime. This determines how long Drupal will hold onto a cached result before it will re-generate the page. If you have frequently changing content, you may want to set the cache lifetime to only 5 minutes, but if your content doesn’t change often, an acceptable value may be several hours.The cache lifetime depends on your site usage.
  9. Optimize JavaScript and CSS Files : Enable the option of optimize javascript and CSS files in the performance settings. When enabled, Drupal will consolidate all CSS and JS files included on each page into a minimum files, and compress the code by removing whitespace. This will reduce the overall file size and improve page load speeds.if you need more aggeration of css and js files then use Advanced CSS/JS Aggregation module https://drupal.org/project/advagg
  10. Disable Un-used Modules from the site .

if you have done all the performance tips written above and you are still getting the performance problems then either get the suggestions from the High performance drupal group https://groups.drupal.org/high-performance

There are also some of the related performance related articles.See there links below

  1. http://www.creativebloq.com/web-design/drupal-performance-tips-9122837
Oct 29 2013
Oct 29
There are many service providers in the world that provide drupal related services.As per the drupal marketplace some of the providers are Featured(those which have an exceptional community contributions and show continued support of the Drupal project) and others are not Featured.See the Top 10 Featured service providers here https://drupal.org/drupal-services.you can filter them according to the Services,location and sectors.

When hiring a Drupal site developer it's important to understand what you need and where you can find the service provider with that set of skills.you can find the detail here https://drupal.org/node/51169

if you are getting some problem while hiring a Drupal Developer then feel free to contact me using my contact form.

Jul 11 2013
Jul 11
How to create the node programmatically in drupal 7 with Reference field modules either References or Entity Reference(that is in drupal 8 core now).

Also find the below example of creating a simple node with page type with Title,Description and a Reference(References or Entity Reference) fields.

$node = new stdClass();
$node->uid = 1;
$node->title = 'Title of the Field';
$node->status = 1;
$node->comment = 1; //Hidden the Comment on the node
$node->promote = 1;
$node->sticky = 0;
$node->type = 'article';
$node->created = '';
$node->changed = '';
$node->timestamp = '';
$node->body['und'][0]['value'] = 'Full Story';
$node->body['und'][0]['summary'] = 'Summary';
$node->body['und'][0]['format'] = 'full_html';
$node->revision = 0;
$node->field_entity_reference['und'][0]['target_id'] = 50;
//Here field_entity_reference is the name of the Entity Reference Field and 50 is the nid of the reference node.
$nid = node_save($node); Here field_entity_reference is the name of the Entity Reference Field and 50 is the nid of the reference node.
you will get the $nid after saving the node
Jul 09 2013
Jul 09

How to create the node programmatically in drupal 7 with Reference field modules either References or Entity Reference(that is in drupal 8 core now).

Also find the below example of creating a simple node with page type with Title,Description and a Reference(References or Entity Reference) fields.

$node = new stdClass();

$node->uid = 1;

$node->title = 'Title of the Field';

$node->status = 1;

$node->comment = 1; //Hidden the Comment on the node

$node->promote = 1;

$node->sticky = 0;

$node->type = 'article';

$node->created = '';

$node->changed = '';

$node->timestamp = '';

$node->body['und'][0]['value'] = 'Full Story';

$node->body['und'][0]['summary'] = 'Summary';

$node->body['und'][0]['format'] = 'full_html';

$node->revision = 0;

$node->field_entity_reference['und'][0]['target_id'] = 50;

//Here field_entity_reference is the name of the Entity Reference Field and 50 is the nid of the reference node.

$nid = node_save($node);

Here field_entity_reference is the name of the Entity Reference Field and 50 is the nid of the reference node.

you will get the $nid after saving the node

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web