Category Archives: Drupal

How-to for Drupal

Drupal 7: Remove “No front page content …” message

Today, I noticed that that Google had found my website and the description showed the Drupal default message “No front page content has been created yet.” Definitely, the front page exists and contained content. However, I had not wanted to create an article page or other item and promote it to the front page. Therefore, Drupal was displaying that message. I had used CSS to hide the phrase, it seemed by a simple solution, but, hiding the content did not hide it from Google … Oops.

An option would have been to recreate the home page and in the administration area request the redefinition of the page to be used as the front page, a page that would not create that message. However, I did not want to recreate the page. I had already created several custom templates, including the page.tpl.php file. However, the message is embedded inside the $page content and printed by the line to render page content:

<?php print render($page[‘content’]); ?>

The question became, how do you remove the particular content and not damage the page as a whole. the answer is to unset the undesired content. the following command at the top of the page.tlp.php file removes the desired message without damaging anything else:


   
    <?php if(drupal_is_front_page()) {
              unset($page['content']['system_main']['default_message']);
          } 
     ?>

This same concept can be used to remove any unwanted text.

 

Drupal 7: Display Suites, Helpful for Custom Display of User Account Page

Perhaps you want to customize the User Account Page. You have multiple options. You can create custom user-profile.tpl.php file and link it into your site with complete control. Or you can have a bit less control and use the Display Suite Module and CSS.

If you need complete control of the content of the user Account Page, create of custom user-profile.tpl.php file, add it to your template directory and add code to your template.php to use the new user-profile.tpl.php file.

However, if your needs are simply to move things around in a minor way and hide or display some content from the Accounts Page, you may prefer to load Display Suite, select to adjust the user accounts page and make high level adjustments.

Once you use Display Suite, you may even find you really like using it to help doing adjustments and helping for format other pages.

Drupal 7: menu token and me Alias are not working

Currently, modules Menu Token and me Alias are not working (8/1/2014). There may be a way to get them to work … each has lots of notes around the internet that indicates they are working on & off, with lots of proposed workarounds. Trying workaround after workaround, I could not get them to work consistently or conveniently. Trying to use either, insert tokens in a menu is a problem. I have a solution. The solution is not sophisticated or convenient, but, it appears to work consistently. Hopefully, it will work consistently until the menu token or me Alias modules work consistently.

Unfortunately, the work around requires:

  • Some familiarity with php
  • Faking out the menu validation
  • use of hook_url_outbound_alter

To insert the current user_id tokens into the path in a menus:

  • Step 1: Realize you really want the path “user/uid/history”
  • Step 2: Create a basic content page with url of “user/uid/history”
  • Step 3: Select the menu you would like to add this entry too, add the menu label, path user/uid/history and save, the entry will be allowed because their is a valid page defined at user/uid/history.
  • Step 4: Before leaving the menu, check the actual node id that is automatically inserted in place of path you specified (ex. node/13 might be the real address)
  • Step 5: In the template.php, create the THEME_url_outbound_alter function as follows:
    
     
      function THEME_url_outbound_alter(&$path, &$options, $original_path) {
        if ($path == "node/13") {     // check $path == 
                                      //       the dummy address you created
          global $user;               // prepare to get the token uid value
                                      // build the $path with the current 
                                      // user uid 
          $path = 'user/' . $user->uid . "/history" ;
                                      // Set $options['alias'] = path you 
                                      // want accessed
          $options['alias'] = $path;  
        }
        // repeat the previous path redefine for all pages you would like
        // to include the token uid.   Other tokens may be dealt with in 
        // a similar manner. 
      
      }   
    
    

Drupal 7: Secret to using hook_menu_alter

Are you trying to use hook_menu_alter in Drupal 7 and finding that hook_menu_alter is not appearing to have any effect? There is a reason. Hook_menu_alter is not called every time you run your site. Hook_menu_alter only runs when the menu module is initialized or a menu is initially constructed. If you have an existing menu and you would like hook_menu_alter to affect that menu, you must do a menu rebuild. In theory, there are two trivial ways to do this. However, the 2 trivial methods may not work for you. The trivial methods are:

  • Use Devel module option to request menu rebuild
  • Use drush to request menu rebuild

However, these 2 methods may not be convenient for you. I know that right now (8/2/2014), Devel will not run correctly on my install because there appears to be problem with the current combination of devel, devel_theme & simplehtmldom that is currently available seem to crash my install. At the same time, drush is inconvenient for the install I have available. My solution involved creation of a simple file that will force the menu rebuild.

To do a menu rebuild programattically:

  • Create a file in your site’s base directory, perhaps menuRebuild.php
  • Include the following code in the new file
    
      <?php
      
        chdir("< your-root-directory >") ;
        define("DRUPAL_ROOT", getcwd());
        require_once("./includes/bootstrap.inc") ;
        drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL) ;
        // Rebuild
        menu_rebuild() ;
        echo "rebuilt" ;
    
      ?>
    
    
  • run the file … the menu will be built.

Drupal 7: Notice: Undefined offset: 2 in drupal_http_request() (line 993 of

Using Drupal 7, When registering a new user do you get the following message?

  • “Notice: Undefined offset: 2 in drupal_http_request() (line 993 of”

If you get this message, you are not alone. This is the result of an error communicating with Facebook, and facebook is incorrectly responding. Unfortunately, to correct the problem, you must adjust the core file common.inc. On line 993 of /includes/common.inc insert a technical error in Drupal. The following will correct the error.

Replace:
list($protocol, $code, $status_message) = explode(‘ ‘, trim(array_shift($response)), 3);

With:
list($protocol, $code, $status_message) = explode(‘ ‘, array_shift($response), 3);