Apt can’t see sources? Try changing the User Agent

If you are trying to use apt behind a corporate firewall, try changing the user agent apt is using with wget to load the package lists. By default it uses:

User-Agent: Debian APT-HTTP/1.3

which isn’t recognised by the filter.

1. Create and edit /etc/apt/apt.conf

sudo vi /etc/apt/apt.conf

2. Paste the following into the file:

  http::User-Agent "Mozilla/5.0 (Windows NT 5.1; rv:25.0) Gecko/20100101 Firefox/25.0";

3. Update apt

sudo apt-get update


Drupal 8 – Create a block plugin

This continues on from the previous post where we created a simple module. In this post we add a basic block, which is pretty easy as it turns out.

Create a new file at lib/Drupal/thrones/Plugin/Block/ThronesExampleBlock.php and add the following:


 * @file
 * Contains \Drupal\thrones\Plugin\Block\ThronesExampleBlock.

namespace Drupal\thrones\Plugin\Block;

use Drupal\block\BlockBase;
use Drupal\Component\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;

 * Provides a simple block.
 * @Plugin(
 *   id = "thrones_example_block",
 *   admin_label = @Translation("Thrones Example Block"),
 *   module = "thrones"
 * )
class ThronesExampleBlock extends BlockBase {

   * Implements \Drupal\block\BlockBase::blockBuild().
  protected function blockBuild() {
    return array(
      '#children' => 'This is a block!',


Clear the cache and you should be able to add the block.

Creating a custom module with routing and menu items in Drupal 8

Drupal 8 changes quite a bit when you go to create a custom module. This post will take us through setting up a module and adding a route and menu item. We are going to create a module that lets us track whether Game of Thrones characters are alive or dead, because it’s damn hard to keep track of them all!

1. Create a new directory for the module under the ‘modules’ directory. This is now in docroot, previously it was under sites/all. From docroot:

mkdir -p modules/custom/thrones

2. Inside the module directory, create a file called thrones.info.yml. This is a YAML file, which is a data markup language that has been selected for use throughout Drupal 8. You can read more about it at http://en.wikipedia.org/wiki/YAML.

cd modules/custom/thrones
vi thrones.info.yml

The yaml file should contain something like:

name: Thrones
type: module
description: 'Track the mortality of Game of Thrones characters.'
package: Custom
version: 1.0 
core: 8.x 
- node
configure: admin/structure/thrones/settings

Now create thrones.module and add the following:


* @file
* Allow users to manage the manage the mortality of Game of Thrones characters.

Great! A fully functional Drupal 8 module! Head to the Extend page and enable it. It will be under the Other category, or use the new search box to quickly locate it.

Head back to thrones.module and lets add the menu item. To do this we will need several things: a YAML file containing the routes (linking a URL to a controller), a hook_menu() to add the menu item and a controller class (very scary!).

Add the following to thrones.module:

 * Implements hook_menu().
function thrones_menu() {

  $items['admin/config/thrones'] = array(
    'title' => 'Settings',
    'access arguments' => array('administer thrones'),

 * Implements hook_permission().
function thrones_permission() {
  $permissions = array(
    'administer thrones' => array(
      'title' => t('Administer Thrones module'),
      'description' => t('Change the settings for thrones module.'),
 return $permissions;

Now create ‘thrones.routing.yml’ and add the following:

  pattern: '/admin/config/thrones'
    _content: '\Drupal\thrones\Controller\ThronesController::settings'
    _permission: 'administer thrones module'

Lastly, you need to create the controller. From the module’s root directory create the controller’s directory:

mkdir -p lib/Drupal/thrones/Controller

Inside the controller directory create the file ‘ThronesController.php’. This will contain your controller class, which should look like this:

 * @file
 * Contains \Drupal\thrones\ThronesController.

namespace Drupal\thrones\Controller;

use Symfony\Component\DependencyInjection\ContainerAware;

class ThronesController extends ContainerAware {

   * Administration page for thrones module.
  public function settings() {
    return 'Game of thrones is soo awesome!';

Now, head to admin/config/development/performance and clear the cache. Now navigate to admin/config/thrones and bask in the glory!

The Change record for the New Symfony Based Routing System has heaps more information on routes and what-not.

I’ll take this module further in future posts.