Dealing with core Cache in Drupal 8

At this point, if you try to login in the Drupal 8 website you will be rejected, it’s because the login system doesn’t read directly the table users_field_data instead of a cache for entities is used.

To flush the cache for a specific user entity with compromise the rest of cache of your system you can use the following SQL statement.

DELETE FROM cache_entity WHERE cid = ‘values:user:1’;

Now you can grab a cup of coffee/tea and enjoy your Drupal 8 website.

Hope this will help you.


Resetting the administrator password with SQL-query in Drupal 8

It’s has been happening, that we tend to forget password on local as well for the live site. When it’s come to Drupal 8 all things has things changed from the prior version of Drupal.

Here we go with some of the tricks for Drupal 8.

The Solution
Generate a new password
First, you have to generate a password hash that is valid for your site.

Execute the following commands from the command line, in the Drupal 8 root directory:

$ php core/scripts/ ‘your-new-pass-here’

password: your-new-pass-here    hash: $S$EV4QAYSIc9XNZD9GMNDwMpMJXPJzz1J2dkSH6KIGiAVXvREBy.9E

Update the user password.

Now you need to update the user password, in our case, we need to update the Administrator password, fortunately, the UID for Administrator is 1 equal to previous versions of Drupal.

With the new password, we need run the following SQL statement.

UPDATE users_field_data SET pass=’$S$E5j59pCS9kjQ8P/M1aUCKuF4UUIp.dXjrHyvnE4PerAVJ93bIu4U’ WHERE uid = 1;

We all set with password update and go… log in!

Page Rendering and Altering in Drupal

Step 1: The Router Item
After Drupal has been bootstrapped, the last thing index.php does is call
menu_execute_active_handler(). This retrieves the router item from the menu_router based on the
current path. There is an important chance here to intervene, hook_menu_item_alter()

