Added the rest of the posts
This commit is contained in:
parent
67242737ce
commit
1a806a00f2
59
source/_posts/2010-04-05-style-drupal-6-lists.md
Normal file
59
source/_posts/2010-04-05-style-drupal-6-lists.md
Normal file
|
@ -0,0 +1,59 @@
|
|||
---
|
||||
title: Style Drupal 6's Taxonomy Lists with PHP, CSS and jQuery
|
||||
slug: style-drupal-6s-taxonomy-lists-php-css-and-jquery
|
||||
tags:
|
||||
- Taxonomy
|
||||
- Drupal Planet
|
||||
- Drupal 6
|
||||
- Drupal Theming
|
||||
---
|
||||
Whilst developing this, and other Drupal websites for clients, I decided that I wanted to categorise content using the taxonomy system. However, I wasn't happy with the way that Drupal displayed the terms lists by default, and I started comparing this to other websites that I look at.
|
||||
|
||||
To start with, I wanted to have something that described what the list was displaying - like in the second example above. I wanted to have the words 'Posted in' displayed before the list of terms. To do this, I had to edit the node template file that exists within my theme folder (sites/all/themes). As I only wanted this change to affect my Blog posts, the file that I needed to change is **node-blog.tpl.php**
|
||||
|
||||
I scrolled down until I found the piece of code that displayed the terms list:
|
||||
|
||||
~~~php
|
||||
<?php if ($terms): ?>
|
||||
<div class="terms terms-inline">
|
||||
<?php print t('Posted in') . $terms; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
~~~
|
||||
|
||||
Adding `print t(' Posted in ')` will print the words 'Posted in' before outputing the terms.
|
||||
|
||||
I then added some CSS to re-size the spacing between the items, and then add the commas between them to seperate them:
|
||||
|
||||
~~~css
|
||||
.terms ul.links li {
|
||||
margin-right: 1px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.terms ul.links li:after {
|
||||
content: ",";
|
||||
}
|
||||
|
||||
.terms ul.links li.last:after {
|
||||
content: ".";
|
||||
}
|
||||
~~~
|
||||
|
||||
I created a file named **script.js** in my theme folder with the following code in it. After clearing Drupal's caches, this file is automatically recognised by Drupal 6.
|
||||
|
||||
~~~js
|
||||
if (Drupal.jsEnabled) {
|
||||
$(document).ready(function() {
|
||||
$('.terms ul.links li.last').prev().addClass('test');
|
||||
})
|
||||
}
|
||||
~~~
|
||||
|
||||
This code finds the last item in the list, uses **.prev** to select the one before it, and then uses **.addClass** to assign it the HTML class of "test". We can then use this class to target it with specific CSS.
|
||||
|
||||
~~~css
|
||||
.terms ul.links li.test:after {
|
||||
content: " and";
|
||||
}
|
||||
~~~
|
28
source/_posts/2010-04-28-imagecrop.md
Normal file
28
source/_posts/2010-04-28-imagecrop.md
Normal file
|
@ -0,0 +1,28 @@
|
|||
---
|
||||
title: Using ImageCache and ImageCrop for my Portfolio
|
||||
slug: using-imagecache-and-imagecrop-my-portfolio
|
||||
tags:
|
||||
- Drupal 6
|
||||
- CCK
|
||||
- ImageCache
|
||||
- ImageField
|
||||
- ImageCrop
|
||||
---
|
||||
Whilst working on my own portfolio/testimonial website, I decided to have a portfolio page displaying the name of each site and a thumbnail image. For this Blog post, I'll be using a site called [Popcorn Strips](http://popcornstrips.com) which I built for a friend earlier this year as an example.
|
||||
|
||||
I created a content type called 'Project' with a CCK ImageField called 'Screenshot'. I created a project called [Popcorn Strips](http://popcornstrips.com), used the [ScreenGrab](https://addons.mozilla.org/addon/1146) add-on for Mozilla Firefox to take a screenshot of the website, and uploaded it to the project node.
|
||||
|
||||
I created a View to display the published projects, and an ImageCache
|
||||
preset to create the thumbnail image by scaling and cropping the image
|
||||
to a size of 200x100 pixels.
|
||||
|
||||
Although, this automatically focused the crop on the centre of the image, whereas I wanted to crop from the top and left of the image - showing the site's logo and header.
|
||||
|
||||
I installed the [ImageCrop](http://drupal.org/project/imagecrop) module, which add a jQuery crop function to the standard ImageCache presents. I removed the original Scale and Crop action and replaced it with a Scale action with a width of 200px.
|
||||
|
||||
I then added a new 'Javascript crop' action with the following settings:
|
||||
|
||||
* Width: 200px
|
||||
* Height: 100px
|
||||
* xoffset: Left
|
||||
* yoffset: Top
|
|
@ -0,0 +1,16 @@
|
|||
---
|
||||
title: Conditional Email Addresses in a Webform
|
||||
slug: conditional-email-addresses-webform
|
||||
tags:
|
||||
- Drupal Planet
|
||||
- Drupal 6
|
||||
- Conditional Email
|
||||
- Webform
|
||||
---
|
||||
I created a new Webform to serve as a simple Contact form, but left the main configuration until after I created the form components. I added 'Name', 'Email', 'Subject' and 'Message' fields, as well as a 'Category' select list. Below 'Options', I entered each of my desired options in the following format:
|
||||
|
||||
Email address|Visible name
|
||||
|
||||
I went back to the form configuration page and expanded 'Conditional Email Recipients', and selected my Category. Note that the standard 'Email To' field above it needs to be empty. Originally, I made the mistake of leaving addresses in that field which resulted in people being sent emails regardles of which category was selected. I then configured the rest of the form.
|
||||
|
||||
Then, when I went to the finished form, the category selection was available.
|
15
source/_posts/2010-05-10-zenophile.md
Normal file
15
source/_posts/2010-05-10-zenophile.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
---
|
||||
title: Quickly Create Zen Subthemes Using Zenophile
|
||||
tags:
|
||||
- Drupal Planet
|
||||
- Drupal 6
|
||||
- Drupal Modules
|
||||
- Drupal Theming
|
||||
- Zen
|
||||
- Zenophile
|
||||
---
|
||||
If you use the [Zen](http://drupal.org/project/zen) theme, then you should also be using the [Zenophile](http://drupal.org/project/zenophile) module!
|
||||
|
||||
The Zenophile module allows you to very quickly create Zen subthemes from within your web browser, as well as editing options such as the site directory where it should be placed, the layout type (fixed or fluid), page wrapper and sidebar widths, and the placement of the sidebars.
|
||||
|
||||
For more information about the Zenophile module, check out [this video](http://blip.tv/file/2427703) by [Elliott Rothman](http://elliottrothman.com).
|
24
source/_posts/2010-05-25-fancy-slide.md
Normal file
24
source/_posts/2010-05-25-fancy-slide.md
Normal file
|
@ -0,0 +1,24 @@
|
|||
---
|
||||
title: Create a Slideshow of Multiple Images Using Fancy Slide
|
||||
slug: create-slideshow-multiple-images-using-fancy-slide
|
||||
tags:
|
||||
- Drupal Planet
|
||||
- Drupal 6
|
||||
- Fancy Slide
|
||||
- Slideshow
|
||||
---
|
||||
Whilst updating my About page, I thought about creating a slideshow of several images instead of just the one static image. When I looking on Drupal.org, the only slideshow modules were to create slideshows of images that were attached to different nodes - not multiple images attached to one node. Then, I found the <a href="http://drupal.org/project/fancy_slide">Fancy Slide</a> module. It's a jQuery Slideshow module with features that include integration with the <a href="http://drupal.org/project/cck">CCK</a>, <a href="http://drupal.org/project/imagecache">ImageCache</a> and <a href="http://drupal.org/project/nodequeue">Nodequeue</a> modules.
|
||||
|
||||
I added an CCK Image field to my Page content type, and set the number of values to 3, then uploaded my images to the Page.
|
||||
|
||||
Once the Images were added, I went to the Fancy Slide settings page and created the slideshow.
|
||||
|
||||
I added the dimensions of my images, the type of animation, specified the node that contained the images, the slideshow field, delay between slides and transition speed. With the slideshow created, it now needed embedding into the page.
|
||||
|
||||
I added the following code into my About page, as described in the Fancy Slide readme.txt file - the number representing the ID of the slideshow.
|
||||
|
||||
~~~php
|
||||
<?php print theme('fancy_slide', 1); ?>
|
||||
~~~
|
||||
|
||||
In my opinion, this adds a nice effect to the About page. I like it because it's easy to set up, and easy to add additional images later on if required.
|
24
source/_posts/2010-05-29-imagefield-import-module.md
Normal file
24
source/_posts/2010-05-29-imagefield-import-module.md
Normal file
|
@ -0,0 +1,24 @@
|
|||
---
|
||||
title: Quickly Import Multiples Images Using the Imagefield_Import Module
|
||||
slug: quickly-import-multiples-images-using-imagefieldimport-module
|
||||
tags:
|
||||
- Drupal Planet
|
||||
- ImageField Import
|
||||
- Drupal 6
|
||||
- Photo Gallery
|
||||
- CCK
|
||||
- ImageField
|
||||
---
|
||||
<strong>Thanks to Bob at <a href="http://mustardseedmedia.com/">Mustardseed Media</a> for <a href="http://twitter.com/mustardseedinc/status/14713096905">tweeting</a> about this module. It's undoubtedly saved me hours of work today alone!</strong>
|
||||
|
||||
I've recently started a personal project converting a website to Drupal. It's currently a static HTML/CSS site which also uses the <a href="http://coppermine-gallery.net/">Coppermine Photo Gallery</a>. As part of building the new website, I wanted to move all the photos from the existing site onto the new one. However, with 1260 photos in 17 albums, this could have been a lengthy process!
|
||||
|
||||
I created a new Drupal-powered Gallery as described in <a href="http://lullabot.com/articles/photo-galleries-views-attach">this screencast</a> by <a href="http://twitter.com/eaton">Jeff Eaton</a> - using the CCK and Imagefield modules, and re-created each of my existing Gallery nodes. Using the <a href="http://drupal.org/project/imagefield_import">Imagefield_Import</a> module, I was then able to quickly import the photos into the new Galleries.
|
||||
|
||||
I downloaded all the photos from the previous Gallery via FTP, and installed and configured the Imagefield_Import module.
|
||||
|
||||
I created an 'Import' folder, selected the target field and mode. In this case, I want each image to be imported into its own Photo node. I moved the photos for the first album into the Import folder, and loaded the 'Import Images' screen <em>(admin/content/imagefield_import)</em>.
|
||||
|
||||
After clicking 'Import', a node is created for each photo, the image is uploaded, and added to the selected Gallery.
|
||||
|
||||
Just another 1248 photos to go...
|
16
source/_posts/2010-06-02-improve-jpg-quality.md
Normal file
16
source/_posts/2010-06-02-improve-jpg-quality.md
Normal file
|
@ -0,0 +1,16 @@
|
|||
---
|
||||
title: Improve JPG Quality in Imagecache and ImageAPI
|
||||
slug: improve-jpg-quality-imagecache-and-imageapi
|
||||
tags:
|
||||
- Drupal Planet
|
||||
- Drupal 6
|
||||
- ImageCache
|
||||
---
|
||||
Whilst uploading images for my Projects and Testimonials sections, I noticed that the Imagecache-scaled images weren't as high a quality the originals on my Mac. I did some searching online and found out that, by default, Drupal resamples uploaded jpgs to 75% of their original quality.
|
||||
|
||||
To increase the quality of your images, change the setting in the two following places:
|
||||
|
||||
* admin/settings/imageapi/config
|
||||
* admin/settings/image-toolkit
|
||||
|
||||
The first one is for ImageAPI. Primarily, this means Imagecache presets. The second one is for core's image.inc. This is used for resizing profile pictures in core, and some contrib modules. Once changed, I did have to flush each of the Imagecache presets (admin/build/imagecache) for the changes to take effect.
|
21
source/_posts/2010-06-23-social-icons-block.md
Normal file
21
source/_posts/2010-06-23-social-icons-block.md
Normal file
|
@ -0,0 +1,21 @@
|
|||
---
|
||||
title: Create a Block of Social Media Icons using CCK, Views and Nodequeue
|
||||
slug: create-block-social-media-icons-using-cck-views-and-nodequeue
|
||||
tags:
|
||||
- Drupal Planet
|
||||
- Drupal 6
|
||||
- Views
|
||||
- Nodequeue
|
||||
- oliverdavies.co.uk
|
||||
---
|
||||
I recently decided that I wanted to have a block displayed in a sidebar on my site containing icons and links to my social media profiles - <a href="http://twitter.com/opdavies">Twitter</a>, <a href="http://facebook.com/opdavies">Facebook</a> etc. I tried the <a href="http://drupal.org/project/follow">Follow</a> module, but it lacked the option to add extra networks such my <a href="http://drupal.org/user/381388">Drupal.org</a> account, and my <a href="http://oliverdavies.co.uk/rss.xml">RSS feed</a>. I started to create my own version, and then found <a href="http://www.hankpalan.com/blog/drupal-themes/add-your-social-connections-drupal-icons">this Blog post</a> by Hank Palan.
|
||||
|
||||
I created a 'Social icon' content type with the body field removed, and with fields for a link and image - then downloaded the favicons from the appropriate websites to use.
|
||||
|
||||
However, instead of using a custom template (node-custom.tpl.php) file, I used the Views module.
|
||||
|
||||
I added fields for the node titles, and the link from the node's content. Both of these are excluded from being displayed on the site. I then re-wrote the output of the Icon field to create the link using the URL, and using the node's title as the image's alternative text and the link's title.
|
||||
|
||||
I also used the <a href="http://drupal.org/project/nodequeue">Nodequeue</a> module to create a nodequeue and arrange the icons in the order that I wanted them to be displayed. Once this was added as a relationship within my View, I was able to use node's position in the nodequeue as the sort criteria.
|
||||
|
||||
To complete the process, I used the <a href="http://drupal.org/project/css_injector">CSS Injector</a> module to add some additional CSS styling to position and space out the icons.
|
22
source/_posts/2010-06-25-useful-drupal-6-modules.md
Normal file
22
source/_posts/2010-06-25-useful-drupal-6-modules.md
Normal file
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
title: 10 Useful Drupal 6 Modules
|
||||
tags:
|
||||
- Drupal Planet
|
||||
- Drupal 6
|
||||
- Modules
|
||||
- Drupal Modules
|
||||
---
|
||||
Aside from the obvious candidates such as Views, CCK etc, here are a list of 10 contributed modules that I currently use on each Drupal project.
|
||||
|
||||
So, in no particular order:
|
||||
|
||||
* **<a href="http://drupal.org/project/admin">Admin</a>:** <br>The admin module provides UI improvements to the standard Drupal admin interface. I've just upgraded to the new <a href="http://drupal.org/node/835870">6.x-2.0-beta4</a> version, and installed the newly-required <a href="http://code.developmentseed.org/rubik">Rubik</a>/<a href="http://code.developmentseed.org/tao">Tao</a> themes. So far, so good!
|
||||
* **<a href="http://drupal.org/project/better_perms">Better Permissions</a>/<a href="http://drupal.org/project/filter_perms">Filter Permissions</a>: <br>**Basic permissions is a basic module which enhances the Drupal Permissions page to support collapsing and expanding permission rows. Filter permissions provides filters at the top of the Permissions page for easier management when your site has a large amount of roles and/or permissions.
|
||||
* **<a href="http://drupal.org/project/better_formats">Better Formats</a>: <br>**Better formats is a module to add more flexibility to Drupal's core input format system.
|
||||
* **<a href="http://drupal.org/project/node_clone">Clone module</a>:**<br>Allows users to make a copy of an existing item of site content (a node) and then edit that copy.
|
||||
* **<a href="http://drupal.org/project/vertical_tabs">Vertical Tabs</a>:<br>**Integrated into Drupal 7 core, this module adds vertical tabs to the node add and edit forms.
|
||||
* **<a href="http://drupal.org/project/context">Context</a>:<br>**Context allows you to manage contextual conditions and reactions for different portions of your site. You can think of each context as representing a "section" of your site. For each context, you can choose the conditions that trigger this context to be active and choose different aspects of Drupal that should react to this active context.
|
||||
* **<a href="http://drupal.org/project/nodepicker">Node Picker</a>:**<br>A rewrite of the module <a rel="nofollow" href="http://drupal.org/project/tinymce_node_picker">TinyMCE Node Picker</a>. Allows you to easily create links to internal nodes.
|
||||
* **<a href="http://drupal.org/project/module_filter">Module Filter</a>:**<br>What this module aims to accomplish is the ability to quickly find the module you are looking for without having to rely on the browsers search feature which more times than not shows you the module name in the 'Required by' or 'Depends on' sections of the various modules or even some other location on the page like a menu item.
|
||||
* **<a href="http://drupal.org/project/zenophile">Zenophile</a>:**<br>Quickly create Zen subthemes.
|
||||
* **<a href="http://drupal.org/project/addanother">Add Another</a>:**<br>Add another displays a message after a user creates a node, and/or displays an "Add another" tab on nodes allowing them to make another node of the same type. You can control what roles and node types see this feature.
|
45
source/_posts/2010-06-28-flickr-photo-gallery.md
Normal file
45
source/_posts/2010-06-28-flickr-photo-gallery.md
Normal file
|
@ -0,0 +1,45 @@
|
|||
---
|
||||
title: Create a Flickr Photo Gallery Using Feeds, CCK and Views
|
||||
slug: create-flickr-photo-gallery-using-feeds-cck-and-views
|
||||
tags:
|
||||
- Drupal Planet
|
||||
- Drupal 6
|
||||
- Photo Gallery
|
||||
- Views
|
||||
- CCK
|
||||
- ImageCache
|
||||
- Feeds
|
||||
- FileField
|
||||
- Flickr
|
||||
- ImageField
|
||||
---
|
||||
In this tutorial, I'll show you how to create a photo gallery which uses photos imported from <a title="Flickr" href="http://www.flickr.com/">Flickr</a>.
|
||||
|
||||
The modules that I'll use to create the Gallery are:
|
||||
|
||||
* <a href="http://drupal.org/project/cck">CCK</a>
|
||||
* <a href="http://drupal.org/project/feeds">Feeds</a>
|
||||
* <a href="http://drupal.org/project/feeds_imagegrabber">Feeds Image Grabber</a>
|
||||
* <a href="http://drupal.org/project/filefield">FileField</a>
|
||||
* <a href="http://drupal.org/project/imageapi/">ImageAPI</a>
|
||||
* <a href="http://drupal.org/project/imagecache">ImageCache</a>
|
||||
* <a href="http://drupal.org/project/imagefield">ImageField</a>
|
||||
* <a href="http://drupal.org/project/views">Views</a>
|
||||
|
||||
The first thing that I did was to create a content type to store my imported images. I named it 'Photo', removed the Body field, and added an Image field.
|
||||
|
||||
Next, I installed and configured the Feeds and Image Grabber module. I used an overridden default Feed to import my photos from Flickr using the following settings:
|
||||
|
||||
* **Basic settings:** I changed the Refresh time to 15 minutes.
|
||||
* **Processor settings:** I changed the content type to 'Photo', and the author's name from 'anonymous'.
|
||||
* **Processor mapping:** I added a new mapping from 'Item URL (link)' to 'Photo (FIG)'. The Photo FIG target is added by the Image Grabber module.
|
||||
|
||||
Next, I needed to create the actual Feed, which I did by clicking 'Import' within the Navigation menu, and clicking 'Feed'. I gave it a title, entered the URL to my RSS feed from Flickr, and enabled the Image Grabber for this feed.
|
||||
|
||||
Once the Feed is created, the latest 20 images from the RSS feed are imported and 20 new Photos nodes are created. In the example below, the image with the 'Photo' label is the Image field mapped by the Image Grabber module. It is this image that I'll be displaying within my Gallery.
|
||||
|
||||
With the new Photo nodes created, I then created the View to display them.
|
||||
|
||||
The View selects the image within the Photo content type, and displays in it a grid using an ImageCache preset. The View is limited to 20 nodes per page, and uses a full pager if this is exceeded. The nodes are sorted by the descending post date, and filtered by whether or not they are published, and only to include Photo nodes.
|
||||
|
||||
As an additional effect, I also included the 'Feeds Item - Item Link' field, which is basically the original link from the RSS feed. By checking the box the exclude the item from the display, it is not shown, but makes the link available to be used elsewhere. By checking the box 'Re-write the output for this field' on the 'Content: Photo' field, I was able to add the replacement token (in this case, [url]) as the path for a link around each image. This meant that when someone clicked a thumbnail of a photo, they were directed to the Flickr website instead of the node within my Drupal site.
|
24
source/_posts/2010-07-01-change-content-type-sql.md
Normal file
24
source/_posts/2010-07-01-change-content-type-sql.md
Normal file
|
@ -0,0 +1,24 @@
|
|||
---
|
||||
title: Change the Content Type of Multiple Nodes Using SQL
|
||||
slug: change-content-type-multiple-nodes-using-sql
|
||||
tags:
|
||||
- Drupal Planet
|
||||
- Drupal 6
|
||||
- SQL
|
||||
- Sequel Pro
|
||||
- Database
|
||||
- Content Types
|
||||
---
|
||||
In this post, I will be changing values within my Drupal 6 site's database to quickly change the content type of multiple nodes. I will be using a test development site with the core Blog module installed, and converting Blog posts to a custom content type called 'News article'.
|
||||
|
||||
**Before changing any values within the database, ensure that you have an up-to-date backup which you can restore if you encounter a problem!**
|
||||
|
||||
To begin with, I created the 'News article' content type, and then used the Devel Generate module to generate some Blog nodes.
|
||||
|
||||
Using <a href="http://www.sequelpro.com/">Sequel Pro</a>, I can query the database to view the Blog posts (you can also do this via the <a href="http://guides.macrumors.com/Terminal">Terminal</a> in a Mac OS X/Linux, <a href="http://www.oracle.com/technology/software/products/sql/index.html">Oracle SQL Developer</a> on Windows, or directly within <a href="http://www.phpmyadmin.net/home_page/index.php">phpMyAdmin</a>):
|
||||
|
||||
Using an SQL 'Update' command, I can change the type value from 'blog' to 'article'. This will change every occurance of the value 'blog'. If I wanted to only change certain nodes, I could add a 'Where' clause to only affect nodes with a certain nid or title.
|
||||
|
||||
Now, when I query the database, the type is shown as 'article'.
|
||||
|
||||
Now, when I go back into the administration section of my site and view the content, the content type now shows at 'News article'.
|
23
source/_posts/2010-07-02-virtual-hosts-virtualhostx.md
Normal file
23
source/_posts/2010-07-02-virtual-hosts-virtualhostx.md
Normal file
|
@ -0,0 +1,23 @@
|
|||
---
|
||||
title: Create Virtual Hosts on Mac OS X Using VirtualHostX
|
||||
slug: create-virtual-hosts-mac-os-x-using-virtualhostx
|
||||
tags:
|
||||
- Drupal Planet
|
||||
- Drupal 6
|
||||
- MAMP
|
||||
- Virtual Hosts
|
||||
- VirtualHostX
|
||||
---
|
||||
This isn't a Drupal related topic per se, but it is a walk-through of one of the applications that I use whilst doing Drupal development work. I assume, like most Mac OS X users, I use <a href="http://www.mamp.info/en/index.html">MAMP</a> to run Apache, MySQL and PHP locally whilst developing. I also use virtual hosts in Apache to create local .dev domains which are as close as possible to the actual live domains. For example, if I was developing a site called mysite.com, my local development version would be mysite.dev.
|
||||
|
||||
Normally, I would have to edit the hosts file and Apache's httpd.conf file to create a virtual host. The first to set the domain and it's associated IP address, and the other to configure the domain's directory, default index file etc. However, using <a href="http://clickontyler.com/virtualhostx/">VirtualHostX</a>, I can quickly create a virtual host without having to edt any files. Enter the virtual domain name, the local path and the port, and apply the settings. VirtualHostX automatically restarts Apache, so the domain is ready to work straight away. You can also enter custom directives from within the GUI.
|
||||
|
||||
There's also an option to share the host over the local network. Next, I intend on configuring a virtual Windows PC within VMware Fusion to view these domains so that I can do cross-browser testing before putting a site live.
|
||||
|
||||
I ensured that my Apache configuration within MAMP was set to port 80, and that VirtualHostX was using Apache from MAMP instead of Apple's built-in Apache.
|
||||
|
||||
**Note:** One problem that I had after setting this up, was that I was receving an error when attempting to open a Drupal website which said *'No such file or directory'.*
|
||||
|
||||
After some troubleshooting, I found out that Web Sharing on my Mac had become enabled (I don't know why, I've never enabled it), and that this was causing a conflict with Apache. Once I opened my System Preferences and disabled it, everything worked fine!
|
||||
|
||||
This, along with <a href="http://www.mamp.info/en/index.html">MAMP</a>, <a href="http://www.panic.com/coda/">Coda</a>, <a href="http://www.sequelpro.com/">Sequel Pro</a>, and <a href="http://www.panic.com/transmit/">Transmit</a>, has become an essential tool within my development environment.
|
|
@ -0,0 +1,50 @@
|
|||
---
|
||||
title: Add a Taxonomy Term to Multiple Nodes Using SQL
|
||||
slug: add-taxonomy-term-multiple-nodes-using-sql
|
||||
tags:
|
||||
- Taxonomy
|
||||
- Drupal Planet
|
||||
- Drupal 6
|
||||
- SQL
|
||||
- Sequel Pro
|
||||
- Database
|
||||
---
|
||||
**Update:** This can also be done using the [Views Bulk Operations](http://drupal.org/project/views_bulk_operations) module.
|
||||
|
||||
In preparation for my Blog posts being added to [Drupal Planet](http://drupal.org/planet), I needed to create a new Taxonomy term (or, in this case, tag) called 'Drupal Planet', and assign it to new content to imported into their aggregator. After taking a quick look though my previous posts, I decided that 14 of my previous posts were relevant, and thought that it would be useful to also assign these the 'Drupal Planet' tag.
|
||||
|
||||
I didn't want to manually open each post and add the new tag, so I decided to make the changes myself directly into the database using SQL, and as a follow-up to a previous post - <a href="internal:node/32" title="Quickly change the content type of multiple nodes using SQL">Quickly Change the Content Type of Multiple Nodes using SQL</a>.
|
||||
|
||||
**Again, before changing any values within the database, ensure that you have an up-to-date backup which you can restore if you encounter a problem!**
|
||||
|
||||
The first thing I did was create the 'Drupal Planet' term in my Tags vocabulary. I decided to do this via the administration area of my site, and not via the database. Then, using [Sequel Pro](http://www.sequelpro.com), I ran the following SQL query to give me a list of Blog posts on my site - showing just their titles and nid values.
|
||||
|
||||
~~~sql
|
||||
SELECT title, nid FROM node WHERE TYPE = 'blog' ORDER BY title ASC;
|
||||
~~~
|
||||
|
||||
I made a note of the nid's of the returned nodes, and kept them for later. I then ran a similar query against the term_data table. This returned a list of Taxonomy terms - showing the term's name, and it's unique tid value.
|
||||
|
||||
~~~sql
|
||||
SELECT NAME, tid FROM term_data ORDER BY NAME ASC;
|
||||
~~~
|
||||
|
||||
The term that I was interested in, Drupal Planet, had the tid of 84. To confirm that no nodes were already assigned a taxonomy term with this tid, I ran another query against the database. I'm using aliases within this query to link the node, term_node and term_data tables. For more information on SQL aliases, take a look at <http://w3schools.com/sql/sql_alias.asp>.
|
||||
|
||||
~~~sql
|
||||
SELECT * FROM node n, term_data td, term_node tn WHERE td.tid = 84 AND n.nid = tn.nid AND tn.tid = td.tid;
|
||||
~~~
|
||||
|
||||
As expected, it returned no rows.
|
||||
|
||||
The table that links node and term_data is called term_node, and is made up of the nid and vid columns from the node table, as well as the tid column from the term_data table. Is it is here that the additional rows would need to be entered.
|
||||
|
||||
To confirm everything, I ran a simple query against an old post. I know that the only taxonomy term associated with this post is 'Personal', which has a tid value of 44.
|
||||
|
||||
~~~sql
|
||||
SELECT nid, tid FROM term_node WHERE nid = 216;
|
||||
~~~
|
||||
|
||||
Once the query had confirmed the correct tid value, I began to write the SQL Insert statement that would be needed to add the new term to the required nodes. The nid and vid values were the same on each node, and the value of my taxonomy term would need to be 84.
|
||||
|
||||
Once this had completed with no errors, I returned to the administration area of my Drupal site to confirm whether or not the nodes had been assigned the new term.
|
21
source/_posts/2010-07-12-teleport-module.md
Normal file
21
source/_posts/2010-07-12-teleport-module.md
Normal file
|
@ -0,0 +1,21 @@
|
|||
---
|
||||
title: Review of the Teleport Module
|
||||
slug: review-teleport-module
|
||||
tags:
|
||||
- Drupal Planet
|
||||
- Drupal 6
|
||||
- Modules
|
||||
- Drupal Modules
|
||||
- Teleport
|
||||
---
|
||||
As a heavily-reliant [Quicksilver](http://en.wikipedia.org/wiki/Quicksilver_%28software%29) user on my MacBook Pro, I was glad when I found the [Teleport](http://drupal.org/project/teleport) module for [Drupal](http://drupal.org) *(due to Elliott Rothman's [tweet](http://twitter.com/elliotttt/status/18044234238))*.
|
||||
|
||||
When you press a configurable hot-key, a jQuery dialog box appears where you can search for nodes by title or path, or directly enter the path that you want to navigate to. This will greatly reduce the number of clicks that I need to perform to get to my desired page - even compared to the [Admin](http://drupal.org/project/admin) and [Administration Menu](http://drupal.org/project/admin_menu) modules.
|
||||
|
||||
Although it's not a new module (the first commits were 2 years ago), I hope that they are still planning on achieving the list of future directions listed on their Drupal.org project page:
|
||||
|
||||
* Make interface act more like Quicksilver (i.e. you should only have to press Enter once to launch)
|
||||
* 'Actions' like Quicksilver: if you select a node, a second input should appear with options to go to the View page, Edit page, (un)publish, etc. Same with users.
|
||||
* Hook into more non-node content, like taxonomy terms and functions in the API module.
|
||||
|
||||
Personally, this will make navigation around both the front-end and administration area of my Drupal sites so much easier.
|
41
source/_posts/2010-08-10-adminhover-module.md
Normal file
41
source/_posts/2010-08-10-adminhover-module.md
Normal file
|
@ -0,0 +1,41 @@
|
|||
---
|
||||
title: Review of the Admin:hover Module
|
||||
slug: review-adminhover-module
|
||||
tags:
|
||||
- Drupal Planet
|
||||
- Drupal 6
|
||||
- Modules
|
||||
- Drupal Modules
|
||||
- Admin:hover
|
||||
- Administration
|
||||
---
|
||||
Sorry for the lack of Blog posts lately, but [my new job](http://horseandcountry.tv) that I started a few weeks ago has certainly been keeping me busy! I've got a few more posts that I'm preparing content for, and I'll hopefully be back into my weekly-post routine before too long!
|
||||
|
||||
Today, I'd like to just give a quick overview of the [Admin:hover](http://drupal.org/project/admin_hover) module. It basically adds an administrative menu that pops up when you hover over a node or block within your Drupal website - the kind of functionality that was present within previous versions of the [Admin module](http://drupal.org/project/admin). It also integrates well with the [Devel](http://drupal.org/project/devel) and [Clone](http://drupal.org/project/node_clone) modules.
|
||||
|
||||
I've found this to be extremely useful whilst working on photo galleries etc. where multiple nodes are displayed in a grid format and I quickly need to publish or unpublish something for testing purposes. No longer do I need to open each node, or go into the administration area to perform the required actions.
|
||||
|
||||
It is also possible to customise which links are available from within the adminstration area. The possible selections that I currently have on this site are as follows:
|
||||
|
||||
**Node links:**
|
||||
|
||||
* Edit
|
||||
* Publish
|
||||
* Unpublish
|
||||
* Promote
|
||||
* Unpromote
|
||||
* Make sticky
|
||||
* Make unsticky
|
||||
* Delete
|
||||
* Clone
|
||||
* Dev load
|
||||
* View author
|
||||
* Edit author
|
||||
* Add
|
||||
|
||||
**Block links:**
|
||||
|
||||
* Configure block
|
||||
* Add block
|
||||
|
||||
Although, as I have additional contributed modules installed, some of these may not neccassaily be available out of the box.
|
122
source/_posts/2010-08-11-better-photo-gallery-1.md
Normal file
122
source/_posts/2010-08-11-better-photo-gallery-1.md
Normal file
|
@ -0,0 +1,122 @@
|
|||
---
|
||||
title: Create a Better Photo Gallery in Drupal - Part 1
|
||||
slug: create-better-photo-gallery-drupal-part-1
|
||||
tags:
|
||||
- Drupal Planet
|
||||
- Drupal 6
|
||||
- Photo Gallery
|
||||
- SQL
|
||||
- Views
|
||||
- Sequel Pro
|
||||
- CCK
|
||||
- Views Attach
|
||||
- Drupal
|
||||
---
|
||||
Recently, I converted a client's static HTML website, along with their Coppermine Photo Gallery, into a Drupal-powered website.
|
||||
|
||||
Over the next few posts, I'll be replicating the process that I used during the conversion, and how I added some additional features to my Drupal gallery.
|
||||
|
||||
To begin with, I created my photo gallery as described by <a href="http://www.lullabot.com/about/team/jeff-eaton">Jeff Eaton</a> in <a href="http://www.lullabot.com/articles/photo-galleries-views-attach">this screencast</a>, downloaded all my client's previous photos via FTP, and quickly added them into the new gallery using the <a href="http://drupal.org/project/imagefield_import">Imagefield Import</a> module (which I mentioned <a href="internal:/2010/05/29/importing-images-using-the-imagefieldimport-module" title="Importing images using the Imagefield_Import module">previously</a>).
|
||||
|
||||
When I compare this to the previous gallery, I can see several differences which I'd like to include. The first of which is the number of photos in each gallery, and the date that the most recent photo was added.
|
||||
|
||||
To do this, I'd need to query my website's database. To begin with, I wanted to have a list of all the galleries on my site which are published, and what they're unique node ID values are. To do this, I opened Sequel Pro and entered the following code:
|
||||
|
||||
~~~sql
|
||||
SELECT title
|
||||
AS title, nid
|
||||
AS gallery_idFROM node
|
||||
WHERE type = 'gallery'
|
||||
AND status = 1;
|
||||
~~~
|
||||
|
||||
As the nid value of each gallery corresponds with the 'field_gallery_nid' field within the content_type_photo field, I can now query the database and retrieve information about each specific gallery.
|
||||
|
||||
For example, using <a href="http://www.w3schools.com/sql/sql_alias.asp">aliasing</a> within my SQL statement, I can retrieve a list of all the published photos within the 'British Squad 2008' gallery by using the following code:
|
||||
|
||||
~~~sql
|
||||
SELECT n.title, n.nid, p.field_gallery_nid
|
||||
FROM node n, content_type_photo p
|
||||
WHERE p.field_gallery_nid = 105
|
||||
AND n.status = 1
|
||||
AND n.nid = p.nid;
|
||||
~~~
|
||||
|
||||
I can easily change this to count the number of published nodes by changing the first line of the query to read SELECT COUNT(*).
|
||||
|
||||
~~~sql
|
||||
SELECT COUNT(*)
|
||||
FROM node n, content_type_photo p
|
||||
WHERE p.field_gallery_nid = 105
|
||||
AND n.status = 1
|
||||
AND n.nid = p.nid;
|
||||
~~~
|
||||
|
||||
As I've used the <a href="http://drupal.org/project/views_attach">Views Attach</a> module, and I'm embedding the photos directly into the Gallery nodes, I easily add this to each gallery by creating a custom node-gallery.tpl.php file within my theme. I can then use the following PHP code to retrieve the node ID for that specific gallery:
|
||||
|
||||
~~~php
|
||||
<?php
|
||||
$selected_gallery = db_result(db_query("
|
||||
SELECT nid
|
||||
FROM {node}
|
||||
WHERE type = 'gallery'
|
||||
AND title = '$title'
|
||||
"));
|
||||
?>
|
||||
~~~
|
||||
|
||||
I can then use this variable as part of my next query to count the number of photos within that gallery, similar to what I did earlier.
|
||||
|
||||
~~~php
|
||||
<?php
|
||||
$gallery_total = db_result(db_query("
|
||||
SELECT COUNT(*)
|
||||
FROM {content_type_photo}
|
||||
WHERE field_gallery_nid = $selected_gallery
|
||||
"));
|
||||
?>
|
||||
~~~
|
||||
|
||||
Next, I wanted to display the date that the last photo was displayed within each album. This was done by using a similar query that also sorted the results in a descending order, and limited it to one result - effectively only returning the created date for the newest photo.
|
||||
|
||||
~~~php
|
||||
<?php
|
||||
$latest_photo = db_result(db_query("
|
||||
SELECT n.created
|
||||
FROM {node} n, {content_type_photo} p
|
||||
WHERE p.field_gallery_nid = $selected_gallery
|
||||
AND n.nid = p.nid
|
||||
ORDER BY n.created DESC LIMIT 1
|
||||
"));
|
||||
?>
|
||||
~~~
|
||||
|
||||
This was all then added into a 'print' statement which displayed it into the page.
|
||||
|
||||
~~~php
|
||||
<?php
|
||||
if ($selected_gallery_total != 0) {
|
||||
$output = '<i>There are currently ' . $selected_gallery_total . ' photos in this gallery.';
|
||||
$output .= 'Last one added on ' . $latest_photo . '</i>';
|
||||
print $output;
|
||||
}
|
||||
?>
|
||||
~~~
|
||||
|
||||
OK, so let's take a look at the Gallery so far:
|
||||
|
||||
You will notice that the returned date value for the latest photo added is displaying the UNIX timestamp instead of in a more readable format. This can be changed by altering the 'print' statement to include a PHP 'date' function:
|
||||
|
||||
~~~php
|
||||
<?php
|
||||
if ($selected_gallery_total != 0) {
|
||||
$output = '<i>There are currently ' . $selected_gallery_total . ' photos in this gallery.';
|
||||
$output .= 'Last one added on ' . date("l, jS F, Y", $latest_photo) . '.</i>';
|
||||
print $output;
|
||||
}
|
||||
?>
|
||||
~~~
|
||||
|
||||
The values that I've entered are from <a href="http://php.net/manual/en/function.date.php">this page</a> on <a href="http://php.net">PHP.net</a>, and can be changed according on how you want the date to be displayed.
|
||||
|
||||
As I've added all of these photos today, then the correct dates are being displayed. However, on the client's original website, the majority of these photos were pubished several months or years ago, and I'd like the new website to still reflect the original created dates. As opposed to modifying each individual photograph, I'll be doing this in bulk in my next post.
|
41
source/_posts/2010-08-17-better-photo-gallery-2.md
Normal file
41
source/_posts/2010-08-17-better-photo-gallery-2.md
Normal file
|
@ -0,0 +1,41 @@
|
|||
---
|
||||
title: Create a Better Photo Gallery in Drupal - Part 2
|
||||
slug: create-better-photo-gallery-drupal-part-2
|
||||
tags:
|
||||
- Drupal Planet
|
||||
- Drupal 6
|
||||
- Photo Gallery
|
||||
- SQL
|
||||
- Sequel Pro
|
||||
- UNIX Timestamp
|
||||
---
|
||||
At the end of my last post, I'd finished creating the first part of the new photo gallery, but I wanted to change the dates of the published photos to reflect the ones on the client's original website.
|
||||
|
||||
Firstly, I'll refer to the previous list of published galleries that I created before, and create something different that also displays the created and modified dates. Picking the node ID of the required gallery, I used the following SQL query to display a list of photos.
|
||||
|
||||
~~~sql
|
||||
SELECT n.title, n.nid, n.created, n.changed, p.field_gallery_nid
|
||||
FROM node n, content_type_photo pWHERE n.type = 'photo'
|
||||
AND p.field_gallery_nid = 103AND n.nid = p.nid
|
||||
ORDER BY n.nid ASC;
|
||||
~~~
|
||||
|
||||
When I look back at the old photo gallery, I can see that the previous 'last added' date was June 27, 2008. So, how do I update my new photos to reflect that date? Using <http://www.onlineconversion.com/unix_time.htm>, I can enter the required date in its readable format, and it will give me the equivilent UNIX timestamp. To keep things relatively simple, I'll set all photos within this gallery to the same time.
|
||||
|
||||
The result that I'm given is '1217149200'. I can now use an UPDATE statement within another SQL query to update the created and modified dates.
|
||||
|
||||
~~~sql
|
||||
UPDATE node
|
||||
INNER JOIN content_type_photo
|
||||
ON node.nid = content_type_photo.nid
|
||||
SET
|
||||
node.created = 1217149200,
|
||||
node.changed = 1217149200
|
||||
WHERE content_type_photo.field_gallery_nid = 103
|
||||
~~~
|
||||
|
||||
Now when I query the database, both the created and modified databases have been updated, and when I return to the new photo gallery, the updated value is being displayed.
|
||||
|
||||
Once the changes have been applied, it's a case of repeating the above process for each of the required galleries.
|
||||
|
||||
In the next post, I'll explain how to add a count of published galleries and photos on the main photo gallery page, as well as how to install and configure the [Shadowbox](http://drupal.org/project/shadowbox) module.
|
23
source/_posts/2010-08-20-image-caption-module.md
Normal file
23
source/_posts/2010-08-20-image-caption-module.md
Normal file
|
@ -0,0 +1,23 @@
|
|||
---
|
||||
title: Review of the Image Caption Module
|
||||
slug: review-image-caption-module
|
||||
tags:
|
||||
- Drupal Planet
|
||||
- Drupal 6
|
||||
- Modules
|
||||
- ImageField
|
||||
- Image Caption
|
||||
---
|
||||
Up until as recent as last week, whenever I added an image into one of my Blog posts, I was manually adding the caption below each image and styling it accordingly. That was until I installed the [Image Caption](http://drupal.org/project/image_caption) module.
|
||||
|
||||
The Image Caption module uses jQuery to dynamically add captions to images. Here is a walkthrough of the process that I followed to install and configure the module. As always, I used Drush to download and enable the module, then visited the Image Caption Settings page (admin/settings/image_caption). Here, I select which node types should be included in image captioning. In my case, I only wanted this to apply to Blog posts.
|
||||
|
||||
As I use the [FileField](http://drupal.org/project/filefield), [ImageField](http://drupal.org/project/imagefield) and [Insert](http://drupal.org/project/insert) modules to add images to my posts, as opposed to via a WYSIWYG editor, I'm able to add the CSS class of 'caption' to my images.
|
||||
|
||||
Now, all images inserted this way will have the CSS class of 'caption'.
|
||||
|
||||
As the Image Caption module uses the image's title tag to create the displayed caption, I enabled the custom title text for my Image field so that when I upload an image, I'm prompted to enter text for the caption.
|
||||
|
||||
This results in a span called `image-caption-container` around the inserted image, and a caption below it called `image-caption` containing the text.
|
||||
|
||||
All that's left is to style these classes within your CSS stylesheet.
|
28
source/_posts/2010-10-10-create-apply-patches.md
Normal file
28
source/_posts/2010-10-10-create-apply-patches.md
Normal file
|
@ -0,0 +1,28 @@
|
|||
---
|
||||
title: How to Create and Apply Patches
|
||||
slug: create-and-apply-patches
|
||||
tags:
|
||||
- Drupal Planet
|
||||
- Drupal 6
|
||||
- Modules
|
||||
- Patch
|
||||
---
|
||||
Earlier this year, I posted a solution to [an issue](http://drupal.org/node/753898) on the Drupal.org issue queue. Originally, I just posted the code back onto the issue, but have now created a patch that can easily be applied to any Drupal 6 installation. Here is a run-through of the process of creating and applying a patch. In this case, I made changes to the `user_pass_validate()` function that's found within `modules/user/user.pages.inc`.
|
||||
|
||||
To begin with, a download a fresh copy of Drupal 6.19 and created a copy of the original user.pages.inc file. Within the duplicate file, I made the same changes to the function that I did in earlier code, and saved the changes. Now, within my Terminal, I can navigate to Drupal's root directory and create the patch.
|
||||
|
||||
diff -rup modules/user/user.pages.inc modules/user/user.pages2.inc > /Users/oliver/Desktop/different_messages_for_blocked_users.patch
|
||||
|
||||
This command compares the differences between the two files, and creates the specified patch file.
|
||||
|
||||
To apply the patch to my Drupal installation, I go back to Terminal and run the following code:
|
||||
|
||||
patch -p0 < /Users/oliver/Desktop/different_messages_for_blocked_users.patch
|
||||
|
||||
If, for some reason, I need to reverse the patch, I can run this code:
|
||||
|
||||
patch -p0 -R < /Users/oliver/Desktop/different_messages_for_blocked_users.patch
|
||||
|
||||
And that's it!
|
||||
|
||||
There is also a Git patch creation workflow, which is described at <http://groups.drupal.org/node/91424>. Thanks to [Randy Fay](http://randyfay.com) for making me aware of this, and suggesting a slight change to my original patch creation command.
|
31
source/_posts/2010-10-13-better-photo-gallery-2.md
Normal file
31
source/_posts/2010-10-13-better-photo-gallery-2.md
Normal file
|
@ -0,0 +1,31 @@
|
|||
---
|
||||
title: Create a Better Photo Gallery in Drupal - Part 3
|
||||
slug: create-better-photo-gallery-drupal-part-3
|
||||
---
|
||||
The next part of the new gallery that I want to implement is to group the galleries by their respective categories. The first step is to edit my original photo_gallery view and add an additional display.
|
||||
|
||||
I've called it 'Taxonomy', and it's similar to the original 'All Galleries' view. The differences are that I've added the taxonomy term as an argument, removed the header, and updated the path to be `gallery/%`. The other thing that I need to do is overwrite the output of the original 'All Galleries' View by creating a file called `views-view--photo-gallery--page-1.tpl.php` and placing it within my theme directory.
|
||||
|
||||
Within that file, I can remove the standard content output. This still outputs the heading information from the original View. I can now use the function called 'views_embed_view' to embed my taxonomy display onto the display. The views_embed_view function is as follows:
|
||||
|
||||
~~~php
|
||||
<?php views_embed_view('my_view', 'block_1', $arg1, $arg2); ?>
|
||||
~~~
|
||||
|
||||
So, to display the galleries that are assigned the taxonomy of 'tournaments', I can use the following:
|
||||
|
||||
~~~php
|
||||
<?php print views_embed_view('photo_gallery', 'page_2', 'tournaments'); ?>
|
||||
~~~
|
||||
|
||||
To reduce the amount of code needed, I can use the following 'while' loop to generate the same code for each taxonomy term. It dynamically retrieves the relevant taxonomy terms from the database, and uses each name as the argument for the view.
|
||||
|
||||
~~~php
|
||||
<?php
|
||||
$terms = db_query("SELECT * FROM {term_data} WHERE vid = 1");
|
||||
while ($term = db_fetch_array($terms)) {
|
||||
print '<h3>' . $term['name'] . '</h3>';
|
||||
print views_embed_view('gallery', 'page_2', $term['name']);
|
||||
}
|
||||
?>
|
||||
~~~
|
53
source/_posts/2010-10-22-better-photo-gallery-21.md
Normal file
53
source/_posts/2010-10-22-better-photo-gallery-21.md
Normal file
|
@ -0,0 +1,53 @@
|
|||
---
|
||||
title: Create a Better Photo Gallery in Drupal - Part 2.1
|
||||
slug: create-better-photo-gallery-drupal-part-21
|
||||
---
|
||||
Today, I realised that I hadn't published the code that I used to create the total figures of galleries and photos at the top of the gallery (I said at the end of <a title="Create a Better Photo Gallery in Drupal - Part 2" href="internal:node/74">Part 2</a> that I'd include it in <a title="Create a Better Photo Gallery in Drupal - Part 3" href="internal:node/75">Part 3</a>, but I forgot). So, here it is:
|
||||
|
||||
~~~php
|
||||
<?php
|
||||
|
||||
// Queries the database and returns a list of nids of published galleries.
|
||||
$galleries = db_query("SELECT nid FROM {node} WHERE type = 'gallery' AND status = 1");
|
||||
// Resets the number of photos.
|
||||
$output = 0;
|
||||
// Prints a list of nids of published galleries.
|
||||
while($gallery = db_fetch_array($galleries)) {
|
||||
$gallery_id = $gallery['nid'];
|
||||
$photos = $photos + db_result(db_query("SELECT COUNT(*) FROM node n, content_type_photo ctp WHERE n.status = 1 AND n.type = 'photo' AND ctp.field_gallery_nid = $gallery_id AND n.nid = ctp.nid"));
|
||||
}
|
||||
|
||||
// Prints the output.
|
||||
print 'There ';
|
||||
if($photos == 1) {
|
||||
print 'is';
|
||||
}
|
||||
else {
|
||||
print 'are';
|
||||
}
|
||||
print ' currently ';
|
||||
print $photos . ' ';
|
||||
if($photos == 1) {
|
||||
print 'photo';
|
||||
}
|
||||
else {
|
||||
print 'photos';
|
||||
}
|
||||
print ' in ';
|
||||
|
||||
// Counts the number of published galleries on the site.
|
||||
$galleries = db_result(db_query("SELECT COUNT(*) FROM {node} WHERE TYPE = 'gallery' AND STATUS = 1"));
|
||||
|
||||
// Prints the number of published galleries.
|
||||
print $galleries;
|
||||
if ($galleries == 1) {
|
||||
print ' gallery';
|
||||
}
|
||||
else {
|
||||
print ' galleries';
|
||||
}
|
||||
print '.';
|
||||
?>
|
||||
~~~
|
||||
|
||||
It was applied to the view as a header which had the input format set to PHP code.
|
37
source/_posts/2010-11-04-regular-expressions-search.md
Normal file
37
source/_posts/2010-11-04-regular-expressions-search.md
Normal file
|
@ -0,0 +1,37 @@
|
|||
---
|
||||
title: Use Regular Expressions to Search and Replace in Coda or TextMate
|
||||
slug: use-regular-expressions-search-and-replace-coda-or-textmate
|
||||
tags:
|
||||
- Taxonomy
|
||||
- Sequel Pro
|
||||
- Database
|
||||
- Coda
|
||||
- Regular Expression
|
||||
- TextMate
|
||||
---
|
||||
As in <span class="nodepicker-link">the </span><a href="internal:node/35" title="Quickly adding a taxonomy term to multiple nodes using SQL">original post</a>, I'd generated a list of node ID values, and needed to add structure the SQL update statment formatted in a certain way. However, I changed my inital query slightly to out put the same nid value twice.
|
||||
|
||||
~~~sql
|
||||
SELECT nid, nid FROM node WHERE TYPE = 'blog' ORDER BY nid ASC;
|
||||
~~~
|
||||
|
||||
Then, I could select all of the returned rows, copy the values, and paste them into Coda:
|
||||
|
||||
As before, I needed my SQL update statement to be in the following format:
|
||||
|
||||
~~~sql
|
||||
INSERT INTO term_node VALUE (nid, vid, tid), (nid2, vid2, tid);
|
||||
~~~
|
||||
|
||||
As I mentioned previously, the nid and vid values are the same for each node, and the tid will remain constant. In this case, the tid value that I needed to use was '63'.
|
||||
|
||||
So, using the 'Find and Replace' function within Coda, combined with [regular expressions](http://en.wikipedia.org/wiki/Regular_expression) (regex), I can easily format the values as needed. To begin with, I need to ensure that the RegEx search option is enabled, and that I'm using the correct escape character.
|
||||
|
||||
The first thing that I wanted to do was add the seperating comma between the two values. To do this, I
|
||||
perform a search for `\s*\t`. This searches for everything that is whitespace AND is a tab value. I can then add the comma as the replacement for each result.
|
||||
|
||||
All 31 lines have been changed.
|
||||
|
||||
Next, I can use `\n` to target the lines between the rows. I'll replace it with the next comma, the number 63 (the tid value), the closing bracket, another comma, re-add the line and add the opening bracket.
|
||||
|
||||
The only two lines that aren't changed are the first and last, as they don't have any line breaks following them. I can complete these lines manually. Now all I need to do is add the beginning of the SQL update statement, then copy and paste it into Sequel Pro.
|
19
source/_posts/2011-02-14-typekit-fonts.md
Normal file
19
source/_posts/2011-02-14-typekit-fonts.md
Normal file
|
@ -0,0 +1,19 @@
|
|||
---
|
||||
title: Easily Embed TypeKit Fonts into your Drupal Website
|
||||
slug: easily-embed-typekit-fonts-your-drupal-website
|
||||
tags:
|
||||
- Drupal Planet
|
||||
- Drupal 6
|
||||
- TypeKit
|
||||
---
|
||||
To begin with, you will need to [register for a TypeKit account](https://typekit.com/plans) - there is a free version if you just want to try it out.
|
||||
|
||||
Next, you'll need to create a kit that contains the fonts that you want to use on your website. I've used [FF Tisa Web Pro](http://typekit.com/fonts/ff-tisa-web-pro).
|
||||
|
||||
Under 'Kit Settings', ensure that your website domain (e.g. mysite.com) is listed under 'Domains'.
|
||||
|
||||
Download and install the [@font-your-face](http://drupal.org/project/fontyourface) module onto your Drupal site, and to go admin/settings/fontyourface to configure it. Enter [your TypeKit API key](https://typekit.com/account/tokens), and click 'Import Typekit' to import your kits and fonts.
|
||||
|
||||
Go to admin/build/themes/fontyourface, and click 'Browse fonts to enable'. Click on the name of the font that you want to enable, check 'Enabled', and click 'Edit font' to save your changes.
|
||||
|
||||
With the font enabled, you can now use it in your CSS.
|
18
source/_posts/2011-03-15-number-of-facebook-fans.md
Normal file
18
source/_posts/2011-03-15-number-of-facebook-fans.md
Normal file
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
title: Display the Number of Facebook fans in PHP
|
||||
slug: display-number-facebook-fans-php
|
||||
---
|
||||
Replace the $page_id value with your Page ID number (unless you want to show the number of fans for this site).You can find your Page ID by logging into your Facebook account, going to 'Adverts and Pages', clicking 'Edit page', and looking at the URL.
|
||||
|
||||
For example, mine is <https://www.facebook.com/pages/edit/?id=143394365692197&sk=basic>.
|
||||
|
||||
I've also wrapped the output in a number_format() function so that it properly formatted with commas etc - like where I've used it within the [Gold Event listing](http://www.horseandcountry.tv/events/paid) on the Horse & Country TV website.
|
||||
|
||||
~~~php
|
||||
$page_id = "143394365692197";
|
||||
$xml = @simplexml_load_file("http://api.facebook.com/restserver.php?method=facebook.fql.query&query=SELECT%20fan_count%20FROM%20page%20WHERE%20page_id=".$page_id."") or die ("a lot");
|
||||
$fans = $xml->page->fan_count;
|
||||
print number_format($fans);
|
||||
~~~
|
||||
|
||||
This code was originally found at <http://wp-snippets.com/display-number-facebook-fans>.
|
9
source/_posts/2011-03-31-proctors.md
Normal file
9
source/_posts/2011-03-31-proctors.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
title: Proctor & Stevenson
|
||||
slug: proctor-stevenson
|
||||
tags:
|
||||
- Personal
|
||||
---
|
||||
2 weeks ago, I handed in my notice of resignation to [Horse & Country TV](http://horseandcountry.tv)because I've been offered a new role at [Proctor & Stevenson](http://proctors.co.uk) - a Marketing Design and Communications agency in Bristol.
|
||||
|
||||
Proctors have an [extensive client list](http://www.proctors.co.uk/clients) - including [BMW](http://www.proctors.co.uk/clients/bmw-financial-services), [Panasonic](http://www.proctors.co.uk/clients/panasonic), the [Open University](http://www.proctors.co.uk/clients/open-university) and [VOSA](http://www.proctors.co.uk/clients/vosa), and it's going to be a fantastic opportunity for me to continue expanding my skillset whilst gaining vital experience.
|
7
source/_posts/2011-05-20-proctors-drupal-meetup.md
Normal file
7
source/_posts/2011-05-20-proctors-drupal-meetup.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
title: Proctors Hosting the next Drupal Meetup
|
||||
slug: proctors-hosting-next-drupal-meetup
|
||||
---
|
||||
My employer, [Proctor & Stevenson](http://www.proctors.co.uk), are going to be hosting the next Bristol & South West Drupal meetup on the 25th May at our offices.
|
||||
|
||||
You can [view more details](http://groups.drupal.org/node/147324), or register [on our website](http://www.proctors.co.uk/Drupal-SWUG-Meetup).
|
14
source/_posts/2011-05-23-imagefield-import-archive.md
Normal file
14
source/_posts/2011-05-23-imagefield-import-archive.md
Normal file
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
title: Imagefield Import Archive
|
||||
tags:
|
||||
- Drupal Planet
|
||||
- ImageField Import
|
||||
- Module Development
|
||||
---
|
||||
I've finally uploaded my first module onto Drupal.org!
|
||||
|
||||
I've written many custom modules, although the vast majority of them are either small tweaks for my own sites, or company/site-specific modules that wouldn't be good to anyone else, so there would be nothing achieved by contributing them back to the community. Previously, I've blogged about the [Imagefield Import](http://drupal.org/project/imagefield_import) module - a module that I use on a number of sites, both personal and for clients - and what I've looked for lately is for a way to speed up the process again. Gathering my images together and manually copying them into the import directory takes time - especially if I'm working somewhere with a slow Internet connection and I'm FTP-ing the images into the directory. Also, it's not always the easiest solution for site users - especially non-technical ones.
|
||||
|
||||
So, I wrote the Imagefield Import Archive module. Including comments, the module contains 123 lines, and builds upon the existing functionality of the Imagefield Import module by adding the ability for the user to upload a .zip archive of images. The archive is then moved into the specified import directory and unzipped before being deleted, and the user is directed straight to the standard Imagefield Import page where their images are waiting to be imported, just as usual.
|
||||
|
||||
The module is currently a [sandbox project](http://drupal.org/sandbox/opdavies/1165110) on Drupal.org, although I have applied for full project access so that I can be added as a fully-fledged downloadable module.
|
29
source/_posts/2011-08-28-multigroups-field-collections.md
Normal file
29
source/_posts/2011-08-28-multigroups-field-collections.md
Normal file
|
@ -0,0 +1,29 @@
|
|||
---
|
||||
title: Create Multigroups in Drupal 7 using Field Collections
|
||||
slug: create-multigroups-drupal-7-using-field-collections
|
||||
tags:
|
||||
- Drupal 7
|
||||
- Drupal Planet
|
||||
- CCK
|
||||
- Fields
|
||||
- Field Collection
|
||||
- Entity API
|
||||
- Multigroup
|
||||
---
|
||||
One of my favourite things lately in Drupal 6 has been CCK 3, and more specifically, the Content Multigroups sub-module. Basically this allows you to create a fieldset of various CCK fields, and then repeat that multiple times. For example, I use it on this site whist creating invoices for clients. I have a fieldset called 'Line Item', containing 'Description', 'Quantity' and 'Price' fields. With a standard fieldset, I could only have one instance of each field - however, using a multigroup, I can create multiple groups of line items which I then use within the invoice.
|
||||
|
||||
But at the time of writing this, there is no CCK 3 version for Drupal 7. So, I created the same thing using [Field Collection](http://drupal.org/project/field_collection) and [Entity](http://drupal.org/project/entity) modules.
|
||||
|
||||
With the modules uploaded and enabled, go to admin/structure/field-collections and create a field collection.
|
||||
|
||||
With the module enabled, you can go to your content type and add a Field Collection field. By default, the only available Widget type is 'Hidden'.
|
||||
|
||||
Next, go to admin/structure/field-collections and add some fields to the field collection - the same way that you would for a content type. For this collection is going to contain two node reference fields - Image and Link.
|
||||
|
||||
With the Field Collection created, I can now add it as a field within my content type.
|
||||
|
||||
Whilst this works perfectly, the field collection is not editable from the node edit form. You need to load the node, and the collection is displayed here with add, edit, and delete buttons. This wasn't an ideal solution, and I wanted to be able to edit the fields within the collection from the node edit form - the same way as I can using multigroups in Drupal 6.
|
||||
|
||||
After some searching I found [a link to a patch](http://drupal.org/node/977890#comment-4184524) which when applied adds a 'subform' widget type to the field collection field and allows for it to be embedded into, and editable from within the node form. Going back to the content type fields page, and clicking on 'Hidden' (the name of the current widget), I can change it to subform and save my changes.
|
||||
|
||||
With this change applied, when I go back to add or edit a node within this content type, my field collection will be easily editable directly within the form.
|
|
@ -0,0 +1,121 @@
|
|||
---
|
||||
title: How to Install and Configure Subversion (SVN) Server on Ubuntu
|
||||
slug: install-and-configure-subversion-svn-server-ubuntu
|
||||
tags:
|
||||
- SVN
|
||||
- Ubuntu
|
||||
- Version control
|
||||
---
|
||||
Recently, I needed to set up a Subversion (SVN) server on a Ubuntu Linux server. This post is going to outline the steps taken, and the commands used, to install and configure the service.
|
||||
|
||||
Note: As I was using Ubuntu, I was using the 'apt-get' command to download and install the software packages. If you're using a different distribution of Linux, then this command may be different. I'm also assuming that Apache is already installed.
|
||||
|
||||
Firstly, I'm going to ensure that all of my installed packages are up to date, and install any available updates.
|
||||
|
||||
$ sudo apt-get update
|
||||
|
||||
Now, I need to download the subversion, subversion-tools and libapache2 packages.
|
||||
|
||||
$ sudo apt-get install subversion subversion-tools libapache2-svn
|
||||
|
||||
These are all of the packages that are needed to run a Subversion server.
|
||||
|
||||
## Create subversion directory
|
||||
|
||||
Now, I need to create the directory where my repositories are going to sit. I've chosen this directory as I know that it's one that is accessible to my managed backup service.
|
||||
|
||||
$ sudo mkdir /home/svn
|
||||
|
||||
## Create a test repository
|
||||
|
||||
First, I'll create a new folder in which I'll create my test project, and then I'll create a repository for it.
|
||||
|
||||
$ sudo mkdir ~/test
|
||||
$ sudo svnadmin create /home/svn/test -m 'initial project structure'
|
||||
|
||||
This will create a new repository containing the base file structure.
|
||||
|
||||
## Adding files into the test project
|
||||
|
||||
$ cd ~/test
|
||||
$ mkdir trunk tags branches
|
||||
|
||||
I can now import these new directories into the test repository.
|
||||
|
||||
$ sudo svn import ~/test file:///home/svn/test -m 'Initial project directories'
|
||||
|
||||
This both adds and commits these new directories into the repository.
|
||||
|
||||
In order for Apache to access the SVN repositories, the `/home/svn` directory needs to be owned by the same user and group that Apache runs as. In Ubuntu, this is usually www-data. To change the owner of a directory, use the chown command.
|
||||
|
||||
$ sudo chown -R www-data:www-data /home/svn
|
||||
|
||||
## Configuring Apache
|
||||
|
||||
The first thing that I need to do is enable the dav_svn Apache module, using the a2enmod command.
|
||||
|
||||
$ sudo a2enmod dav_svn
|
||||
|
||||
With this enabled, now I need to modify the Apache configuration file.
|
||||
|
||||
$ cd /etc/apache2
|
||||
$ sudo nano apache2.conf
|
||||
|
||||
At the bottom of the file, add the following lines, and then save the file by pressing Ctrl+X.
|
||||
|
||||
~~~
|
||||
<Location "/svn">
|
||||
DAV svn
|
||||
SVNParentPath /home/svn
|
||||
</Location>
|
||||
~~~
|
||||
|
||||
With this saved, restart the Apache service for the changes to be applied.
|
||||
|
||||
sudo service apache2 restart
|
||||
|
||||
I can now browse through my test repository by opening Firefox, and navigating to `http://127.0.0.1/svn/test`. Here, I can now see my three directories, although they are currently all empty.
|
||||
|
||||
<img class="imagecache-blog imagecache image-caption caption" title="Viewing the test repository in Firefox" src="http://oliverdavies.co.uk/sites/default/files/imagecache/blog/images/blog/how-install-and-configure-subversion-svn-server-ubuntu/viewing-test-repository-firefox.png" alt="Image: Screenshot of the test SVN repository in Firefox">
|
||||
|
||||
## Securing my SVN repositories
|
||||
|
||||
Before I start committing any files to the test repository, I want to ensure that only authorised users can view it - currently anyone can view the repository and it's contents, as well as being able to checkout and commit files. To do this, I'm going to require the user to enter a username and a password before viewing or performing any actions with the repository.
|
||||
|
||||
Re-open apache2.conf, and replace the SVN Location information with this:
|
||||
|
||||
~~~~
|
||||
<Location "/svn">
|
||||
DAV svn
|
||||
SVNParentPath /home/svn
|
||||
AuthType Basic
|
||||
AuthName "My SVN Repositories"
|
||||
AuthUserFile /etc/svn-auth
|
||||
Require valid-user
|
||||
</Location>
|
||||
~~~~
|
||||
|
||||
Now I need to create the password file.
|
||||
|
||||
$ htpasswd -cm /etc/svn-auth oliver
|
||||
|
||||
I'm prompted to enter and confirm my password, and then my details are saved. The Apache service will need to be restarted again, and then the user will need to authenticate themselves before viewing the repositories.
|
||||
|
||||
<img class="imagecache-blog imagecache image-caption caption" title="Being prompted for authorisation" src="http://oliverdavies.co.uk/sites/default/files/imagecache/blog/images/blog/how-install-and-configure-subversion-svn-server-ubuntu/being-prompted-authorisation_0.png" alt="Image: Screenshot of the authorisation prompt when opening the repository">
|
||||
|
||||
## Checking out the repository and commiting files
|
||||
|
||||
For example, now want to checkout the files within my repository into a new directory called 'test2' within my home directory. Firstly, I need to create the new directory, and then I can issue the checkout command.
|
||||
|
||||
$ cd ~
|
||||
$ mkdir test2
|
||||
$ svn checkout http://127.0.0.1/svn/test/trunk test2
|
||||
|
||||
I'm passing the command two arguments - the first is the URL of the repository's trunk directory, and the second is the directory where the files are to be placed. As no files have been commited yet into the trunk, it appears to be empty - but if you perform an ls -la command, you'll see that there is a hidden .svn directory.
|
||||
|
||||
Now you can start adding files into the directory. Once you've created your files, perform a svn add command, passing in individual filenames as further arguments.
|
||||
|
||||
$ svn add index.php
|
||||
$ svn add *
|
||||
|
||||
With all the required files added, they can be committed using `svn commit -m 'commit message'` command, and the server can be updated using the svn up command.
|
9
source/_posts/2012-01-04-upgraded-drupal-7.md
Normal file
9
source/_posts/2012-01-04-upgraded-drupal-7.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
title: Site Upgraded to Drupal 7
|
||||
slug: site-upgraded-drupal-7
|
||||
---
|
||||
As the vast majority of the Drupal websites that I currently work on are built on Drupal 7, I thought that it was time that I upgraded this site. Following the [core upgrade process](http://drupal.org/node/570162) and the [CCK migration process](http://drupal.org/node/1144136), everything was upgraded smoothly without any issues.
|
||||
|
||||
I've upgraded a handful of essential contrib modules to the latest stable version, [Administration Menu](http://drupal.org/project/admin_menu), [Views](http://drupal.org/project/views) etc., and will continue upgrading the other modules on the site as time allows.
|
||||
|
||||
I also prefer [Bartik](http://drupal.org/project/bartik) to [Garland](http://drupal.org/project/garland) - but I will be creating a new custom theme when I get a chance.
|
27
source/_posts/2012-02-01-authorized-keys-passwordless-ssh.md
Normal file
27
source/_posts/2012-02-01-authorized-keys-passwordless-ssh.md
Normal file
|
@ -0,0 +1,27 @@
|
|||
---
|
||||
title: How to use Authorized Keys to Create a Passwordless SSH Connection
|
||||
slug: use-authorized-keys-create-passwordless-ssh-connection
|
||||
tags:
|
||||
- Linux
|
||||
- SSH
|
||||
---
|
||||
If you're accessing Linux servers or automating tasks between servers, rather than having to enter your user password every time, you can also use SSH public key authentication. This is a simple process that involves creating a local key and storing it within the *authorized_keys* file on the remote server.
|
||||
|
||||
1. Check if you already have a SSH key.
|
||||
`$ ssh-add -L`
|
||||
2. If you don't have one, create one.
|
||||
`$ ssh-keygen`
|
||||
2. Upload the key onto the server. Replace *myserver* with the hostname or IP address of your remote server.
|
||||
`$ ssh-copy-id myserver`
|
||||
|
||||
If you're using Mac OS X and you don't have ssh-copy-id installed, download and install [Homebrew](http://mxcl.github.com/homebrew "Homebrew") and run the `brew install ssh-copy-id` command.
|
||||
|
||||
If successful, you should now see a message like:
|
||||
|
||||
> Now try logging into the machine, with "ssh 'myserver'", and check in:
|
||||
>
|
||||
> ~/.ssh/authorized_keys
|
||||
>
|
||||
> to make sure we haven't added extra keys that you weren't expecting.
|
||||
|
||||
Now the next time that you SSH onto the server, it should log you in without prompting you for your password.
|
33
source/_posts/2012-04-16-omega-subtheme-drush-omega-tools.md
Normal file
33
source/_posts/2012-04-16-omega-subtheme-drush-omega-tools.md
Normal file
|
@ -0,0 +1,33 @@
|
|||
---
|
||||
title: Create an Omega Subtheme with LESS CSS Preprocessor using Omega Tools and Drush
|
||||
slug: create-omega-subtheme-less-css-preprocessor-using-omega-tools-and-drush
|
||||
tags:
|
||||
- Drupal 7
|
||||
- Omega
|
||||
- Theming
|
||||
- LESS
|
||||
- Drupal Planet
|
||||
- Drupal
|
||||
---
|
||||
In this tutorial I'll be showing how to create an [Omega](http://drupal.org/project/omega) subtheme using the [Omega Tools](http://drupal.org/project/omega_tools) module, and have it working with the [LESS CSS preprocessor](http://lesscss.org).
|
||||
|
||||
The first thing that I need to do is download the Omega theme and the Omega Tools and <a title="LESS module on drupal.org" href="http://drupal.org/project/less">LESS</a> modules, and then to enable both modules. I'm doing this using Drush, but you can of course do this via the admin interface at admin/modules.
|
||||
|
||||
$ drush dl less omega omega_tools;
|
||||
$ drush en -y less omega_tools
|
||||
|
||||
With the Omega Tools module enabled I get the drush omega-subtheme command that creates my Omega subtheme programatically. Using this command, I'm creating a new subtheme, enabling it and setting it as the default theme on my site.
|
||||
|
||||
$ drush omega-subtheme "Oliver Davies" --machine_name="oliverdavies" --enable --set-default
|
||||
|
||||
By default, four stylesheets are created within the subtheme's css directory. The first thing that I'm going to do is rename `global.css` to `global.less`.
|
||||
|
||||
$ mv css/global.css css/global.less
|
||||
|
||||
Now I need to find all references to global.css within my oliverdavies.info file. I did this using `$ nano oliverdavies.info`, pressing `Ctrl+W` to search, then `Ctrl+R` to replace, entering `global.css` as the search phrase, and then `global.less` as the replacement text. After making any changes to oliverdavies.info, I need to clear Drupal's caches for the changes to be applied.
|
||||
|
||||
$ drush cc all
|
||||
|
||||
I tested my changes by making some quick additions to my global.less file and reloading the page.
|
||||
|
||||
If your changes aren't applied, then confirm that your global.less file is enabled within your theme's configuration. I did this by going to admin/appearance/settings/oliverdavies, clicking on the Toggle styles tab within *Layout configuration* and finding global.less at the bottom of *Enable optional stylesheets*.
|
11
source/_posts/2012-04-17-nagios-centos.md
Normal file
11
source/_posts/2012-04-17-nagios-centos.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
title: Installing Nagios on CentOS
|
||||
slug: installing-nagios-centos
|
||||
tags:
|
||||
- Nagios
|
||||
- CentOS
|
||||
- Linux
|
||||
---
|
||||
A great post details that details the steps needed to install [Nagios](http://nagios.org) - a popular open source system and network monitoring software application - on CentOS.
|
||||
|
||||
<http://saylinux.net/story/009506/how-install-nagios-centos-55>
|
63
source/_posts/2012-04-19-custom-theme-templates.md
Normal file
63
source/_posts/2012-04-19-custom-theme-templates.md
Normal file
|
@ -0,0 +1,63 @@
|
|||
---
|
||||
title: Adding Custom Theme Templates in Drupal 7
|
||||
description: >
|
||||
Today, I had a situation where I was displaying a list of teasers for news article nodes. The article content type had several different fields assigned to it, including main and thumbnail images. In this case, I wanted to have different output and fields displayed when a teaser was displayed compared to when a complete node was displayed.
|
||||
slug: adding-custom-theme-templates-drupal-7
|
||||
tags:
|
||||
- Drupal Planet
|
||||
---
|
||||
Today, I had a situation where I was displaying a list of teasers for news article nodes. The article content type had several different fields assigned to it, including main and thumbnail images. In this case, I wanted to have different output and fields displayed when a teaser was displayed compared to when a complete node was displayed.
|
||||
|
||||
I have previously seen it done this way by adding this into in a node.tpl.php file:
|
||||
|
||||
~~~~
|
||||
if ($teaser) {
|
||||
// The teaser output.
|
||||
}
|
||||
else {
|
||||
// The whole node output.
|
||||
}
|
||||
~~~~
|
||||
|
||||
However, I decided to do something different and create a separate template file just for teasers. This is done using the hook_preprocess_HOOK function that I can add into my theme's template.php file.
|
||||
|
||||
The function requires the node variables as an argument - one of which is theme_hook_suggestions. This is an array of suggested template files that Drupal looks for and attempts to use when displaying a node, and this is where I'll be adding a new suggestion for my teaser-specific template. Using the `debug()` function, I can easily see what's already there.
|
||||
|
||||
~~~~php
|
||||
array (
|
||||
0 => 'node__article',
|
||||
1 => 'node__343',
|
||||
2 => 'node__view__latest_news',
|
||||
3 => 'node__view__latest_news__page',
|
||||
)
|
||||
~~~~
|
||||
|
||||
So, within my theme's template.php file:
|
||||
|
||||
~~~~php
|
||||
/**
|
||||
* Implementation of hook_preprocess_HOOK().
|
||||
*/
|
||||
function mytheme_preprocess_node(&$variables) {
|
||||
$node = $variables['node'];
|
||||
|
||||
if ($variables['teaser']) {
|
||||
// Add a new item into the theme_hook_suggestions array.
|
||||
$variables['theme_hook_suggestions'][] = 'node__' . $node->type . '_teaser';
|
||||
}
|
||||
}
|
||||
~~~~
|
||||
|
||||
After adding the new suggestion:
|
||||
|
||||
~~~~php
|
||||
array (
|
||||
0 => 'node__article',
|
||||
1 => 'node__343',
|
||||
2 => 'node__view__latest_news',
|
||||
3 => 'node__view__latest_news__page',
|
||||
4 => 'node__article_teaser',
|
||||
)
|
||||
~~~~
|
||||
|
||||
Now, within my theme I can create a new node--article-teaser.tpl.php template file and this will get called instead of the node--article.tpl.php when a teaser is loaded. As I'm not specifying the node type specifically and using the dynamic <em>$node->type</em> value within my suggestion, this will also apply for all other content types on my site and not just news articles.
|
16
source/_posts/2012-05-23-apache-text-files.md
Normal file
16
source/_posts/2012-05-23-apache-text-files.md
Normal file
|
@ -0,0 +1,16 @@
|
|||
---
|
||||
title: Prevent Apache from displaying text files within a web browser
|
||||
slug: prevent-apache-displaying-text-files-within-web-browser
|
||||
tags:
|
||||
- Apache
|
||||
- Code
|
||||
- Drupal
|
||||
---
|
||||
When you download [Drupal](http://drupal.org), there are several text files that are placed in the root of your installation. You don't want or need these to be visible to anyone attempting to view them in a browser - especially CHANGELOG.txt as that includes the exact version of Drupal you are running and could therefore have security implications. Rather than delete these files or change the file permissions manually for each file, I can add the following lines into my VirtualHost configuration:
|
||||
|
||||
<Files ~ "\.txt$">
|
||||
Order deny,allow
|
||||
Deny from all
|
||||
</Files>
|
||||
|
||||
This prevents any files with a .txt extension from being accessed and rendered in a web browser.
|
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
title: Checkout a specific revision from SVN from the command line
|
||||
slug: checkout-specific-revision-svn-command-line
|
||||
tags:
|
||||
- SVN
|
||||
- Version control
|
||||
---
|
||||
If you're checking out the repository for the first time:
|
||||
|
||||
svn checkout -r 1234 url://repository/path
|
||||
|
||||
If you already have the repository checked out:
|
||||
|
||||
svn up -r 1234
|
35
source/_posts/2012-05-23-date-popup-custom-form.md
Normal file
35
source/_posts/2012-05-23-date-popup-custom-form.md
Normal file
|
@ -0,0 +1,35 @@
|
|||
---
|
||||
title: How to add a date popup calendar onto a custom form
|
||||
slug: add-date-popup-calendar-custom-form
|
||||
tags:
|
||||
- Forms
|
||||
- Form API
|
||||
- Date
|
||||
- Calendar
|
||||
- Drupal 7
|
||||
- Drupal Planet
|
||||
- Drupal
|
||||
---
|
||||
First, I need to download the <a href="http://drupal.org/project/date" title="Date module on Drupal.org">Date</a> module, and make my module dependent on date_popup by adding the following line into my module's .info file.
|
||||
|
||||
dependencies[] = date_popup
|
||||
|
||||
Within my form builder function:
|
||||
|
||||
~~~php
|
||||
$form['date'] = array(
|
||||
'#title' => t('Arrival date'),
|
||||
|
||||
// Provided by the date_popup module
|
||||
'#type' => 'date_popup',
|
||||
|
||||
// Uses the PHP date() format - http://php.net/manual/en/function.date.php
|
||||
'#date_format' => 'j F Y',
|
||||
|
||||
// Limits the year range to the next two upcoming years
|
||||
'#date_year_range' => '0:+2',
|
||||
|
||||
// Default value must be in 'Y-m-d' format.
|
||||
'#default_value' => date('Y-m-d', time()),
|
||||
);
|
||||
~~~
|
24
source/_posts/2012-05-23-forward-domain-mod-rewrite.md
Normal file
24
source/_posts/2012-05-23-forward-domain-mod-rewrite.md
Normal file
|
@ -0,0 +1,24 @@
|
|||
---
|
||||
title: Forward one domain to another using mod_rewrite and .htaccess
|
||||
slug: forward-one-domain-another-using-modrewrite-and-htaccess
|
||||
tags:
|
||||
- .htaccess
|
||||
- Code
|
||||
- Drupal
|
||||
- Apache
|
||||
- mod_rewrite
|
||||
---
|
||||
Within the mod_rewrite section of your .htaccess file, add the following lines:
|
||||
|
||||
RewriteCond %{HTTP_HOST} ^yoursite\.co\.uk$
|
||||
RewriteRule (.*) http://yoursite.com/$1 [R=301,L]
|
||||
|
||||
This automatically forwards any users from http://yoursite.co.uk to http://yoursite.com. This can also be used to forward multiple domains:
|
||||
|
||||
RewriteCond %{HTTP_HOST} ^yoursite\.co\.uk$ [OR]
|
||||
RewriteCond %{HTTP_HOST} ^yoursite\.info$ [OR]
|
||||
RewriteCond %{HTTP_HOST} ^yoursite\.biz$ [OR]
|
||||
RewriteCond %{HTTP_HOST} ^yoursite\.eu$
|
||||
RewriteRule (.*) http://yoursite.com/$1 [R=301,L]
|
||||
|
||||
If any of the RewriteCond conditions apply, then the RewriteRule is executed.
|
38
source/_posts/2012-05-23-info-file-drupal-7-theme.md
Normal file
38
source/_posts/2012-05-23-info-file-drupal-7-theme.md
Normal file
|
@ -0,0 +1,38 @@
|
|||
---
|
||||
title: Writing a .info file for a Drupal 7 theme
|
||||
slug: writing-info-file-drupal-7-theme
|
||||
tags:
|
||||
- Theming
|
||||
- Drupal Theming
|
||||
- Drupal
|
||||
- Code
|
||||
---
|
||||
~~~
|
||||
name = My Theme
|
||||
description = A description of my theme
|
||||
core = 7.x
|
||||
|
||||
# Add a base theme, if you want to use one.
|
||||
base = mybasetheme
|
||||
|
||||
# Define regions, otherwise the default regions will be used.
|
||||
regions[header] = Header
|
||||
regions[navigation] = Navigation
|
||||
regions[content] = Content
|
||||
regions[sidebar] = Sidebar
|
||||
regions[footer] = Footer
|
||||
|
||||
# Define which features are available. If none are specified, all the default
|
||||
# features will be available.
|
||||
features[] = logo
|
||||
features[] = name
|
||||
features[] = favicon
|
||||
|
||||
# Add stylesheets
|
||||
stylesheets[all][] = css/reset.css
|
||||
stylesheets[all][] = css/mytheme.css
|
||||
stylesheets[print][] = css/print.css
|
||||
|
||||
# Add javascript files
|
||||
styles[] = js/mytheme.js
|
||||
~~~
|
|
@ -0,0 +1,82 @@
|
|||
---
|
||||
title: Dividing Drupal's process and preprocess functions into separate files
|
||||
description: If you use a lot of process and preprocess functions within your Drupal theme, then your template.php can get very long and it can become difficult to find a certain piece of code. Following the example of the Omega theme, I've started separating my process and preprocess functions into their own files.
|
||||
slug: dividing-drupals-process-and-preprocess-functions-separate-files
|
||||
tags:
|
||||
- Drupal
|
||||
- Code
|
||||
- Theming
|
||||
- Preprocessing
|
||||
---
|
||||
If you use a lot of process and preprocess functions within your Drupal theme, then your template.php can get very long and it can become difficult to find a certain piece of code. Following the example of the <a href="http://drupal.org/project/omega" title="The Omega theme on Drupal.org">Omega theme</a>, I've started separating my process and preprocess functions into their own files. For example, mytheme_preprocess_node can be placed within a preprocess/node.inc file, and mytheme_process_page can be placed within process/page.inc.
|
||||
|
||||
The first step is to use the default mytheme_process() and mytheme_preprocess() functions to utilise my custom function. So within my template.php file:
|
||||
|
||||
~~~php
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implements hook_preprocess().
|
||||
*
|
||||
* Initialises the mytheme_invoke() function for the preprocess hook.
|
||||
*/
|
||||
function mytheme_preprocess(&$variables, $hook) {
|
||||
mytheme_invoke('preprocess', $hook, $variables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_process().
|
||||
*
|
||||
* Initialises the mytheme_invoke() function for the process hook.
|
||||
*/
|
||||
function mytheme_process(&$variables, $hook) {
|
||||
mytheme_invoke('process', $hook, $variables);
|
||||
}
|
||||
~~~
|
||||
|
||||
Now, to write the `mytheme_invoke()` function:
|
||||
|
||||
~~~php
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Invokes custom process and preprocess functions.
|
||||
*
|
||||
* @param string $type
|
||||
* The type of function we are trying to include (i.e. process or preprocess).
|
||||
*
|
||||
* @param array $variables
|
||||
* The variables array.
|
||||
*
|
||||
* @param string $hook
|
||||
* The name of the hook.
|
||||
*
|
||||
* @see mytheme_preprocess()
|
||||
* @see mytheme_process()
|
||||
*/
|
||||
function mytheme_invoke($type, $hook, &$variables) {
|
||||
global $theme_key;
|
||||
|
||||
// The name of the function to look for (e.g. mytheme_process_node).
|
||||
$function = $theme_key . '_' . $type . '_' . $hook;
|
||||
|
||||
// If the function doesn't exist within template.php, look for the
|
||||
// appropriate include file.
|
||||
if (!function_exists($function)) {
|
||||
// The file to search for (e.g. process/node.inc).
|
||||
$file = drupal_get_path('theme', $theme_key) . '/' . $type . '/' . $type . '-' . str_replace('_', '-', $hook) . '.inc';
|
||||
|
||||
// If the file exists, include it.
|
||||
if (is_file($file)) {
|
||||
include($file);
|
||||
}
|
||||
}
|
||||
|
||||
// Try to call the function again.
|
||||
if (function_exists($function)) {
|
||||
$function($variables);
|
||||
}
|
||||
}
|
||||
~~~
|
||||
|
||||
As `mytheme_invoke()` checks to see if the function already exists before searching for checking the include files, I could still add the functions into template.php as normal and this would override any corresponding include file.
|
17
source/_posts/2012-07-12-my-new-drupal-modules.md
Normal file
17
source/_posts/2012-07-12-my-new-drupal-modules.md
Normal file
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
title: My new Drupal modules
|
||||
description: After a busy few days, I've released two new contrib Drupal modules.
|
||||
tags:
|
||||
- Drupal
|
||||
- Drupal Modules
|
||||
- Drupal 6
|
||||
- Drupal 7
|
||||
- Drupal Planet
|
||||
- Accessibility
|
||||
---
|
||||
After a busy few days, I've released two new contrib Drupal modules:
|
||||
|
||||
* [Block Aria Landmark Roles](http://drupal.org/project/block_aria_landmark_roles) - Inspired by [Block Class](http://drupal.org/project/block_class), this module adds additional elements to the block configuration forms that allow users to assign a ARIA landmark role to a block.
|
||||
* [Nomensa Accessible Media Player](http://drupal.org/project/nomensa_amp) - Provides integration with Nomensa's [Accessible Media Player](https://github.com/nomensa/Accessible-Media-Player).
|
||||
|
||||
Documentation for both to follow shortly on Drupal.org.
|
14
source/_posts/2012-07-27-linux-journal.md
Normal file
14
source/_posts/2012-07-27-linux-journal.md
Normal file
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
title: Writing an Article for Linux Journal
|
||||
description: I'm absolutely delighted to announce that I'm going to be writing an article for Linux Journal magazine's upcoming Drupal special.
|
||||
slug: writing-article-linux-journal
|
||||
tags:
|
||||
- Drupal
|
||||
- Distributions
|
||||
- Installation Profiles
|
||||
- Writing
|
||||
- Linux Journal
|
||||
---
|
||||
I'm absolutely delighted to announce that I'm going to be writing an article for [Linux Journal](http://www.linuxjournal.com) magazine's upcoming Drupal special. The article is going to be entitled "Speeding Up Your Drupal Development Using Installation Profiles and Distributions" and will be mentioning existing distributions available on Drupal.org, but mainly focussing on the steps needed to create your own custom distribution. Needless to say, I'm quite excited about it!
|
||||
|
||||
The article is expected to be published in October.
|
|
@ -0,0 +1,25 @@
|
|||
---
|
||||
title: Display a Custom Menu in a Drupal 7 Theme Template File
|
||||
description: For reference, this is the code needed to display a menu in a Drupal 7 template file.
|
||||
slug: display-custom-menu-drupal-7-theme-template-file
|
||||
tags:
|
||||
- Drupal
|
||||
- Drupal 7
|
||||
- Drupal Planet
|
||||
- PHP
|
||||
- ARIA
|
||||
---
|
||||
For reference, this is the code needed to display a menu in a Drupal 7 template file, including the navigation ARIA role.
|
||||
|
||||
~~~php
|
||||
$menu_name = 'menu-footer-menu';
|
||||
$menu_id = 'footer-menu';
|
||||
print theme('links', array(
|
||||
'links' => menu_navigation_links($menu_name),
|
||||
'attributes' => array(
|
||||
'id' => $menu_id,
|
||||
'role' => 'navigation',
|
||||
'class'=> array('links', 'inline')
|
||||
)
|
||||
));
|
||||
~~~
|
12
source/_posts/2012-09-06-reflections-speaking-unifieddiff.md
Normal file
12
source/_posts/2012-09-06-reflections-speaking-unifieddiff.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
title: Reflections on speaking at UnifiedDiff
|
||||
description: Yesterday evening I went to and spoke at the <a href="http://www.unifieddiff.co.uk" title="UnifiedDiff">UnifiedDiff meetup</a> in Cardiff, having offered previously to do a presentation providing an introduction to Drupal.
|
||||
slug: reflections-speaking-unifieddiff
|
||||
---
|
||||
Yesterday evening I went along and spoke at the [UnifiedDiff meetup](http://www.unifieddiff.co.uk) in Cardiff, having offered previously to do a presentation providing an introduction to Drupal.
|
||||
|
||||
I'm an experienced Drupal Developer, but not an experienced public speaker (although I have done several user training sessions and Drupal demonstrations for clients previously), and I think that some of the nerves that I had beforehand were apparent during the presentation, and being the first speaker for the evening probably didn't help, although I did get a [nice tweet](https://twitter.com/craigmarvelley/status/243418608720543745) mid-way through.
|
||||
|
||||
Initially, after aiming for a 20-minute presentation plus Q&A, I think I wrapped up the presentation in around 14 minutes, although I did about 6 minutes of answering questions afterwards including the apparently mandatory "Why use Drupal compared to WordPress or Joomla?" question, some Drupal 8 and Symfony questions, as well as an interesting question about the White House development project after I'd listed it within a list of example sites. Next time, I think that some more detailed presenter notes are needed. Typically, as soon as it sat back in my seat, the majority of things that I'd managed to remember beforehand all came flooding back to me and I thought "I should have said that whilst I was up speaking".
|
||||
|
||||
Overall, considering my inexperience at speaking to this type of audience, I was fairly happy with my presentation, although I'm sure that I'll change my mind once I've watched the video of it on the UnifiedDiff website. Regardless, I think that it was a great experience and I enjoyed doing it, and I'd like to thank the organisers of UnifiedDiff for having me speak at their meetup. It was great to have a more relaxed conversation with some people after the other speakers had been up, and having introduced Drupal I would be more than happy to come back and do a more in-depth presentation if there is an interest for me to do so.
|
96
source/_posts/2012-10-25-my-sublime-text-2-settings.md
Normal file
96
source/_posts/2012-10-25-my-sublime-text-2-settings.md
Normal file
|
@ -0,0 +1,96 @@
|
|||
---
|
||||
title: My Sublime Text 2 settings
|
||||
description: <a href="http://www.sublimetext.com/2" title="Sublime Text 2">Sublime Text 2</a> has been my text editor of choice for the past few months, and I use it at home, in work, and on any virtual machines that I run. So rather than having to manually re-enter my settings each time, I thought that I'd document them here for future reference.
|
||||
tags:
|
||||
- Sublime Text
|
||||
---
|
||||
[Sublime Text 2](http://www.sublimetext.com/2) has been my text editor of choice for the past few months, and I use it at home, in work, and on any virtual machines that I run. So rather than having to manually re-enter my settings each time, I thought that I'd document them here for future reference. These preferences ensure that the code is compliant with [Drupal coding standards](http://drupal.org/coding-standards "Drupal coding standards on Drupal.org") - using two spaces instead of a tab, no trailing whitespace, blank line at the end of a file etc.
|
||||
|
||||
## Preferences
|
||||
|
||||
These can be changed by going to Preferences > Settings - User.
|
||||
|
||||
~~~
|
||||
{
|
||||
"color_scheme": "Packages/Theme - Aqua/Color Schemes/Tomorrow Night Aqua.tmTheme",
|
||||
"default_line_ending": "unix",
|
||||
"ensure_newline_at_eof_on_save": true,
|
||||
"fallback_encoding": "UTF-8",
|
||||
"file_exclude_patterns":
|
||||
[
|
||||
"*.pyc",
|
||||
"*.pyo",
|
||||
"*.exe",
|
||||
"*.dll",
|
||||
"*.obj",
|
||||
"*.o",
|
||||
"*.a",
|
||||
"*.lib",
|
||||
"*.so",
|
||||
"*.dylib",
|
||||
"*.ncb",
|
||||
"*.sdf",
|
||||
"*.suo",
|
||||
"*.pdb",
|
||||
"*.idb",
|
||||
".DS_Store",
|
||||
"*.class",
|
||||
"*.psd",
|
||||
"*.db",
|
||||
"*.sublime*"
|
||||
],
|
||||
"folder_exclude_patterns":
|
||||
[
|
||||
".svn",
|
||||
".git",
|
||||
".hg",
|
||||
"CVS",
|
||||
"FirePHPCore"
|
||||
],
|
||||
"font_options":
|
||||
[
|
||||
"no_bold",
|
||||
"no_italic"
|
||||
],
|
||||
"font_size": 16.0,
|
||||
"highlight_line": true,
|
||||
"ignored_packages":
|
||||
[
|
||||
],
|
||||
"line_padding_bottom": 1,
|
||||
"rulers":
|
||||
[
|
||||
80
|
||||
],
|
||||
"save_on_focus_lost": true,
|
||||
"shift_tab_unindent": true,
|
||||
"tab_size": 2,
|
||||
"theme": "Soda Light.sublime-theme",
|
||||
"translate_tabs_to_spaces": true,
|
||||
"trim_automatic_white_space": true,
|
||||
"trim_trailing_white_space_on_save": true,
|
||||
"word_wrap": false
|
||||
}
|
||||
~~~
|
||||
|
||||
## Key bindings
|
||||
|
||||
These can be changed by going to Preferences > Key Bindings - User.
|
||||
|
||||
~~~
|
||||
[
|
||||
{ "keys": ["alt+s"], "command": "toggle_side_bar" },
|
||||
{ "keys": ["alt+r"], "command": "reindent" }
|
||||
]
|
||||
~~~
|
||||
|
||||
## Packages
|
||||
|
||||
These are the packages that I currently have installed.
|
||||
|
||||
* [DocBlockr](https://github.com/spadgos/sublime-jsdocs "DocBlockr on GitHub")
|
||||
* [Drupal API](https://github.com/BrianGilbert/Sublime-Text-2-Goto-Drupal-API)
|
||||
* [LESS](https://github.com/danro/LESS-sublime)
|
||||
* [Package Control](http://wbond.net/sublime_packages/package_control)
|
||||
* [Sublime CodeIntel](http://github.com/Kronuz/SublimeCodeIntel)
|
||||
* [Theme - Soda](https://github.com/buymeasoda/soda-theme)
|
11
source/_posts/2012-11-15-accessible-bristol-site.md
Normal file
11
source/_posts/2012-11-15-accessible-bristol-site.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
title: Accessible Bristol site launched
|
||||
description: I'm happy to report that the Accessible Bristol was launched this week, on Drupal 7.
|
||||
tags:
|
||||
- Accessibility
|
||||
- Accessible Bristol
|
||||
- Nomensa
|
||||
---
|
||||
I'm happy to report that the [Accessible Bristol](http://www.accessiblebristol.org.uk) website was launched this week, on Drupal 7. The site's been developed over the past few months, and uses the [User Relationships](http://drupal.org/project/user_relationships) and [Privatemsg](http://drupal.org/project/privatemsg) modules to provide a community-based platform where people with an interest in accessibility can register and network with each other.
|
||||
|
||||
The group is hosting a launch event on the 28th November at the Council House, College Green, Bristol. Interested? More information is available at <http://www.accessiblebristol.org.uk/events/accessible-bristol-launch> or go to <http://buytickets.at/accessiblebristol/6434> to register.
|
|
@ -0,0 +1,15 @@
|
|||
---
|
||||
title: Open Sublime Text 2 from the Mac OS X Command Line
|
||||
slug: open-sublime-text-2-mac-os-x-command-line
|
||||
tags:
|
||||
- Sublime Text
|
||||
- Mac OS X
|
||||
- Terminal
|
||||
---
|
||||
Paste the following code into the Mac OS X Terminal, assuming that you've installed Sublime Text 2 into the /Applications folder.
|
||||
|
||||
$ ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/sublime
|
||||
|
||||
Now you can type `sublime <filename>` open a file or directory in Sublime Text, or `sublime .` to open the current directory.
|
||||
|
||||
You can also type `sublime --help` to see a list of the available commands.
|
|
@ -0,0 +1,58 @@
|
|||
---
|
||||
title: How to use SASS and Compass in Drupal 7 using Sassy
|
||||
slug: use-sass-and-compass-drupal-7-using-sassy
|
||||
tags:
|
||||
- Compass
|
||||
- CSS
|
||||
- Drupal
|
||||
- Drupal 7
|
||||
- Drupal Planet
|
||||
- LESS
|
||||
- Preprocessing
|
||||
- SASS
|
||||
- SCSS
|
||||
---
|
||||
I've recently started using <a href="http://sass-lang.com" title="SASS">SASS</a> rather than LESS to do my CSS preprocessing - namely due to its integration with <a href="http://compass-style.org" title="Compass">Compass</a> and it's built-in CSS3 mixins. There are three modules that provide the ability to use SASS within Drupal:
|
||||
|
||||
* [Sassy](http://drupal.org/project/sassy "Sassy module on drupal.org")
|
||||
* [Prepro](http://drupal.org/project/prepro "Prepro module on drupal.org")
|
||||
* [Libraries API](http://drupal.org/project/libraries "Libraries API module on drupal.org")
|
||||
|
||||
Alternatively, you could use a base theme like [Sasson](http://drupal.org/project/sasson "Sasson theme on drupal.org") that includes a SASS compiler.
|
||||
|
||||
## Download the PHPSass Library
|
||||
|
||||
The first thing to do is download the PHPSass library from [GitHub](https://github.com/richthegeek/phpsass "PHPSass on GitHub"), as this is a requirement of the Sassy module and we can't enable it without the library. So, in a Terminal window:
|
||||
|
||||
$ mkdir -p sites/all/libraries;
|
||||
$ cd sites/all/libraries;
|
||||
$ wget https://github.com/richthegeek/phpsass/archive/master.tar.gz;
|
||||
$ tar zxf master.tar.gz;
|
||||
$ rm master.tar.gz;
|
||||
$ mv phpsass-master/ phpsass
|
||||
|
||||
Or, if you're using Drush Make files:
|
||||
|
||||
libraries[phpsass][download][type] = "get"
|
||||
libraries[phpsass][download][url] = "https://github.com/richthegeek/phpsass/archive/master.tar.gz"
|
||||
|
||||
The PHPSass library should now be located at `sites/all/libraries/phpsass`.
|
||||
|
||||
## Download and enable the Drupal modules
|
||||
|
||||
This is easy if you use [Drush](http://drupal.org/project/drush):
|
||||
|
||||
$ drush dl libraries prepro sassy
|
||||
$ drush en -y libraries prepro sassy sassy_compass
|
||||
|
||||
Otherwise, download the each module from it's respective project page and place it within your `sites/all/modules` or `sites/all/modules/contrib` directory.
|
||||
|
||||
## Configuring the Prepro module
|
||||
|
||||
The Prepro module provides various settings that can be changed for each preprocessor. Go to `admin/config/media/prepro` to configure the module as required.
|
||||
|
||||
Personally, in development, I'd set caching to 'uncached' and the error reporting method to 'show on page'. In production, I'd change these to "cached" and "watchdog" respectively. I'd also set the output style to "compressed",
|
||||
|
||||
## Adding SASS files into your theme
|
||||
|
||||
With this done, you can now add SASS and SCSS files by adding a line like `stylesheets[all][] = css/base.scss` in your theme's .info file.
|
|
@ -0,0 +1,137 @@
|
|||
---
|
||||
title: Creating and using custom tokens in Drupal 7
|
||||
slug: creating-and-using-custom-tokens-drupal-7
|
||||
tags:
|
||||
- Drupal
|
||||
- Drupal Planet
|
||||
- Drupal 7
|
||||
- Tokens
|
||||
---
|
||||
This post outlines the steps required to create your own custom tokens in Drupal.
|
||||
|
||||
When writing the recent releases of the [Copyright Block](http://drupal.org/project/copyright_block) module, I used tokens to allow the user to edit and customise their copyright message and place the copyright_message:dates token in the desired position. When the block is rendered, the token is replaced by the necessary dates.
|
||||
|
||||
We will be using the fictional *foo* module to demonstrate this.
|
||||
|
||||
## Requirements
|
||||
|
||||
* [Token module](http://drupal.org/project/token)
|
||||
|
||||
## Recommended
|
||||
|
||||
* [Devel module](http://drupal.org/project/devel) - useful to run `dpm()` and `kpr()` functions
|
||||
* [Copyright Block module](http://drupal.org/project/copyright_block) - 7.x-2.x and 6.x-1.x use tokens, handy as a reference
|
||||
|
||||
## Implementing hook_token_info()
|
||||
|
||||
The first thing that we need to do is define the new token type and/or the token itself, along with it's descriptive text. To view the existing tokens and types, use `dpm(token_get_info());`, assuming that you have the [Devel module](http://drupal.org/project/devel) installed.
|
||||
|
||||
~~~php
|
||||
/**
|
||||
* Implements hook_token_info().
|
||||
*/
|
||||
function foo_token_info() {
|
||||
$info = array();
|
||||
|
||||
// Add any new tokens.
|
||||
$info['tokens']['foo']['bar'] = t('This is my new bar token within the foo type.');
|
||||
|
||||
// Return them.
|
||||
return $info;
|
||||
}
|
||||
~~~
|
||||
|
||||
In this case, the token called *bar* resides within the *foo* group.
|
||||
|
||||
If I needed to add a new token within an existing token type, such as 'node', the syntax would be `$info['tokens']['node']['bar']`.
|
||||
|
||||
## Implementing hook_tokens()
|
||||
|
||||
Now that the Token module is aware of our new token, we now need to determine what the token is replaced with. This is done using `hook_tokens()`. Here is the basic code needed for an implementation:
|
||||
|
||||
~~~php
|
||||
/**
|
||||
* Implements hook_tokens().
|
||||
*/
|
||||
function foo_tokens($type, $tokens, array $data = array(), array $options = array()) {
|
||||
$replacements = array();
|
||||
|
||||
// Code goes here...
|
||||
|
||||
// Return the replacements.
|
||||
return $replacements;
|
||||
}
|
||||
~~~
|
||||
|
||||
The first thing to check for is the type of token using an `if()` function, as this could be an existing type like 'node', 'user' or 'site', or a custom token type like 'foo'. Once we're sure that we're looking at the right type(s), we can use `foreach ($tokens as $name => $original)` to loop through each of the available tokens using a `switch()`. For each token, you can perform some logic to work out the replacement text and then add it into the replacements array using `$replacements[$original] = $new;`.
|
||||
|
||||
~~~php
|
||||
/**
|
||||
* Implements hook_tokens().
|
||||
*/
|
||||
function foo_tokens($type, $tokens, array $data = array(), array $options = array()) {
|
||||
$replacements = array();
|
||||
|
||||
// The first thing that we're going to check for is the type of token - node,
|
||||
// user etc...
|
||||
if ($type == 'foo') {
|
||||
// Loop through each of the available tokens.
|
||||
foreach ($tokens as $name => $original) {
|
||||
// Find the desired token by name
|
||||
switch ($name) {
|
||||
case 'bar':
|
||||
$new = '';
|
||||
|
||||
// Work out the value of $new...
|
||||
|
||||
// Add the new value into the replacements array.
|
||||
$replacements[$original] = $new;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Return the replacements.
|
||||
return $replacements;
|
||||
}
|
||||
~~~
|
||||
|
||||
## Example
|
||||
|
||||
An example from Copyright Block module:
|
||||
|
||||
~~~php
|
||||
/**
|
||||
* Implements hook_tokens().
|
||||
*/
|
||||
function copyright_block_tokens($type, $tokens, array $data = array(), array $options = array()) {
|
||||
$replacements = array();
|
||||
|
||||
if ($type == 'copyright_statement') {
|
||||
foreach ($tokens as $name => $original) {
|
||||
switch ($name) {
|
||||
case 'dates':
|
||||
$start_year = variable_get('copyright_block_start_year', date('Y'));
|
||||
$current_year = date('Y');
|
||||
|
||||
$replacements[$original] = $start_year < $current_year ? $start_year . '-' . $current_year : $start_year;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $replacements;
|
||||
}
|
||||
~~~
|
||||
|
||||
## Using token_replace()
|
||||
|
||||
With everything defined, all that we now need to do is pass some text through the `token_replace()` function to replace it with the values defined within `hook_token()`.
|
||||
|
||||
~~~php
|
||||
$a = t('Something');
|
||||
// This would use any token type - node, user etc.
|
||||
$b = token_replace($a);
|
||||
// This would only use foo tokens.
|
||||
$c = token_replace($a, array('foo'));
|
||||
~~~
|
|
@ -0,0 +1,15 @@
|
|||
---
|
||||
title: The Quickest way to Install Sublime Text 2 in Ubuntu
|
||||
slug: quickest-way-install-sublime-text-2-ubuntu
|
||||
tags:
|
||||
- Linux
|
||||
- Sublime Text
|
||||
- Ubuntu
|
||||
---
|
||||
After reading numerous blog posts about how to install [Sublime Text 2](http://www.sublimetext.com/2 "Sublime Text 2") in [Ubuntu](http://www.ubuntu.com/2 "Ubuntu"), this is definitely the quickest way! Just paste the following lines into your Terminal:
|
||||
|
||||
$ sudo add-apt-repository ppa:webupd8team/sublime-text-2
|
||||
$ sudo apt-get update
|
||||
$ sudo apt-get install sublime-text
|
||||
|
||||
After running this, Sublime Text 2 has been installed within the */usr/lib/sublime-text-2* directory and can be launched from the Dashboard, or by typing `subl`, `sublime-text` or `sublime-text-2` into a Terminal window.
|
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
title: Leaving Nomensa, Joining Precedent
|
||||
description: Yesterday was my last day working at Nomensa. Next week, I'll be starting as a Senior Developer at Precedent.
|
||||
tags:
|
||||
- Nomensa
|
||||
- Precedent
|
||||
- Personal
|
||||
---
|
||||
Yesterday was my last day working at [Nomensa](http://www.nomensa.com "Nomensa"). Next week, I'll be starting as a Senior Developer at [Precedent](http://www.precedent.co.uk "Precedent").
|
||||
|
||||
The last 14 months that I've been working at Nomensa have been absolutely fantastic, and had allowed me to work on some great projects for great clients - mainly [unionlearn](http://www.unionlearn.org "unionlearn") and [Digital Theatre Plus](http://www.digitaltheatreplus.com "Digital Theatre Plus"). I've learned so much about accessibility and web standards, and have pretty much changed my whole approach to front-end development to accommodate best practices. I've also been involved with the Drupal Accessibility group since starting at Nomensa, and have written several accessibility-focused Drupal modules, including the [Nomensa Accessible Media Player](http://drupal.org/project/nomensa_amp "The Nomensa Accessible Media Player Drupal module") module and the [Accessibility Checklist](http://drupal.org/project/a11y_checklist "The accessibility checklist for Drupal"). I'll definitely be continuing my interest in accessibility, championing best practices, and incorporating it into my future work wherever possible.
|
||||
|
||||
With that all said, I'm really looking forward to starting my new role at Precedent, tackling some new challenges, and I'm sure that it'll be as great a place to work as Nomensa was.
|
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
title: Some useful links for using SimpleTest in Drupal
|
||||
slug: some-useful-links-using-simpletest-drupal
|
||||
tags:
|
||||
- SimpleTest
|
||||
- TDD
|
||||
- Test Driven Development
|
||||
- Drupal Planet
|
||||
- Drupal
|
||||
---
|
||||
Here are some useful links that I've found when researching about unit testing in Drupal using SimpleTest:
|
||||
|
||||
* [An Introduction to Unit Testing in Drupal](http://www.lullabot.com/blog/articles/introduction-unit-testing-drupal "An Introduction to Unit Testing in Drupal")
|
||||
* [Module Developer's Guide to SimpleTest](http://www.lullabot.com/blog/articles/drupal-module-developers-guide-simpletest "Module Developer's Guide to SimpleTest")
|
||||
* [SimpleTest Tutorial (Drupal 6)](https://drupal.org/simpletest-tutorial "SimpleTest Tutorial (Drupal 6)")
|
||||
* [SimpleTest Tutorial (Drupal 7)](https://drupal.org/simpletest-tutorial-drupal7 "SimpleTest Tutorial (Drupal 7)")
|
||||
* [SimpleTest Reference](https://drupal.org/node/278126 "SimpleTest Reference")
|
||||
* [Testing with SimpleTest](https://drupal.org/node/1128366 "Testing with SimpleTest")
|
|
@ -0,0 +1,40 @@
|
|||
---
|
||||
title: Creating Local and Staging sites with Drupal's Domain Module Enabled
|
||||
slug: creating-local-and-staging-sites-drupals-domain-module-enabled
|
||||
tags:
|
||||
- Drupal
|
||||
- Drupal Planet
|
||||
- Databases
|
||||
- Domain
|
||||
- Table Prefixing
|
||||
---
|
||||
The [Domain Access project](https://drupal.org/project/domain "The Domain Access project on Drupal.org") is a suite of modules that provide tools for running a group of affiliated sites from one Drupal installation and a single shared database. The issue is that the domains are stored within the database so these are copied across when the data is migrated between environments, whereas the domains are obviously going to change.
|
||||
|
||||
Rather than changing the domain settings within the Domain module itself, the best solution I think is to use table prefixes and create a different domain table per environment. With a live, staging and local domains, the tables would be named as follows:
|
||||
|
||||
~~~~
|
||||
live_domain
|
||||
local_domain
|
||||
staging_domain
|
||||
~~~~
|
||||
|
||||
Within each site's settings.php file, define the prefix for the domain table within the databases array so that each site is looking at the correct table for its environment.
|
||||
|
||||
~~~~php
|
||||
$databases['default']['default'] = array(
|
||||
'driver' => 'mysql',
|
||||
'database' => 'foobar',
|
||||
'username' => 'foo',
|
||||
'password' => 'bar',
|
||||
'host' => 'localhost',
|
||||
'prefix' => array(
|
||||
'default' => '',
|
||||
'domain' => 'local_', // This will use the local_domain table.
|
||||
// Add any other prefixed tables here.
|
||||
),
|
||||
);
|
||||
~~~~
|
||||
|
||||
Within each environment-specific domain table, update the subdomain column to contain the appropriate domain names.
|
||||
|
||||
**Update:** I've just found out about the Domain Alias sub-module, which you can enable and add aliases to each domain, so you could add the aliases in this way also.
|
12
source/_posts/2013-07-26-going-to-drupalcon.md
Normal file
12
source/_posts/2013-07-26-going-to-drupalcon.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
title: Going to DrupalCon
|
||||
slug: going-drupalcon
|
||||
tags:
|
||||
- DrupalCon
|
||||
- Precedent
|
||||
---
|
||||
[Precedent](http://www.precedent.co.uk) are sending myself and two of our other Drupal Developers to [Drupalcon Prague](http://prague2013.drupal.org).
|
||||
|
||||
Having wanted to attend the last few Drupalcons (London, especially) but not being able to, I'm definitely looking forward to this one.
|
||||
|
||||
See you there!
|
28
source/_posts/2013-09-06-create-zen-sub-theme-using-drush.md
Normal file
28
source/_posts/2013-09-06-create-zen-sub-theme-using-drush.md
Normal file
|
@ -0,0 +1,28 @@
|
|||
---
|
||||
title: Create a Zen Sub-theme Using Drush
|
||||
description: How to quickly create a Zen sub-theme using Drush.
|
||||
tags:
|
||||
- Drupal
|
||||
- Drupal Planet
|
||||
- Drush
|
||||
- Zen
|
||||
- Theming
|
||||
---
|
||||
First, download the [Zen](https://drupal.org/project/zen "The Zen theme") theme if you haven't already done so.
|
||||
|
||||
$ drush dl zen
|
||||
|
||||
This will now enable you to use the "drush zen" command.
|
||||
|
||||
$ drush zen "Oliver Davies" oliverdavies --description="A Zen sub-theme for oliverdavies.co.uk" --without-rtl
|
||||
|
||||
The parameters that I'm passing it are:
|
||||
|
||||
1. The human-readable name of the theme.
|
||||
2. The machine-readable name of the theme.
|
||||
3. The description of the theme (optional).
|
||||
4. A flag telling Drush not to include any right-to-left elements within my sub-theme as these aren't needed (optional).
|
||||
|
||||
This will create a new theme in sites/all/themes/oliverdavies.
|
||||
|
||||
For further help, type `$ drush help zen` to see the Drush help page for the zen command.
|
18
source/_posts/2013-11-27-useful-vagrant-commands.md
Normal file
18
source/_posts/2013-11-27-useful-vagrant-commands.md
Normal file
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
title: Useful Vagrant Commands
|
||||
description: Here are the basic commands that you need to adminster a virtual machine using <a href="http://vagrantup.com" title="The Vagrant Home page">Vagrant</a>.
|
||||
---
|
||||
[Vagrant](http://www.vagrantup.com "About Vagrant") is a tool for managing virtual machines within [VirtualBox](https://www.virtualbox.org) from the command line. Here are some useful commands to know when using Vagrant:
|
||||
|
||||
Command | Description
|
||||
:-|:-
|
||||
vagrant init {box} | Initialise a new VM in the current working directory. Specify a box name, or "base" will be used by default.
|
||||
vagrant status | Shows the status of the Vagrant box(es) within the current working directory tree.
|
||||
vagrant up (--provision) | Boots the Vagrant box. Including "–provision" also runs the "vagrant provision" command.
|
||||
vagrant reload (--provision) | Reloads the Vagrant box. Including "--provision" also runs the "vagrant provision" command.
|
||||
vagrant provision | Provision the Vagrant box using Puppet.
|
||||
vagrant suspend | Suspend the Vagrant box. Use "vagrant up" to start the box again.
|
||||
vagrant halt (-f) | Halt the Vagrant box. Use -f to forcefully shut down the box without prompting for confirmation.
|
||||
vagrant destroy (-f) | Destroys a Vagrant box. Use -f to forcefully shut down the box without prompting for confirmation.
|
||||
|
||||
The full Vagrant documentation can be found at <http://docs.vagrantup.com/v2/>.
|
|
@ -0,0 +1,20 @@
|
|||
---
|
||||
title: Quickly Apply Patches Using Git and curl or wget
|
||||
description: How to quickly download a patch file and apply it to a Git repository in one line
|
||||
tags:
|
||||
- Git
|
||||
- Drupal Planet
|
||||
---
|
||||
Testing a patch file is usually a two-step process. First you download the patch file from the source, and then you run a separate command to apply it.
|
||||
|
||||
You can save time and typing by running the two commands on one line:
|
||||
|
||||
$ curl http://drupal.org/files/[patch-name].patch | git apply
|
||||
|
||||
Or, if you don't have curl installed, you can use wget:
|
||||
|
||||
$ wget -q -O - http://drupal.org/files/[patch-name].patch | git apply
|
||||
|
||||
These commands need to be run within the root of your Git repository (i.e. where the .git directory is).
|
||||
|
||||
These snippets were taken from [Applying Patches with Git](https://drupal.org/node/1399218) on Drupal.org.
|
|
@ -0,0 +1,36 @@
|
|||
---
|
||||
title: Download Different Versions of Drupal with Drush
|
||||
description: How to download different versions of Drupal core using Drush.
|
||||
slug: download-different-versions-drupal-drush
|
||||
tags:
|
||||
- Drupal
|
||||
- Drupal Planet
|
||||
- Drush
|
||||
---
|
||||
If you use [Drush](https://raw.github.com/drush-ops/drush/master/README.md "About Drush"), it's likely that you've used the `drush pm-download` (or `drush dl` for short) command to start a new project. This command downloads projects from Drupal.org, but if you don't specify a project or type "drush dl drupal", the command will download the current stable version of Drupal core. Currently, this will be Drupal 7 with that being the current stable version of core at the time of writing this post.
|
||||
|
||||
But what if you don't want Drupal 7?
|
||||
|
||||
I still maintain a number of Drupal 6 sites and occassionally need to download Drupal 6 core as opposed to Drupal 7. I'm also experimenting with Drupal 8 so I need to download that as well.
|
||||
|
||||
By declarding the core version of Drupal, such as "drupal-6", Drush will download that instead.
|
||||
|
||||
$ drush dl drupal-6
|
||||
|
||||
This downloads the most recent stable version of Drupal 6. If you don't want that, you can add the --select and additionally the --all options to be presented with an entire list to chose from.
|
||||
|
||||
$ drush dl drupal-6 --select
|
||||
$ drush dl drupal-6 --select --all
|
||||
|
||||
If you want the most recent development version, just type:
|
||||
|
||||
$ drush dl drupal-6.x
|
||||
|
||||
The same can be done for other core versions of Drupal, from Drupal 5 upwards.
|
||||
|
||||
# This will download Drupal 5
|
||||
$ drush dl drupal-5
|
||||
# This will download Drupal 8
|
||||
$ drush dl drupal-8
|
||||
|
||||
For a full list of the available options, type "drush help pm-download" into a Terminal window or take a look at the entry on [drush.ws](http://drush.ws/#pm-download, "The entry for pm-download on drush.ws").
|
28
source/_posts/2014-01-15-some-useful-git-aliases.md
Normal file
28
source/_posts/2014-01-15-some-useful-git-aliases.md
Normal file
|
@ -0,0 +1,28 @@
|
|||
---
|
||||
title: Some Useful Git Aliases
|
||||
tags:
|
||||
- Git
|
||||
---
|
||||
Here are some bash aliases that I use and find helpful for quickly writing Git and Git Flow commands. These should be placed within your `~/.bashrc` or `~/.bash_profile` file:
|
||||
|
||||
~~~~
|
||||
alias gi="git init"
|
||||
alias gcl="git clone"
|
||||
alias gco="git checkout"
|
||||
alias gs="git status"
|
||||
alias ga="git add"
|
||||
alias gaa="git add --all"
|
||||
alias gc="git commit"
|
||||
alias gcm="git commit -m"
|
||||
alias gca="git commit -am"
|
||||
alias gm="git merge"
|
||||
alias gr="git rebase"
|
||||
alias gps="git push"
|
||||
alias gpl="git pull"
|
||||
alias gd="git diff"
|
||||
alias gl="git log"
|
||||
alias gfi="git flow init"
|
||||
alias gff="git flow feature"
|
||||
alias gfr="git flow release"
|
||||
alias gfh="git flow hotfix"
|
||||
~~~~
|
18
source/_posts/2014-02-09-drupalcamp-london-2014.md
Normal file
18
source/_posts/2014-02-09-drupalcamp-london-2014.md
Normal file
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
title: DrupalCamp London 2014
|
||||
description: It's all booked, I'm going to be attending DrupalCamp London.
|
||||
tags:
|
||||
- Drupal
|
||||
- DrupalCamp London
|
||||
- Git
|
||||
- Git Flow
|
||||
---
|
||||
It's all booked, I'm going to be attending [DrupalCamp London](http://2014.drupalcamplondon.co.uk).
|
||||
|
||||
I'm going as a volunteer, so I'm going to be helping with the registrations on the Saturday morning and for another couple hours elsewhere over the weekend. I've also offered to help organise and oversee some code sprints, although I'm definitely wanting to do some sprinting of my own and attend a few sessions.
|
||||
|
||||
I'm looking forward to meeting some new people as well as catching up with some people that I met at [DrupalCon Prague](http://prague2013.drupal.org).
|
||||
|
||||
If you're also coming, see you there!
|
||||
|
||||
**Update:** I've just found out that my session, [What is Git Flow?](http://2014.drupalcamplondon.co.uk/drupalcamp-london-2014/session/what-git-flow "Information about the session on the DrupalCamp website"), has been accepted and will take place on the Sunday morning. It's going to be a busy weekend!
|
17
source/_posts/2014-05-03-drupal-association.md
Normal file
17
source/_posts/2014-05-03-drupal-association.md
Normal file
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
title: Drupal Association
|
||||
tags:
|
||||
- Drupal
|
||||
- Personal
|
||||
---
|
||||
Today was my last day working at [Precedent](http://www.precedent.com). Next week, I'll be starting my [new job](https://assoc.drupal.org/node/18923 "Drupal.org Developer") at the [Drupal Association](http://assoc.drupal.org) working on Drupal's home - [Drupal.org](http://www.drupal.org).
|
||||
|
||||
I was at Precedent for just over a year and had the opportunity to work on several Drupal projects from project leading to ad-hoc module and theme development, including my largest Drupal build to date.
|
||||
|
||||
I was also lucky enough to go to [DrupalCon Prague](http://prague2013.drupal.org) as well as [DrupalCamp London](http://2014.drupalcamplondon.co.uk).
|
||||
|
||||
I was able to [contribute some code](https://drupal.org/project/eventsforce) back into the community and encourage other team members to do the same.
|
||||
|
||||
It was good to be able to introduce some new tools like [Vagrant](http://www.vagrantup.com), [Puppet](http://www.puppetlabs.com), [SASS](http://www.sass-lang.com) and [Compass](http://www.compass-style.org) into the team. I was pleased to introduce and champion the [Git Flow](http://danielkummer.github.io/git-flow-cheatsheet "Git Flow Cheat Sheet") branching model, which them became the standard approach for all Drupal projects, and hopefully soon all development projects.
|
||||
|
||||
Working for the Drupal Association and on Drupal.org was an opportunity that I couldn't refuse, and is certainly going to be a fun and interesting challenge. I can't wait to get started!
|
8
source/_posts/2014-05-06-thanks.md
Normal file
8
source/_posts/2014-05-06-thanks.md
Normal file
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
title: Thanks
|
||||
tags:
|
||||
- Drupal
|
||||
- Drupal Association
|
||||
- Personal
|
||||
---
|
||||
This is just a quick post to thank everyone for their comments and congratulations after my previous post about [joining the Drupal Association](/blog/drupal-association). I’m looking forward to my first day in the job tomorrow.
|
12
source/_posts/2014-07-02-drush-make-drupalbristol.md
Normal file
12
source/_posts/2014-07-02-drush-make-drupalbristol.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
title: drush make drupalbristol
|
||||
tags:
|
||||
- Drupal
|
||||
- Drush
|
||||
- Drush Make
|
||||
- Drupal Bristol
|
||||
- Talks
|
||||
---
|
||||
Here are my slides from this month's talk night at the [Drupal Bristol user group](https://groups.drupal.org/bristol-and-west-uk).
|
||||
|
||||
<script async class="speakerdeck-embed" data-id="42605700f102013198de5a5f6f23ab67" data-ratio="1.29456384323641" src="//speakerdeck.com/assets/embed.js"></script>
|
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
title: How to fix Vagrant Loading the Wrong Virtual Machine
|
||||
slug: fix-vagrant-loading-wrong-virtual-machine
|
||||
tags:
|
||||
- Vagrant
|
||||
- VirtualBox
|
||||
---
|
||||
A few times recently, I've had instances where Vagrant seems to have forgotten which virtual machine it's supposed to load, probably due to renaming a project directory or the .vagrant directory being moved accidentally. Here are the steps that I took to fix this and point Vagrant back at the correct VM.
|
||||
|
||||
* Stop the machine from running using the `$ vagrant halt` command.
|
||||
* Use the `$ VBoxManage list vms` command to view a list of the virtual machines on your system. Note the ID of the correct VM that should be loading. For example, `"foo_default_1405481857614_74478" {e492bfc3-cac2-4cde-a396-e81e37e421e2}`. The number within the curly brackets is the ID of the virtual machine.
|
||||
* Within the .vagrant directory in your project (it is hidden by default), update the ID within the machines/default/virtualbox/id file.
|
||||
* Start the new VM with `$ vagrant up`.
|
|
@ -0,0 +1,48 @@
|
|||
---
|
||||
title: Updating Features and Adding Components Using Drush
|
||||
slug: updating-features-and-adding-components-using-drush
|
||||
tags:
|
||||
- Drupal
|
||||
- Drupal Planet
|
||||
- Drush
|
||||
- Features
|
||||
---
|
||||
If you use the [Features module](http://drupal.org/project/features) to manage your Drupal configuration, it can be time consuming to update features through the UI, especially if you are working on a remote server and need to keep downloading and uploading files.
|
||||
|
||||
If you re-create a feature through the UI, you'll be prompted to download a new archive of the feature in its entirety onto your local computer. You could either commit this into a local repository and then pull it remotely, or use a tool such as SCP to upload the archive onto the server and commit it from there. You can simplify this process by using [Drush](http://drush.org).
|
||||
|
||||
## Finding Components
|
||||
|
||||
To search for a component, use the `drush features-components` command. This will display a list of all components on the site. As we're only interested in components that haven't been exported yet, add the `--not-exported` option to filter the results.
|
||||
|
||||
To filter further, you can also use the `grep` command to filter the results. For example, `drush features-components --not-exported field_base | grep foo`, would only return non-exported field bases containing the word "foo".
|
||||
|
||||
The result is a source and a component, separated by a colon. For example, `field_base:field_foo`.
|
||||
|
||||
## Exporting the Feature
|
||||
|
||||
Once you have a list of the components that you need to add, you can export the feature. This is done using the `drush features-export` command, along with the feature name and the component names.
|
||||
|
||||
For example:
|
||||
|
||||
$ drush features-export -y myfeature field_base:field_foo field_instance:user-field_foo
|
||||
|
||||
In this example, the base for field_boo and it's instance on the user object is being added to the "myfeature" feature.
|
||||
|
||||
If you are updating an existing feature, you'll get a message informing you that the module already exists and asking if you want to continue. This is fine, and is automatically accepted by including `-y` within the command. If a feature with the specified name doesn't exist, it will be created.
|
||||
|
||||
If you're creating a new feature, you can define where the feature will be created using the `--destination` option.
|
||||
|
||||
Once complete, you will see a confirmation message.
|
||||
|
||||
> Created module: my feature in sites/default/modules/custom/features/myfeature
|
||||
|
||||
## The Result
|
||||
|
||||
Once finished, the feature is updated in it's original location, so there's no download of the feature and then needing to re-upload it. You can add and commit your changes into Git or continue with your standard workflow straight away.
|
||||
|
||||
## Useful Links
|
||||
|
||||
* [The Features project page on Drupal.org](http://www.drupal.org/project/features)
|
||||
* [The "drush features-components" command](http://www.drushcommands.com/drush-6x/features/features-components)
|
||||
* [The "drush features-export" command](http://www.drushcommands.com/drush-6x/features/features-export)
|
|
@ -4,7 +4,7 @@
|
|||
<meta charset="utf-8">
|
||||
<meta name="description" content="{{ page.description }}">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>{{ site.title }}</title>
|
||||
<title>{{ page.title }}</title>
|
||||
</head>
|
||||
<body>
|
||||
{% block content_wrapper %}
|
||||
|
|
Reference in a new issue