Monday, April 4, 2022

Drupal 8 and Drupal 9 Out of the box Features

Out of the box Drupal 8 & 9 provides with the below Features: 

1. WYSIWYG authoring and editing tool that allows editors and admins to easily manage content 
2. Layout Builder - Easily Build engaging pages with templated layouts and drag-and-drop UI for placing content on the page 
3. Customizable workflows and approvals, as well as revisions, so that you can track every content update and revert to a previous version 
4. Media supports local audio, video, images, files, as well as remote content from YouTube, Vimeo, Twitter, etc. 
5. Media Library allows users to add existing media assets to a site as well as upload new items directly into the library 
6. Performance-optimized caching mechanisms 
7. Theme system enables you to create a completely custom, responsive front-end according to brand guidelines and using your framework of choice 
8. Recommended add-on (contrib) modules 
9. Easy-to-use form builder to create anything from a simple contact form or survey to complex, multi-step application forms 
10. Schedule when your content is published in advance 
11. Customizable, user-friendly URLs and configurable metatags for every piece of content 
12. Robust search experience and integration with enterprise-grade search engines (Elasticsearch or Solr) 
13. Migrate system allows you to feed data into Drupal 
14. Multilingual content & user interface 
15. Accessibility compliance (WCAG AA) (people with disabilities)

Sunday, June 9, 2013

Custom Pagination for Item_list - Drupal 7

For theme item_list function, pagination is tricky in Drupal 7. It's not straight forward, we need to use couple of methods to achieve it, one is use of pager_default_initialize and the other is use of sliced array to theme item list function. Below is a sample code to achieve it:

$items = array('Sports', 'Business', 'Entertainment', 'Politics');
$limit = 3;
$page = pager_default_initialize(count($items), $limit);
$offset = $limit * $page;
$content .= theme('item_list', array('items' => array_slice($items, $offset, $limit)));
$content .= theme('pager',array('quantity' => count($items)));

Try above example to use simple custom pagination for theme item_list function

Friday, January 14, 2011

Six new Hooks in Drupal 7

1. hook_node_load

- Act on nodes being loaded from the database. This hook is invoked during node loading. This hook should only be used to add information that is not in the node or node revisions table, not to replace information that is in these tables. For performance reasons, information for all available nodes should be loaded in a single query where possible.


2. hook_block split in to 3 hooks as below:

2.1 hook_block_info - Define all blocks provided by the module. In hook_block_info(), each block your module provides is given a unique identifier referred to as "delta" (the array key in the return value). Delta values only need to be unique within your module.

function training_block_info() {
$blocks['customblock1']['info'] = 'Block Created using Training Module';
$blocks['customblock1']['cache'] = DRUPAL_NO_CACHE;
return $blocks;
}

2.2 hook_block_view - Return a rendered or renderable view of a block.

function training_block_view($delta = '') {
$block = array();
switch ($delta) {
case 'customblock1':
$block['subject'] = 'Custom Block1';
$block['content'] = 'Content Created by Custom Block';
break;
}
return $block;
}

2.3 hook_block_configure - Return a rendered or renderable view of a block.

function training_block_configure($delta = '') {
switch($delta) {
case 'customblock1':
$form['customlement'] = array(
'#type' => 'select',
'#title' => t('Number of items to display'),
'#options' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
);
return $form;
}
}

3. hook_css_alter

- Alter CSS files before they are output on the page.

function hook_css_alter(&$css) {
// Remove defaults.css file.
unset($css[drupal_get_path('module', 'system') . '/defaults.css']);
}

4. hook_drupal_goto_alter

- Change the page the user is sent to by drupal_goto().

function hook_drupal_goto_alter(&$path, &$options, &$http_response_code) {
$http_response_code = 500;
}

5. hook_user_view

- The user's account information is being displayed. The module should format its custom additions for display and add them to the $account->content array.

function training_user_view($account, $view_mode, $langcode) {
$account->content['summary']['blog'] = array(
'#type' => 'user_profile_item',
'#title' => t('Blog11'),
'#markup' => l(t('View recent blog entries'), "blog/$account->uid", array('attributes' => array('title' => t("Read !username's latest blog entries.", array('!username' => format_username($account)))))),
'#attributes' => array('class' => array('blog')),
);
}

