Showing posts with label Drupal. Show all posts
Showing posts with label Drupal. Show all posts

Monday, December 30, 2019

Drupal 8 aggregator workflow

Drupal aggregation has 2 different elements that are compressing the content on temporary files.
  1. JS
  2. CSS
Whenever we are enabling the aggregation in drupal. It will create a file in /sites/default/files/css 
and /sites/default/files/js folder with file contents. This file name will be stored in a cache table
called “cache_data”. If you delete any one of the files, it will keep on cache content and will try
to find the JS and CSS from this table.

If you opted for the drupal aggregation, make below steps are followed as drupal administrator
  1. Keep ready all JS and CSS files in the themes folder (themes/themesname/css and themes/themesname/js)
  2. Clear the cache (Configuration > Performance)
  3. Activate the aggregation in drupal CMS (Configuration > Performance)
After activated the above steps, you can find the compressed files on sites/default/files/css and
sites/default/files/js folder. 


Execute the below query in mysql DB, to find the list of aggregation entries are exists in the table


SELECT * FROM `cache_data` WHERE cid like 'css%' OR cid like 'js%'





In all terms of CMS we will have 2 views on systems. One is Site Administrator view (Drupal admin view)
and end user view (Public view)

Aggregation will be enabled in drupal admin section JS and CSS. It's up to the site
administrator option to enable both options or either one of them to be aggregated.
As soon as we opted for the aggregation in the drupal admin panel. On the next page load, it will start
picking up the JS / CSS from the public temp location of drupal, where we opted during the site setup.
This temp file will always be upto date, even if we have not opted for the aggregation.
When we opted for the aggregation, site JS / CSS will be on top of it.

Thursday, October 15, 2015

Creating content type tpl file in drupal 7

In Drupal 7, Page.tpl.php will be the default template file for whole site. In top of this, we can customize our template for different content type, individual nodes and front pages. Even we can customize the block template and views templates.

In this blog post, i am going to give you small snippet of code for creating template file depends on content type.

To create a template file for content type, First step we need to define in template.php file on hook_preprocess_page method.


After included in template.php we need to copy the page.tpl.php. Paste in same folder, rename it according to you content type.

For example:- My content type name is reviews. My file name should be page--reviews.tpl.php

In this file, you can customize your design.

Tuesday, September 22, 2015

Get node content using node_view and node_load in drupal 7

Drupal 7 has vast functions to manipulate node and its content. Here i have gave you the piece of code to get node content using node id.

Thursday, January 9, 2014

Call content type form in custom module with Drupal 7

Here we have realtime syntax to call content type form in drupal 7. It will allow you to call add form of particular content type.

To use this code, please add some custom module with menu hook. For menu hook, Have the callback function with below code. You will get the form to submit your values.

Wednesday, December 25, 2013

Enable default token values in drupal 7

To enable the default token to be display in the drupal site. We have to install separate module to do the same. This module will allow the content type field to enable and replace with particular token.

You download the module here.

Steps to install

  1. Download the module from this location and extract it.
  2. Extract folder should be placed in /sites/all/modules folder.
  3. Then, Login as administrator in site.
  4. In admin menu, Please click on module menu.
  5. In the list modules, You will able to see the "Field default token".
  6. Please check the checkbox, which is row of same module.
  7. Then, scroll down and click "Save Configurations".
Now, you module will start to work on the same. Please give some default token in text field of content type and check.

Monday, April 8, 2013

Create a block using custom module in drupal 7

In this post, we will discuss about creating block using custom module in drupal 7. The main benefit of build a block using custom module is connectable module. This code will act as separate connectable component.

In Drupal 6, there is only one hook used for all block operations but now in Drupal 7 there are different functions for different operations of the blocks. This are the hook method provided by drupal 7 for build a block.

hook_block_info()
hook_block_configure()
hook_block_save()
hook_block_view()
hook_block_list_alter()
hook_block_view_alter()
hook_block_info_alter()
hook_block_view_MODULE_DELTA_alter()

Here we will discuss through different steps.

Step : 1
We need to create a directory in this path "sites/all/modules". i.e you need to create a new module folder inside drupal directory. Directory name must under-stable and meaningful related to your module purpose. I will named as "customblockmodule" for module directory.

We should have this two files inside directory.
1. customblockmodule.info
2. customblockmodule.module

Step : 2
Now we have to write a content for customblockmodule.info file.
Here we have mentioned name,description,core and package. Core  will have the drupal version for this module and package will define the area of module to be placed in module section.

Step : 3
In this module file, First we have to mention about info method

hook_block_info()  : This is used to tell Drupal about the new block or blocks that we will create. Drupal will display the block in the block list in the admin.

An implementation of hook_block_info() takes no arguments and is expected to return an associative array.
This defines a block named “custom_bk_module” that has two properties:

Info: This provides a description about the block. The text is used on block list in admin.
Cache: This tells Drupal how to cache the data from this block. In above example, I mentioned DRUPAL_NO_CACHE which tells Drupal not to cache the block.


hook_block_view() : Will demonstrate about view of the block. It will hold the content of the block. When page requesting to view a block, this method will get called.