Step 2: The Page Callback Is Fired
For example, the default home page returns this:
$build[‘default_message’] = array(
  ‘#markup’ => “<p>No front page content has been created yet.</p>”,
  ‘#prefix’ => ‘ ‘,
  ‘#suffix’ => ‘ ‘,

Step 3: The Delivery Callback

Now you are back in menu_execute_active_handler(). The next callback to fire is the delivery callback,
which defaults to drupal_deliver_html_page(). As the name suggests, by default you are delivering the
page callback results in HTML.

function overlay_deliver_empty_page() {
  $empty_page = ‘<html><head><title></title>’ . drupal_get_css() . drupal_get_js() .
  ‘</head><body class=”overlay”></body></html>’;
  print $empty_page;

Step 4: drupal_render_page()

First, hook_page_build() is called, which allows other modules to add to the page array—because
here you build that. Your modules can add to the page array, also. Second, hook_page_alter() is fired.

Step 5. hook_page_alter()

Perform alterations before a page is rendered.

Use this hook when you want to remove or alter elements at the page level, or add elements at the page level that depend on an other module’s elements (this hook runs after hook_page_build().
For Example Page rendar hook :

function dgd7_page_alter(&$page) {
 if ($node = menu_get_object()) {
  $comments = &$page[‘content’][‘system_main’][‘nodes’][$node->nid][‘comments’][‘comments’];
  $comments[‘ad’] = dgd7_get_ad();
  // The first comment weight is 0, the second is 1, go between them.
  $comments[‘ad’][‘#weight’] = 0.5;
function dgd7_get_ad() {
  return array(‘#markup’ => t(‘Hello I am an ad!’));

Step 6. drupal_render()
This is a recursive function called on every child of the page array. So you start with running
drupal_render($page), then continue with drupal_render($page[‘content’]), then with
drupal_render($page[‘content’][‘system_main’]), and finally with

So for example:
$element[‘#cache’] = array(
  ‘cid’ => ‘foo:bar’,
  ‘bin’ => ‘cache_something’,
  ‘expire” => 900,

Vim Plugin for Drupal on Linux


The following commands will indent your code the right amount, using spaces rather than tabs and automatically indent after you start. The commands should be added to a .vimrc file in your home directory (~/.vimrc), you may need to create this.
set expandtab
set tabstop=2
set shiftwidth=2
set autoindent
set smartindent

Syntax highlighting

If you enjoy syntax highlighting, it may be worth remembering that many of Drupal’s PHP files are *.module or *.inc, among others.

Vim seems to syntax highlight *.inc files properly by default but doesn’t know that some other files are PHP content. For *.module and *.install, use this snippet in .vimrc:
if has(“autocmd”)
” Drupal *.module and *.install files.
augroup module
autocmd BufRead,BufNewFile *.module set filetype=php
autocmd BufRead,BufNewFile *.install set filetype=php
autocmd BufRead,BufNewFile *.test set filetype=php
autocmd BufRead,BufNewFile *.inc set filetype=php
autocmd BufRead,BufNewFile *.profile set filetype=php
autocmd BufRead,BufNewFile *.view set filetype=php
augroup END
syntax on

more can be done its all open source.. it’s upto you 🙂

Getting Rid Of Magento ReIndexing Errors

If even after trying multiple times Magento Indexer fails to respond or keep throwing same errors you can take the following steps resolve Magento ReIndexing errors.

1. Locate var/locks directory and remove all files under this directory. This will clear all the locks for re-indexing to take place again.

2. Now, login to your MysQSL/phpMyAdmin to run the following MySQL query (Ensure that your have taken full backup before committing this MySQL que

DELETE cpop.* FROM catalog_product_option_price AS cpop
INNER JOIN catalog_product_option AS cpo
ON cpo.option_id = cpop.option_id
cpo.type = ‘checkbox’ OR
cpo.type = ‘radio’ OR
cpo.type = ‘drop_down’;

DELETE cpotp.* FROM catalog_product_option_type_price AS cpotp
INNER JOIN catalog_product_option_type_value AS cpotv
ON cpotv.option_type_id = cpotp.option_type_id
INNER JOIN catalog_product_option AS cpo
ON cpotv.option_id = cpo.option_id

*hope above will helps 🙂

Programmatically Adding a Field Collection Item to a exiting Node in Drupal

In such case where you need to add field item to a node like text,link field's in a node for drupal 7

function my_custom_module_field_collection($nid, $fid){
   // Load target node
   $node = node_load($nid);

   // Create a new field collection 
   $fieldCollectionItem = entity_create('field_collection_item', array('field_name' => 'my_field_collection_item_name'));

   // Prepare link field
   $link = array(
      'title' => "",
      'url' => "",
      'attributes' => array(
         'title' => "",

   // Prepare file 
   $file = (array)file_load($fid);
   $file['display'] = "1";

   // Load items into field collection
$fieldCollectionItem->field_image[LANGUAGE_NONE][] = $file;

$fieldCollectionItem->field_link[LANGUAGE_NONE][] = $link; // Save field collection item

$fieldCollectionItem->setHostEntity('node', $node);

$fieldCollectionItem->save(TRUE); node_save($node);


Disable Outgoing Mail in Drupal 7

* Implements hook_mail_alter
function yourmodule_mail_alter(&$message) {
// set ‘To’ field to nothing, so Drupal won’t have any address
$message[‘to’] = ‘ ‘;

Other Way you can do

If using devel with drupal 6, add to settings.php
$conf[‘smtp_library’] = ‘sites/all/modules/devel/devel.module’;

and all outgoing emails get logged in watchdog.

If using devel with in drupal 7, if you add
$conf[‘mail_system’] = array(‘default-system’ => ‘DevelMailLog’);

emails get written to files in the drupal temporary directory.

Re-route All Emails Using Reroute Email Module

Download and install the Reroute Email module.

Go to Configuration-> Reroute Email (admin/config/development/reroute_email).

And  than Check the Enable rerouting checkbox and enter in an email address into the Email addresses text field.