Planet Drupal

Anchors Panels Navigation Module as an Excellent Alternative to Single Page Website Module

Background

Several years ago I was working on my personal Web site. Even in that time One Page solutions were very popular for some presentation, personal or CV pages.

The main idea of such approach to put all information on one long page with several link anchors corresponding some separate sub-sections of this page.

In 2011 Single Page Website module was created. Initially my home page was done on the base of this module.

Single Page Website module is good out of box solution for Drupal beginners but it has a lot of weak points connected with it's architectural solution. Some more information about this module you can see in my report on Kiev Drupal Camp 2011.

Frustration due to Single Page Website module

It was my fault to build single page on the base of my custom solution without some prepared and ready to use approaches (Views or Panels for example) that can put several nodes or other content entities together on one page. And according incorrect architecture Single Page Website module has a lot of restrictions. The most significant one is theme restriction. Module works with limited number of themes. Also on the module there is out of box ability to have only one page with anchor navigation from menu.

So we should have only one language One Page Website. And the last frustrated feature of the module we should have anchors links in menu only without links to some internal or external pages.

New Approach based on Panels

I'm start working on the other solution about one year ago, see my post Anchors Panels Navigation Module. And now I have some stable version of Anchors Panels Navigation Module with no theme restriction and with manual anchor name management.

Of course, new approach is Panel based and it require several modules to be installed. Also to set One page website driven on Anchors Panels Navigation module takes more time than on the base Of Single Page Website one. But this solution more flexible. You can use several menus, and links in blocks and content for one page navigation. Also you can use this module to set on your site several Landing Pages and the number of such pages is not limited!

If you would like to set Landing Page solution on the base of Anchors Panels Navigation module you should do a lot of manual work in Drupal admin area.

  1. In addition to setup this module you should create node with type Panel and put several pieces of content in the panes.
  2. Set CSS IDs to each pane that should have #anchors. The name of #anchors will be equal to the names of CSS IDs.
  3. To set links in menu with #hashes. You can use absolute links to your site (like I use on my personal site) or use Void Menu Module (I think it is overkill approach).
  4. To make this menu fixed in the browser window. You can use Code per Node module or Floating Block module or, of course, put required CSS code directly in your theme.

After this steps Anchors Panels Navigation module module will take care about scroll to you anchors when visitors will click to the links and about #hash changing in browser address string. By the fact this new approach less complex than Single Page Website module. It has less PHP and JS code and cause less problems to the site developers I hope :-)

What will be the next step?

After one year of developing and using this module I find out that "Anchors Panels Navigation" is not good name for this module according marketing view. It reflects some architectural semantic core of the module but there is no any ideas about module applying in the name of the module. So I would like to ask Drupal community about better name for this module.

Other solutions

It is fair to mention some other solutions belong to the other developers.

There is Drupal Distribution One Page CV created by Ukrainian Drupal Developer Artem Shymko.

There is Single Page Site module developed by Belgium Drupal Developer Robin Ingelbrecht. This module has no theme restriction such as Single Page Website module but there is no ability do more than one Landing Page into one Drupal site also there is no anchors in address line that does not allow to send link on separate block in the One Page site. But in this module there is beautiful Next Page submodule, and it works perfect, see http://www.starfisk.com.

Please let me know is there are some other Drupal based solutions that I should mention here.

7 Helpful Drupal Modules for Webmasters and Site Admins

In this post I'm not going to describe extremely great modules that you must use on each your Drupal site such as Backup&Migrate module or Views module etc. This modules you can use in some separate cases but they can improve support of your Drupal sites!

Profile Switcher

https://www.drupal.org/project/profile_switcher

If you have old site that was done many years ago and maybe upgraded for example from previous Drupal branch, say from D6 to D7. Than you can face with Distribution name Notice.

Notice: Undefined index: distribution_name in drupal_install_profile_distribution_name()...

You can google this issue and find solution, for example

UPDATE `my_database_name`.`system` SET `status` = '1',
`info` = '' WHERE `system`.`filename` = 'profiles/demo_profile/demo_profile.profile';

or
UPDATE `system`
SET `status` = '1'
WHERE `filename` = 'profiles/standard/standard.profile';

But it can not help in my case, when I use my own custom profile. But it does have sense to switch to Standard one to have easy Drupal core updates etc.

