fr.ench.info

Articles on “drupal”

Upcoming Events Calendar View in Drupal

Posted on

Here's what I have when I worked on an Event feature for a site. I first tried the Event module although it wasn't flexible enough to accomplish some of the things I needed. The modules I finally used (with their specific versions) were: Calendar 6.x-2.2 CCK 6.x-2.8 Date 6.x-2.6 Views 6.x-2.11 For my Event content type, I just have the usual fields for a node with a datestamp as a CCK date field. And for my Upcoming Events Calendar view, I simply cloned the Calendar view that came with the Calendar module and removed some of the displays. It did have an Upcoming display although wasn't a ...

Migrating Field Collections

Posted on ,

Field collection allows users to group fields. Basically, when you create a 'field collection' field, you are creating a field_collection_item bundle in which you can then add fields on it. This is nice but unfortunately the migrate module doesn't support this. I got this working though with the patch here. To apply the patch you can do this: cd /path/to/field_collection/ wget http://drupal.org/files/field_collection_migrate-entity_load-1175082-120.patch patch -p1 < field_collection_migrate-entity_load-1175082-120.patch There is a sample usage of the destination handler found at the beg...

<span> Tag in Primary Links in a Genesis Subtheme

Posted on

The codes on this post below would result to a markup like this in a Genesis subtheme: <a href="/" title="Home" class="active"><span>Home</span></a> First, you would need to edit the template.php file of your Genesis subtheme and add the codes below. For the SUBTHEME_primary_links function, you'll need to copy the theme_links function. You'll then need to make some slight modifications on the function. <?php function SUBTHEME_theme(&$existing, $type, $theme, $path) { $hooks = genesis_theme($existing, $type, $theme, $path); $hooks['primary_links'] = array...

Drupal Starter Themes

Posted on

Here's a list of starter themes that I have observed popular. The first three would be the ones that I've tried out. The next ones are the ones I am planning to try out. Below the names of each theme are the description taken directly from their project page: Zen For many people, Zen is the ultimate starting theme for Drupal. If you are building your own standards-compliant theme, you will find it much easier to start with Zen than to start with Garland or Bluemarine. This theme has LOTs of documentation in the form of code comments for both the PHP (template.php) and HTML (page.tpl.php,...

Remove Class from Body Classes

Posted on

Removing a class from the variable $body_classes is very simple. All you need to do is make some changes on the variable in the SUBTHEME_preprocess_page function. I have done this with a Zen subtheme: <?php function SUBTHEME_preprocess_page(&$vars, $hook) { if {$node = menu_get_object()) { $vars['node'] = $node; } /* * Make some changes once the node type is 'full'. 'full' is the content * type I am using for pages with no sidebars. */ if ($node->type == 'full') { $body_classes = explode(' ', $vars['body_classes']); $new_body_classes = array(); ...

Create Custom Form Instead Of Altering Node Form

Posted on

This a post to remind me to not alter the node form as much as possible, but instead create a custom form and save the node upon submission. Some issues I had trouble with: Field attach form isn't that flexible for altering. The node form becomes ugly for administrators that want to just create/edit a node due to form alterations. The fields I have in the node type I'm trying to create are: Taxonomy term with a 'select' widget. Taxonomy term with the 'checkboxes' widget. 2 textfields for 'First name' and 'Last name'. Email field. Checkbox for agreement. Requirements: Make the first ta...

Add a "Save and continue editing" button in a Node Edit Form

Posted on

There are times that I would somehow want to continue editing a node rather than view it after saving. Here's a little snippet that would achieve what I needed. <?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...

Add Filters for Apache SOLR

Posted on ,

To add simple filters on your search query with apachesolr can be easily done through hook_apachesolr_query_alter. You'll find the documentation on path/to/apachesolr/apachesolr.api.php. An example would be: <?php function module_apachesolr_query_alter($query) { $query->addFilter('bundle', 'page'); // To filter by either page or article content type $query->addFilter('bundle', 'page OR article'); } For adding subqueries (which is a bit different), you may do this: <?php function module_apachesolr_query_alter($query) { $sometid = 1; $filter = new SolrFilterSubQuery('A...

Problems with hook_download_authorize in Ubercart

Posted on ,

My task involved to limit the number of downloads to 1 but with an exemption for those with a specific role or a so-called "credit". I've used hookdownloadauthorize() to try this one out. The first problem I encountered was that if you do a return FALSE as what the documentation mentioned, it would return the error "A hook denied your access to this file. Please contact the site administrator if this message has been received in error." based on this section of the code: <?php //Check any if any hook_download_authorize calls deny the download foreach (module_implements('download_authori...

#autocomplete_path of Path Alias

Posted on

I was trying to implement the #autocomplete_path to be used to autocomplete URL aliases. I believe this is somewhat a short introduction to doing autocomplete in your textfields when using the Form API. <?php function example_autocomplete() { $items = array(); $i = 2; while(arg($i)) { $items[] = arg($i); $i++; } $string = implode('/', $items); $matches = array(); if ($string) { $result = db_query_range("SELECT dst FROM {url_alias} WHERE LOWER(dst) LIKE LOWER ('%s%%')", $string, 0, 10); while ($destination = db_fetch_object($result)) { $matches[$dest...

Using hook_views_query_alter

Posted on ,

There are times that you might want to alter the query that the Views module generates. My problem was to include an attribute filter for products from the Ubercart module. uc_views might be able to do the trick although filters for product attributes were only for products that have already been order. There is also a patch available although I didn't make use of it as I only needed something simple. I decided to use hookviewsquery_alter. It says to put your function MODULENAME_views_query_alter in MODULENAME.views.inc although it seemed to have just been called in my MODULENAME.module. I...

BlueTrip CSS Framework

Posted on ,

I was recently searching for a CSS Framework. Amongst the ones I found that I believe are popular were Blueprint, 960gs, and YUI. I also searched from the Kohana forums since I was planning to use the CSS framework on trying out Kohana and found BlueTrip. Looked really nice and was quite easy to use (check out its documentation :D) although I haven't much explored it. BlueTrip's definition taken directly from its site: A full featured and beautiful CSS framework which originally combined the best of Blueprint, Tripoli (hence the name), Hartija, 960.gs, and Elements, but has now found a l...

Installation Profile with Content

Posted on

Recently, I encountered a project that requires rebuilding a site over and over in order to test recent changes. There were a bunch of scripts that did this automatically. The scripts were bash and PHP scripts. The bash scripts consist of calling drush commands such as drush en, drush si and drush scr. The PHP scripts task were to import content, terms, and probably set some configurations. These PHP scripts are also the ones ran through drush scr. I didn't go through each line of the scripts but I think what they basically do is enable modules, import contents from a data source, copy some...

Breakdown checkboxes in FAPI and '#disabled' Property

Posted on

If you wish to set some FAPI properties of the checkboxes generated with #type => 'checkboxes' individually, you'll need to breakdown the checkboxes first. There are two ways to do this that I am aware of. One is to add a #process callback to the form element, and another is to set each #options as a separate element e.g. $form['checkboxes'][{#option-key}]. For adding the #process callback, you can do it like this: <?php $form['checkboxes'] = array( '#type' => 'checkboxes', '#options' => $options, '#process' => array('some_callback'), ... ) You'll then need to break...

Pathauto Batch Custom Module

Posted on

I recently just started studying about Drupal's Batch API. I've decided to duplicate Pathauto Bulk Update but using the Batch API in order to bypass the limit you set for Pathauto Bulk Update. Mostly are based on the samples from the API reference and the Handbook. For my .info file, I simply added the dependency for pathauto like so, dependencies[] = "pathauto". For the .module file specifically the Batch API section, I have this: <?php function pathauto_batch_form_submit($form, &$form_state) { $batch = array( 'title' => t('Generating Aliases'), 'finished' => 'path...

Bad Theming Job

Posted on

I read last time about Drupal Theming Nightmares written by a Drupalist. It is somehow a series of the blogger's experience upon continuing the theming job started by another themer. If you know about theming in Drupal then your reaction would probably be similar to the comments. I then recently checked one of the themes I've created and also found out that it had a few (:P) mistakes too considering that I wasn't that familiar to theming when we've started this. This one is a subtheme from Zen (at least the theme came from a decent base theme :P). A screenshot of the file structure follows...

Print Views Output in Drupal

Posted on

There are times that I would like to print the output of a view without it being rendered from a template i.e. it would go through page.tpl.php. I find this useful when say I'd like to do an Ajax call and I'd like it to return just the output of the view itself so I could print it inside a div container for example. This is quite simple as I could use drupal_json as my reference. I first created a new menu like so: <?php function MODULE_menu() { $items = array(); $items['example/js'] = array( 'page callback' => 'MODULE_menu_callback', 'type' => MENU_CALLBACK, 'acc...

Check Available Variables in Theming

Posted on

First off, you can probably check out this entry which provides four functions to look at upon developing. You would need the Devel module for this. I personally use dsm though I believe it simply makes use of the dpm function from devel. I am not certain if this is the proper way of checking the available variables when theming. You could first take a look at the template files e.g. page.tpl.php or node.tpl.php to check what variables are available for you. I also sometimes add the code below to check for the available variables in a template file. <?php dsm(get_defined_vars()); ?>...

URL Shortening Custom Module

Posted on

I first tried using the modules Short URL and Shorten URLs but I believe the module Short URL is currently on its early stages. I've decided to create a custom module for our project but basing it on the modules above. Unfortunately, the module isn't an API like Short URL. It was a combination of both in which it provides a UI for shortening URLs and records them. I started with how the module redirects the URLs when it encounters one from the record. The Short URL implemented the hookinit() to do this. This is somewhat what I was able to come up with based on the _Short URL__ module: <...