Tuesday, January 26, 2021

Drupal 8, 9, Debugging Twig templates, The website encountered an unexpected error

Drupal 8 and drupal 9 is not something we used to, like drupal 7, its is entirely disffrent code base and templating engine. for this new dcenario we need to be able to keep our dubugging skills upto date as the new drupal 8 and 9 thorwing errors on us and if we are able to fix it, chances are, we are going to install fresh copy of drupal each time, thiis is what I have heard from some developers and alos eaperinced in early version of drupal 8.

The website encountered an unexpected error. Please try again later.

This is somthing you will see if each time if having any error in yu code.

1) Goto sites/ and copy example.settings.local.php

Paste in > sites/default and rename it to settings.local.php

2) goto the settings.local.php file and uncomment the following line if commented.

$config['system.logging']['error_level'] = 'verbose';

3) goto edit settings.php in same sites/default directory and uncommnet the following line:

 if (file_exists($app_root . '/' . $site_path . '/settings.local.php')) {

   include $app_root . '/' . $site_path . '/settings.local.php';

 }


Additionally add following line in settings.local.php

error_reporting(E_ALL); ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE);


Above solution will produce all errors on your screen that help you to fix the error.




Monday, January 11, 2021

Drupal 9 is released

On June 30 2020, Drupal 9 is now relased with a stable version. All the reouces from drupal 8 like themes and modules can be use for drupal 9, it share same admin look & feel almost everything look wise.

download drupal 9



Wednesday, May 30, 2018

First step to secure your Drupal website.

Article Series -1
In recent time Drupal faces too many security threats, people around the world claimed that their website hacked. As a website owner or the developer, we need to keep eye on our websites updates and logs.
In this process, Drupal core and other module update is the first and most important step to do.

In this series, we are going to bring you more information about Drupal security.
Keep eye on our blog to get all information about this,

Please take a look

Thursday, May 19, 2016

Connect to multiple databases in Drupal 7 ?

The way Drupal is designed, it handle most of the user demands, sometime most complex one. Here we are discussing the having multiple databases connection in, and i am very much sure that drupal can do it with easy way. More Details

There are two way we can achieve this.
  • Adding database in settings.php file
  • Adding in module as needed (on the fly)

Adding database in settings.php file

You can add your database in settings.php so that all module can use it.  here is sampe, suppose we have new databses "second_db"
$databases = array();
$databases['default']['default'] = array(
  // Drupal's default credentials here.
  // This is where the Drupal core will store its data.
);
$databases['second_db']['default'] = array(
  // Your secondary database's credentials here.
  // You will be able to explicitly connect to this database from your modules.
);

Here is the way we can access this in our module
// Use the database we set up earlier
db_set_active('second_db');
// Run some queries, process some data
// ...

// Go back to the default database,
// otherwise Drupal will not be able to access its own data later on.
db_set_active();

Adding in module as needed (on the fly)

This is used when a single module needs new database  In this case we can desfine our databse connection directly in our module like this.
 $other_database = array(
      'database' => 'databasename',
      'username' => 'username', // assuming this is necessary
      'password' => 'password', // assuming this is necessary
      'host' => 'localhost', // assumes localhost
      'driver' => 'mysql', // replace with your database driver
  );
  // replace 'YourDatabaseKey' with something that's unique to your module
  Database::addConnectionInfo('YourDatabaseKey', 'default', $other_database);
  db_set_active('YourDatabaseKey');

  // execute queries here

  db_set_active(); // without the paramater means set back to the default for the site
  drupal_set_message(t('The queries have been made.'));

Wednesday, May 11, 2016

Workbench module to controle content publishing.


Workbench  module used to controle content in website fron different roles. Content slike blog post. article, page or any other custom content type. To achieve this we need at least tw roles,  a content creator and a content publisher.
Content creator will be able to create content
Content publisher will be able to review/edit/publish content.
Workbench module provides multiple states to content like
DRAFT >> NEEDS REVIEW >>PUBLISH, 
we can also create more states.

Monday, May 9, 2016

How to start Drupal 8 ?


Drupal 8 is a advance version of drupal 7.  It comes with some new, exiting features to to work and learn. Since drupal 8 is released in a stable version we can choose to work and contribute our module, themes, patches, documentation etc.

We can devide Drupal 8 learning in 2 parts
What to learn Befor starting Drupal 8


 What is new in Drupal 8

  • Views and ckeditor in core
  • New fields as, email, telephone references etc.
  • Quick edit on nodes and blocks, titile(helps in better contet authoring)
  • Mobile freindly and responsive images
  • Multilingual
  • Webservices







Tuesday, April 21, 2015

Overriding the user menu title function for change My account as username

Replacing My account label with the username in drupal user menu. I have not found any module for this but we can do it by hacking(Not a good Practice) in Drupal user module file
in modules/user/user.module line:2035
/**
 * Menu item title callback for the 'user' path.
 *
 * Anonymous users should see "User account", but authenticated users are
 * expected to see "My account".
 */
function user_menu_title() {
 //return user_is_logged_in() ? t('My account') : t('User account');
}

Change with
  return user_is_logged_in() ? $GLOBALS['user']->name : t('User account');

Reference
https://www.drupal.org/node/1760634
http://www.ipsure.com/blog/2012/showing-username-instead-of-my-account-in-drupal-7/