Link to entity

This Drupal module provides two field formatter for displaying entity reference field.

Link entity belongs to formatter

Link entity belongs to formatter link the current entity to the entity it belongs to. for example, terms in the tags if you want to redirect to node instead of term page.

Link entity query parameter formatter

Link entity as query parameter formatter link the current entity to any specific page and as the query parameter of that field. You have setting page to set the page and query parameter name you need to. for example, category in faq node if you want to /faq view page with filter tid.

How it work

– Create entity reference field the content types.
– Choose the formatter you want to use.
– Start adding content with field.
– See how it works ūüôā


, , ,

Leave a comment

Nice blog to know how override views template in drupal 8

This is one if the blog post regarding views template override in Drupal 8

check the link below:-

Leave a comment

How to get fields list in drupal 8

If you want to get all field list of a specific field type in Drupal 8 there is a easiest way to get them. Lets say you want to get all entity reference fields from all content types.

You just need to use this function in your class. You also need to load entity manager service into class.

$ref_fields = $this->entityManager->getStorage('field_storage_config')->loadByProperties(
        'settings' => array(
          'target_type' => 'node',
        'entity_type' => 'node',
        'type' => 'entity_reference',
        'deleted' => FALSE,
        'status' => 1,

Leave a comment

Call core services of Drupal 8 via the service container

It is not very good way to call Drupal core services directly in the class. Try to avoid such code in your code. Intead of doing that you can inject core services through service containner. Following code will help you to know how you should do that.


   * Database Service Object.
   * @var \Drupal\Core\Database\Connection
  protected $connection;

  public function __construct(Connection $connection) {
    $this->connection = $connection;

   * {@inheritdoc}
  public static function create() {
    return new static($container->get('database'), $container->get('entity.manager')->getStorage('taxonomy_vocabulary')

  public function validatefunction($arg) { 
    $select = $this->connection->select('taxonomy_index', 'ti')->fields('ti', array('tid'));
    $result = $select->execute();

So intead of calling $connection = \Drupal::database(); , you should inject core services into your class visa container service.

Details code you can found :-

Helpful information to read :-

Leave a comment

Create own service for your module in Drupal 8

It is always good to know how to use core services and as well how to create your own service. Following code snippet can help you to do that.

Create custom service into modulename.service.yml

    class: Drupal\content_connected\ContentConnectedManager
    arguments: ["@entity.manager", "@config.factory","@entity.query", "@module_handler","@renderer","@string_translation"]

You can see the details code in (

Module link :-


Leave a comment

Content_connected module in

Content connected is a lightweight module which allow administer to know whether content is connected with some other content before it is about to be deleted from the system. So administer should know whether content should be deleted or not.

Content connected is also added as sub tab in node pages to view content connection with other contents. This can be restricted by permissions for different roles.

Content connection based on entity reference field and any textarea/long field for any content type.

Connected content is listed in a table where it can be identified how it is connected(Reference field or textarea/long field).

, ,

Leave a comment

Similarterms module in

This Drupal module attempts to provide context for content items by displaying a view block with links to other similar content. Similarity is based on the taxonomy terms assigned to content. Views are available based on similarity within each of the defined vocabularies for a site as well as similarity within all vocabularies.

What does this really mean? How should you use this module?

1) Create a freetagging vocabulary called “Tags” assigned to the content types on which you’d like to display the “Similar” view block.
2) Enable the view block called “Similar entries from the Tags vocabulary”.
3) Add keyword tags to the content.

, , ,

Leave a comment

Dynamically change Iframe height for cross domain site.

If you want to make iframe height change dynamically according to content then just use this. .-)

##### External site HTML #####

Add iframe tag with src.
Add js file from library:- http://INCLUDE-JS-FILE_PATH/iframeResizer.min.js

call js function :-



It works using iframe-resizer framework. So the iframe source page also need to include one js file as well.

#### Iframe content site #####
Add js file from library:-

### GIT REPO of Iframe resizer framework(See example/index.html and example/frame.content.html ) ###

Leave a comment

Programmatically create user account in drupal 7

It is the clean and tested code for programmatically create a user account in drupal system. Anyone can use this code according to their requirement and fields.

////// Creating user //////
$password = user_password(8);
$roles = user_roles(TRUE);
$your_rid = array_search(‘YOUR OTHER ROLE’, $roles);
//set up the user fields
$fields = array(
‘name’ => $node->field_mail[‘und’][0][’email’],
‘mail’ => $node->field_mail[‘und’][0][’email’],
‘pass’ => $password,
‘status’ => 1,
‘roles’ => array(
DRUPAL_AUTHENTICATED_RID => ‘authenticated user’,
$your_rid => ‘YOUR OTHER ROLE’,
‘field_first_name’ => array(
‘und’ => array(
0 => array(
‘value’ => $node->field_first_name[‘und’][0][‘value’]
‘field_last_name’ => array(
‘und’ => array(
0 => array(
‘value’ => $node->field_last_name[‘und’][0][‘value’],
‘field_telephone’ => array(
‘und’ => array(
0 => array(
‘value’ => $node->field_telephone[‘und’][0][‘value’],
// First parameter is left blank so a new user is created.
$account = user_save(NULL, $fields);


Leave a comment

SOLVED!! How can you make form_set_error() affect the only form submitted?

Drupal form_set_error() function provide validation message based field name. So if you have same field name in same page , after the submission you can see both fields are marked as red color(Error class). It validate or show message for right form but it provide error class for all element which are same.

I found a way to solve it. If you render those form using drupal_get_form then you can add one extra line in top to get rid of this problem.

for example :-

drupal_static_reset('form_set_error'); // adding this line makes you life out of hell.-)
$form = drupal_get_form('webform_client_form', $node, $submission);
return drupal_render($form);



Leave a comment