And I was happy when I found Profile Switcher.

I think when project start to save some time in development we start with some Drupal distribution to have already prepared set of modules. But during project life some modules are turned off and some new modules are installed. Thus we go far from initial Drupal distribution. And some times we find a decision to switch Profile name to Standard...

User One

https://www.drupal.org/project/userone

I have my common practice to create for the client some separate admin user with abilities that they need only without any complex and extra admin items. Not qualified user can brake Drupal site if we provide him or her Drupal Superuser account. But sometimes we need to delegate to the client admin ability to manage users. And OMG, they can delete First Drupal user, for example. In this case User One module must be installed! After that your First Drupal user will be protected.

Bootstrap optimizer

https://www.drupal.org/project/bootstrap_optimizer

I think each Drupal developer noticed that after some long development activity when you install and uninstall a lot of modules and themes trying to find optimal solution for your project than Drupal become crazy slow. It is due to some out of date data in "system" table. Bootstrap optimizer fix this issue.

Floating block

https://www.drupal.org/project/floating_block

This module helps you to create menu that will be already on the screen or some permanently visible informational block, for example contact form. I have found it useful together with my new Anchors Panels Navigation module.

Node Convert

https://www.drupal.org/project/node_convert

During production life time of each Drupal sites some new features appear and they require new type of content. Also some old nodes should be converted in new content types with new fields. For example several years ago I'm working on Music School site where we have Teacher profile content type. Client would like to add gallery ability for some separate VIP teachers. New Profile content type was created and some separate profiles was converted to new content type. By the way module Node Convert allow to set some mapping rules during conversion process.

Code per Node

https://www.drupal.org/project/cpn

I tried this module at first when I did video background in the header on one of page of the project of my client. It was separate page with video background and we no need to use this feature on any other pages. So I put VideoBG Jquery script, settings and paths to my HTML5 video files in the JS field in node edit form. This module provide an ability to customise pages directly from admin area without theme edit. I think it is reasonable to do when this custom JS or CSS behaviour strongly connected with current node content and thus we do not loose this behaviour when we will switch from one theme to another one.

Void Menu

https://www.drupal.org/project/void_menu

I think every Drupal Developer use placeholder in menu that make Drupal point to the front page of the site. Void Menu module allow Drupal admins to set their own tags with some replacement rules. The most easy example, we can set in menu hashes pointed to anchors on the current page. I have found this module extremely perfect together with me new module Anchors Panels Navigation.

Turn off maintenance mode on separate paths in Drupal 7

We have faced with the problem. We use Ajax Login/Register module but put site in Maintenance mode.

But we need to have Sign up ability. Ajax Register module show Sign up form in popup, content is requested from "ajax_register/register". But in maintenance mode we can see Maintenance page response...

But fortunately we have hook_menu_site_status_alter. Thus we can turn off Maintenance mode in our module on separate path:

<?php
function ajax_register_fix_menu_site_status_alter(&$menu_site_status, $path) {
  if (
$menu_site_status == MENU_SITE_OFFLINE && user_is_anonymous() && $path == 'ajax_register/register') {
   
$menu_site_status = MENU_SITE_ONLINE;
  }
}
?>

This is content of ajax_register_fix.module custom module.

Anchors Panels Navigation Module

Several years ago I have a dream to put my own personal site into One Page solution.
Due to I'm Drupal developer Drupal was selected as platform for my site.
Thus Single Page Website Module was done.

This module is some kind of out of box solution. One can turned it on, do several settings on the module settings page and have One Page website on Drupal CMS engine.

But due to architecture of the module it has a lot of significant restrictions that will be difficult to resolve. The main problem is the limited number of themes that people can use with that module. By the fact Bartik theme and it's subthemes only works correct with the module. This issue connected with some automatic actions that module should perform with page template to make it One Page site.

There are a lot of other issues and limitations that restrict significantly abilities of Single Page Website module. There is no any multilingual support and there is no ability to set two One Page Landings, there is no ability to have link in menu that go to the separate Drupal or external page and so on, and so on...

The talk about weak and strong points of Single Page Website module is out of scope of this post, I'm ready to provide my thoughts but in the other post that will be created soon I hope :-)

The topic of this post is Anchors Panels Navigation Module. What made me make a second approach to the One Page site on Drupal? I think that if we can use higher layer of abstraction in the architecture we can avoid any theme dependence. But we should find some kind of wrapper to combine our One page site from different content parts.