5. hook_node_view

- Act on a node that is being assembled before rendering. The module may add elements to $node->content prior to rendering. This hook will be called after hook_view().

function training_user_view($account, $view_mode, $langcode) {
$account->content['summary']['blog'] = array(
'#type' => 'user_profile_item',
'#title' => t('Blog11'),
'#markup' => l(t('View recent blog entries'), "blog/$account->uid", array('attributes' => array('title' => t("Read !username's latest blog entries.", array('!username' => format_username($account)))))),
'#attributes' => array('class' => array('blog')),
);
}

Thursday, January 13, 2011

Five New Features of Drupal 7 .info file

1. Drupal 7 now supports a dynamic-loading code registry.To support it, all modules must now declare any code files containing class or interface declarations in the .info file


files[] = example.test

2. As of version Drupal 7.x, the path of the module's (main) configuration page can be given in .info file. This will be the path of the "Configure" link for this particular module on the modules overview page.


configure = admin/config/example

3. As of version Drupal 7.x, modules and themes may specify that they should not be visible on the modules page by adding hidden = TRUE.


4. As of version Drupal 7.x, modules and themes may specify that they are absolutely required and should never be disabled by adding required = TRUE. These modules will be enabled automatically during install. In most cases it should only be used with the Drupal core required modules (e.g. Node, User, etc.).


5. Stylesheets can be included in drupal 7 .info in below format:

stylesheets[all][] = sample.css

Drupal 7 page Layout

The Whole drupal rendering page is now controlled by html.tpl.php and not page.tpl.php as in drupal 6. So to override it copy "html.tpl.php" from system drupal module (Core) and paste it in default theme to override the whole page layout of drupal 7.

But make sure the cache(admin/settings/performance) is cleared after the files are updated in theme.

To override the overlay popup of admin pages, make sure you copy the html.php to theme named "seven".

Friday, October 30, 2009

Drupal In White House

The White House Web site has caught a case of Drupal. The open-source software package helps people create and manage their Web sites. And this week, a new WhiteHouse.gov site arrived that had been built via the Drupal code.

Companies like Nike, Warner Bros. and Yahoo use Drupal for various parts of their Web sites. All told, close to 500,000 Drupal-based sites are on the Web, according to Thomas Erickson, the chief executive of Acquia.

To some, the White House shift to Drupal from a proprietary software package represented a serious seal of approval for open-source software.

“While open source is already widespread throughout the government, its adoption by the White House will almost certainly give permission for much wider uptake,” wrote Tim O’Reilly, who publishes books and holds conferences about open-source software.Like many open-source companies, Acquia sells service and support to back up the free Drupal. It claims about 300 customers, and “that number is doubling every quarter,”

Monday, October 12, 2009

Basic Drupal Notes

Configuration

1. After installation, it is a good idea to set site configuration by going to Administer -> Settings -> Site Information to set email address, slogan, footer, greeting for anonymous user, etc.

2. Create an administer role and assigning permissions.

3. Enables the modules that you want to use by going to Administer -> Site Building -> Modules.. The Path module allows users to create URL alias to pages, which can benefit SEO when pages are named appropriately. These alias can be viewed at Administer -> Url Aliases.

4. Clean URL feature eliminates the query string parameters in the URL path and is recommended for SEO and can be done by Administration - > Settings -> Clean URLs . For this to work, your server must be Apache servers which have the LoadModule rewrite_module and mod_rewrite configured in httpd.conf. In the settings page, there is a test for you to run to see if your server is configured correctly or not. If you enable Clean URL without proper server configuration, you can get back to the admin page to disable the feature by using the non-clean URL of the form http://www.yourdomain.com/?q=admin/settings

5. Whether or not to allow users to post comments to your stories is controlled by Administer -> Content Management -> Content Type -> Edit.

6. You can configure your Contact form by Administer -> Site Building -> Menu -> Contact.

7. If you site is having problems because you are installing Drupal in a subdirectory, you might need to adjust the $base_url property in sites/default/settings.php.


