drupal 6

Save and Continue Button

<?php
function module_form_alter(&$form, &$form_state, $form_id) {
  if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) {
    $form['buttons']['continue_edit'] = array(
      '#type' => 'submit',
      '#value' => t('Save and continue editing'),
      '#submit' => array('node_form_submit', '_module_continue_edit'),
    );
  }
}

function _module_continue_edit($form, &$form_state) {
  $form_state['redirect'] = 'node/' . $form_state['nid'] . '/edit';
}

Reverse Geocoding

This is one of those items that I can see myself using for sure sometime in the near future. For whatever reason, HLopes (drupal.org/user/610498) was denied a CVS application so his sweet reverse geocoding module is not hosted at d.o.

He did however put it up on his own site here - http://buseee.com

For anyone that wants to follow the discussion this is the link you're after - http://drupal.org/user/610498

Also, go here - http://buseee.com/drupal/modules/reverse-geocode/try and enter in a lat/long pair then click 'fetch address' to see it in action. Nice!

Use PHP Snippet to Show Block for Certain Roles, on Certain Pages and Only to Users in Certain Groups

This snippet came about because I needed to show a block to users in a very specific circumstance.

Users have a hidden field in their content profile page. This field is a node reference to a content type called "county".
Users can only be in one county.

1. Show only to users not in specified roles.
2. Show only on either a certain path OR on a certain content type page.
3. Show only on a county content type page IF the user is on his own county page.


<?php
global $user;
if(!$user->uid) {
return FALSE;
}

Create Uneditable CCK Text Fields

Following is a little gem I found here - http://www.coderintherye.com/disabled-cck-fields-in-node-forms

I actually have a need for this in an upcoming project so it's right on time.

The goal: Create two uneditable text fields that would display in the node edit form with default values and in the node view and be saved in the node object.

//$Id:

/**
* Implementation of hook_form_alter().
* For the news story content type
* Make some fields not editable and have default values
*/

function formedits_form_alter(&$form, &$form_state, $form_id) {

Change the Labels on the Form for Location Module

If you have ever needed to do something "simple" like change the form label from something like "Additional" to "Apartment" you know how difficult that can be. Apparently the location module does not use the Form API like other modules so you can't simply do a hook_form_alter().

I stumbled across the following little piece to handle just this sort of situation. Drop the following in your custom module and you can easily change labels.

/**
* Implementation of hook_locationapi().
*/
function YOUR-MODULE-NAME_locationapi(&$obj, $op, $a3 = NULL, $a4 = NULL, $a5 = NULL) {

Adding a Better Embed Plugin to WYSIWYG + CKEditor

Found a nice solution to the problem of adding embedded code to the wysiwyg CKEditor. The plugin is called MediaEmbed, was written by Kent Safranski and can be downloaded from here http://www.fluidbyte.net/index.php?view=embed-youtube-vimeo-etc-into-cke...

The code was written by Henrik Danielsson (TwoD) and conveniently packaged into an installable module for Drupal 6 by njathan and attached to this comment http://drupal.org/node/848674#comment-3509058

Nice!

Need to Access Views Argument From the Footer or Header of the View?

The following snippet will give it to you.

<?php
$view
=views_get_current_view();
$arg1=$view->args[0];
print
$arg1;
?>

Preload Images with JQuery

In a recent project I had an image heavy page and noticed that sometimes, certain images would not load for some reason. I used the technique found here to ensure that my images were being loaded.

I created a quick file named preload_images.js and put the following into it.

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

Then in my themes .info file, I added the following

scripts[] = js/preload_images.js

Next, I added this to my page.tpl.php in the head section

<script type="text/javascript">
jQuery.preLoadImages("/images/home-menu-block.png", "/images/button-about.png");
</script>

Then a simple visit to the performance page mysite.com/admin/settings/performance to clear the cache.

Syndicate content

Contact Me

Feel free to contact me.

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.