I have used Panels module. If you would like to create some Landing Page with anchor navigation inside it, please use Anchors Panels Navigation module. Please use development version it should works, but some decoration moments I should finished before an official release.

There are several simple steps that you should do to obtain One Page site on the base of Panels with anchor navigation:

  1. Turn on Anchors Panels Navigation module. Panels, Panel nodes and Ctools are required also.

  2. Create several pages with content that you would like to have on One page Panel
  3. Create Panel an put nodes that you did on previous step into the Panel areas.
  4. For each region that you would like to have anchor set CSS id in Panels settings.

  5. Put several links to created Panels node with anchors equal the IDs into any Drupal menu. You can have some other links in that menu too.

  6. Now you have Landing Page with anchors. The module does not provide any CSS altering of the page so to set your menu in fixed position you should do some CSS changes manually. I found CSS Injector module is helpful to set some specific CSS rules on the separate Palels page.

The results here: http://apn.yaremchuk.ru

Feel free to ask any questions and send any ideas about that approach. Thanks!

Don't forget to check Backup&Migrate settings after D6 to D7 upgrade!

Several days ago we upgraded simple Drupal 6 site to Drupal 7. After core upgrade process was finished we turned on all necessary modules such as Admin menu and Backup & Migrate.

Some features required custom update by scripts and some manual work, we made backup before this activity.
... something went wrong and we go back by restoring DB via Backup&Migrate module and site wend down :-(

When we took a look on DB backup script we found that there was empty dump with the structure of some tables.
So as a result the data in several tables was killed.

When we repeated upgrade process again and took a look on Backup&Migrate advanced settings we were shocked

incorrect table exclude settings

By some reason all tables was excluded from backup.

After we align B&M settings backup became works correctly :-)

The main idea of this post due to automatic upgrade process you should double check settings of contributed modules, upgrade can make them different according initial state.

And, of course, backups is necessary part of site development activity but you should be sure that your backups correct.

How to delete users without any role in Drupal 7

We faced of one of the projects that we supported with large amount of spam registrations. But there were valid users with assigned roles that should not be deleted.

Short script was written to resolve this task:

<?php
require_once './includes/bootstrap.inc';
define('DRUPAL_ROOT', '<path_to_you_Drupal_folder>'); // optional
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); // load Drupal to use Drupal API
$query = 'SELECT users.uid as uid FROM {users} LEFT JOIN {users_roles} ON users.uid = users_roles.uid WHERE users.uid != 0 AND users_roles.uid IS null ORDER BY users.uid DESC LIMIT 300';
$result = db_query($query);
while (
$row = $result->fetchObject()) {
 
user_delete($row->uid);
}
echo
'300 spam users were deleted!'
?>

Let me explain this code in details:

If we would like to use Drupal API and DB connection in any separate script not in our custom Drupal module we need to start with these lines:

<?php
require_once './includes/bootstrap.inc';
define('DRUPAL_ROOT', '<path_to_you_Drupal_folder>'); // optional
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); // load Drupal to use Drupal API
?>

Attention! You should put your path instead ''.
Some times script can work without 'DRUPAL_ROOT' definition, but some times can't like in our case.

Authenticated User role ID is 2. But there is no any record with that role ID in {users_roles} table, so we should select all user IDs that have no records in {users_roles} table users_roles.uid IS null.

And do not forget to exclude Anonymous user record users.uid != 0.
Other wise we can delete record with 0 UID from {users} table, that serve for Anonymous user purpose.

Start to delete most resent users ORDER BY users.uid DESC.

Due to user_delete() function require pretty large number of SQL requests it is reasonable to set some limit LIMIT 300.

If there are a lot of spam users you can set cron task, for example:

*/02 * * * * /usr/bin/wget -O - -q -t 1 http://your_site.com/your_script_name.php >/dev/null 2>&1

Swipe Photo Gallery

We are happy to inform you that we have put new beautiful photo gallery module on Drupal.org

Project page: https://drupal.org/project/swipe_photo_gallery

This module show the matrix of images on one separate page. User can see only one page in matrix and go to the next with Up, Down, Right or Left key or using swipe in Up, Down, Right or Left direction.