Template Writing

1. Don't use relative image paths in the tpl files. Instead use ...

'< img src="/images/yourimage.gif" />'

2. Drupal caches on the server for non-registered users. So when you make changes to the template, one way to force Drupal to update its cache is to click on "Save Configuration" in Admin -> Site Building -> Modules. Also refresh your browser cache as well. Or you can run "DELETE * FROM cache;" on your database. Also your webhost may be caching. To mitigate that, you can do http://www.yourdomain.com/?dsfkds where the query string is some random characters.

3. If you want to change the User Login block, try to change it with CSS first. If you really want to get to the code, the function starts at user_login_block() in user.module and traces to drupal_render_form() and theme_form_element() and theme_button() in form.inc.

4.
Misc Notes

5. The MySQL username and password access can be found in sites/default/settings.php in the form...

$db_url = 'mysql://username:password@localhost/databasename';

6. If you don't want the login box to be displayed, you can disable the block and use the following to login...

http://www.yourdomain.net/user

or

http://www.yourdomain.net/?q=user

7. You can determine which node id a page is by printing out ...

nid); ?>

Then you can write PHP if condition and apply them to specific pages such as ...

nid == 33) { ?>
< style >
< /style >

Upgrading from Drupal 5 to Drupal 6

MasteringDrupal.com

Thursday, April 23, 2009

FileField and ImageField for Drupal 6 Released

For drupal 6, image field was recenly released where it can be integrated with CCK.Probably the most exciting improvement is the addition of upload progress indication. This enhancement requires the PECL uploadprogress PHP extension, but adds a real asset to sites that use FileField for podcasts, videos, or other large files.ImageField is now completely dependent on FileField for its data handling. This means less duplicated, less bugs, and more compatibility between add-on modules. If an add-on module works for FileField, it automatically works for ImageField. This means that ImageField is now purely a "widget" for CCK, not a "field" any more.

Hook file support

Other modules can use FileField's hook_file() implementation to help determine when and where a file is in use. This means modules like the new FileField Sources module can reuse existing images on multiple nodes, even use IMCE to browse existing images and reuse them (as long as the files are assigned an FID in the database).

Sunday, February 22, 2009

Google Maps in Drupal

Below are some brief instructions on how to use it:

Step 1. Create a map with macro creator

Each site includes a macro to create a map that you can customize it as you see fit. You can see the GMap Macro on my site here. To create a map:

* Scroll to the bottom of the macro to define the Map Height and Map Width. This is in pixels (try "500px" by "500px" to start with) and make sure you include the "px" after the number. Scroll back to the top and you will see the template map has automatically resized.
* Move the map around with the mouse to the area you want to include. Also adjust the zoom control to achieve the level of magnification you want. You can choose between a basic map, a Satellite map or a hybrid version by switching between the buttons.
* You can add points, lines or circles by (single) clicking on the map. You can switch between these options with the pull down menu where it says Click Map. Experiment by clicking around a map to see what happens.
* Some of the line/polygon settings are a little temperamental, but the marker options work well allowing you to change the marker type. It is possible to link one marker to another.
* To remove a marker make sure the Click Marker option is set to "remove" and then click the marker to be removed on the map.
* Each map needs a different name or identifier (set to "map" by default). Type this in to the Map id attribute field. This can only contain numbers letters and the "-" symbol, and must be unique for each map that will appear on the same page.
* The Control feature (None|Large|Small) allows you to specify whether there is a zoom control on the map and what size it is.
* There are all sorts of advanced options available for customizing your map. The most important of these is the ability to have feeds that take information from a local RSS feed with geolocation data and dynamically plot this on the map. I'll blog about this separately when I have figured out how to do it!

Step 2. Put the map on a webpage (node) in your site

Scroll down to the bottom of the macro and copy the Macro Text that appears in the text box. You then need to paste this into the body field of a new page (node). When you do this make sure to disable rich text (just underneath the text box) and under Input Format select the GMap Filter option. You can add any other information to the page with HTML or the rich text editor.Just do not change the GMap Macro text. When you are done, click Submit and the new page with your Google Map and any plotted points, lines or polygons will appear.