You can see demo on http://carolsachs.com/overview
We have done site of Carol Sachs and understand that there are some custom solutions that we must share with world Drupal community.

The simple instruction how to use this module:

  1. Turn on module as usual drupal module.
  2. Check that you use Jquery 1.7 or higher with Jquery Update module!
  3. Put several nodes with Slide content type. This content type will appear automatically.
  4. Go to the configuration page admin/config/media/swipe_photo_gallery and set path where you would like to show your slides.
  5. Go to this page and enjoy your slides.

Feel free to send us any recommendations and ideas that can improve this module!

How to Add Circle Image Style into Rotating Banner SlideShow

During update work of the site of our Drupal department (http://php.sfdev.com) we faced following task: to upload rectangular images but to show circle ones on the pages of our site.

In the case if we are going to display circle image form Image or Media field it is easy to set image style preset and use it in the field display. But Rotating banner (https://drupal.org/project/rotating_banner) does not allow to use image styles without hack module.

It is extremely worth practice to hack contributes module even in no feather development status :-)

But how can avoid to hack module and use image style to make image be circle?

By the way to do circle images with image style preset you can use ImageCache Action Module (https://drupal.org/project/imagecache_actions)

Ok, back to our task. We can try to use hook_preprocess_image(). In our theme template.php file we put following code:

<?php
function sfdev_preprocess_image(&$vars) {
  if(isset(
$vars['attributes']['class']) && $vars['attributes']['class'] == 'rb-background-image') {
   
$url_splits = explode(variable_get('file_public_path', conf_path() . '/files/'), $vars['path']);
   
$vars['path'] = image_style_url('circle', file_build_uri($url_splits[1]));
  }
}
?>

Fortunately each rotating banner add 'rb-background-image' to each image. So we can separate this kind of images from the other ones:
if(isset($vars['attributes']['class']) && $vars['attributes']['class'] == 'rb-background-image') {

Before implementing hook_preprocess_image we should create 'circle' image style to use it in this function.
To make Drupal create circle image we should just simply request it via image style URL:
image_style_url('circle', file_build_uri($url_splits[1]));
So the main idea to put image style URL instead original one.

By the way, after some discussions we decide to create circle images manually, because in some cases they should not be circle :-)
And these cases are not predictable :-(

We should not use a drupal_goto function in our module hooks!

Today one of my colleague nortmas had explained to the young developers one not obvious but extremely important point. In the begin of my career of Drupal developer I often did that kind of mistake.

I would like to share with us his message:

You should not put drupal_goto() into the hooks of our custom module!

Why?

Because our hook function is into the queue of the other functions that represent the same hook in the other contributed and custom modules. The order depends on the weight of the module and alphabetic order in the case of equal weights.

In the case if you will put drupal_goto in your hook function code, you will take away the ability to do necessary actions of the modules that located in the back of the hook order queue.

In any case you should avoid drupal_goto() function in your code because it indicated poor codding style like for example goto operator in classic C language.

Thank you, Dmitry for that helpful blog topic!

Cursor Easy Change module

We, like any active Drupal team, faced with the task of recruiting new staff. To begin with, to cut off unwanted people, the usual step is the test task. Commonly in our practice we ask the applicant to create simple module. But Drupal has a lot of contributed modules that cover all needs of ordinary developer. So if we ask applicants to repeat some existing solution they can look for contributed solution... Yes, it is good skill to easy implementation of contributed solution with some customization. But we would like to see how applicant will create solution from scratch. Recently we have to propose the most amazing tasks, which may be completely useless, just for fun only.

Below I would like to show the result of such test task, that was successfully done.

Every beginner in the web development area is seeking to add to the site as many different effects as it possible, wanting to impress site visitor. A little creative effects, which can easily to surprise is custom cursor on the site. We ask the applicant create Drupal module that will provide to the admin of the site the set of cursors to apply via CSS.
You can find the result in the sandbox project.
Also one can download archive here.

The solution is really simple. The form of theme settings is altered.

There is no ability to upload cursors but there are several cases that we can use to show the ability of such kind of effect.
In addition in the module there is function that stores the selected version of the cursor in the system variable and hook_init, which adds the necessary CSS file.

It is really easy module so the main question to the community:

Whether it should stay in the sandbox?

Or we should modify it by adding the ability to load custom cursors and make a full project?

Pages