• What's new in Drupal World? Week #25 DrupalDevDays special

    The big event of last week is of course the Drupal Dev days in Barcelona: not so many tweets about it though, but don't worry I've managed to find some interesting links!

    New version for Commerce Kickstart

    The CommerceGuys rolled out a version 2 of the Drupal Commerce installation profile, the new UI will surely amaze during client demos http://commerceguys.com/blog/sneak-preview-commerce-kickstart-v2

    Barcelona DrupalDev days sessions

    Here are the slides of the different sessions:

    WSCCI and Web Services

    A sprint in Paris took place last week on Web Services in Drupal 8, here's the summary by @Crell. This sums up how you are going to code with the future entities in D8 and what protocol is discussed for providing Web Services in Drupal http://groups.drupal.org/node/237443

    Twig in D8 core

    Twig just got committed to Drupal 8 core http://drupalcode.org/project/drupal.git/commit/07e217036136e0bc3369c276...

    New UI for string translation committed

    The issue is finally pushed to 8.x, congratz! http://drupal.org/node/1452188

    Drupal 8 Plugin architecture

    A draft of D8 plugin architecture is on the way by EclipseGc http://drupal.org/node/1637614

    A Drupal energy drink spotted

    drupal energy drink
    So that you can code harder, better, faster, stronger...

  • What's new in Drupal World? Week #24

    This is a followup to my last week's blog post, where I bring to you the latest news in Drupal world:

    New 404 and 403 handling

    In one of the latest drupal core patches drupal_not_found() and drupal_access_denied() were replaced with symfony exceptions http://drupal.org/node/1616360
    Follow @Drupal8changes for this kind of updates.

    Install Apache Solr on Mac OS X

    A short blog post on how to install Solr on Mac, very useful! http://ramlev.dk/blog/2012/06/02/install-apache-solr-on-your-mac/

    Yet another drupal showcase

    Well, it's always good to advertise http://www.withdrupal.com/

    Drupal 8 at Symphony Live

    This is the big news of this week, @Crell went giving a presentation at Symphony Live on the state of Drupal 8 core and Symphony. As a reminder, D8 will use (for now) 6 components of Symphony:

    • HttpFoundation
    • HttpKernel
    • EventDispatcher
    • ClassLoader
    • DependencyInjection
    • Yaml

    http://garfieldtech.com/presentations/sfl2012-drupal8/index.html http://lockerz.com/s/215044232

    The Drupal Association Store

    The Drupal Association opened a section on their site to sell some T-Shirt, more is expected though. It is currently built with Ubercart, and will likely be rewritten with Commerce in the D7 version of drupal.org https://association.drupal.org/store

    Views in Drupal Core, the tour

    If you missed it, two weeks ago, Earl Miles announced that D8 will ship with Views in core in his blog post, now that he raised some money to work on it with few others, it is time to plan trips to multiple drupal event and code sprints! http://www.angrydonuts.com/chaos-world-tour-12

    For more info, Earl gave 2 interviews as podcasts: http://www.lullabot.com/podcasts/podcast-103-views-core and http://modulesunraveled.com/podcast/023-earl-miles-and-getting-views-in-...

    D7 has now has full Entity language support

    Another change in Drupal core, but this one has been backported to Drupal 7, read more at http://groups.drupal.org/node/236548

  • What's new in Drupal World? Week #23

    I'm trying to make another kind of blog post, very short and simply stating what happened in the last week in the Drupal world. Those news come mainly from Twitter, and are the links that are highly mentioned or retweeted by the community:

    Initial prototype of in-place editing features in Spark

    @Dries made a blog post about the Spark distribution and its expected feature, in-line editing. Check out the video by @webchick http://youtu.be/a53Wcq31LmY

    Dries et la baguette

    Dries went in Paris at the end of last week, seeing Radio France people and venue, and giving some interviews to several tech magazines, including Le Journal du Net, here's the article (in French) http://www.journaldunet.com/developpeur/php/drupal-8-0512.shtml

    Olivier Friesse, technical executive at Radio France, talked about their media management module: ScalD, that just hit a Drupal 7 version.

    The state of Drupal 8 by @webchick: hook_future_alter()

    Angie made a great slide deck for people who want to know/talk about D8: http://webchick.net/drupal-8-slides

    The Drupal Code of Conduct

    During the last DrupalCon booth babes were spotted, this started a debate on twitter, and resulted in the creation of a DrupalCon Code of Conduct: http://groups.drupal.org/node/232633

    A new face for DrupalCommerce site

    The Drupal Commerce project homepage is back with a sweet new theme and user support channel http://www.drupalcommerce.org/

    The kernel has landed

    @Crell (Larry Garfield) announced that the HttpKernel from Symphony got into Drupal http://www.garfieldtech.com/blog/wscci-kernel-merge

    Entities are now classed objects using a defined interface

    OOP is getting to Drupal 8 and fast! http://groups.drupal.org/node/235193

    That's it, see you next week for other news!

  • What's new in Drush 5?

    During the DrupalCon Denver this week, there was a presentation by Moshe Weitzman, Jonathan Hedstrom, Owen Barton and Mark Sonnabaum. With it the stable version 5 of Drush should have been released (I might be a little early for that).

    Drush is your friend, if you are a developer, you have to have it installed, so I will assume that you have used Drush 4 before and I will present you the new features of version 5 in this article.

    Configuration location

    Configurations, through drushrc.php files, can now be placed at several locations:

    • Relative to the unix user: ~/.drush/drushrc.php
    • Relative to the Drupal site: sites/{default|example.com}/drushrc.php
    • Relative to the server: /etc/drush/drushrc.php

    Shell aliases

    You can now provide your own drush aliases in the configuration, for example:

    1
    2
    3
    4
    
    $options['shell-aliases'] => array(
      'pull' => '!git pull',
      'pulldb' => '!git pull && drush updatedb',
    );

    So you can set drush commands along with system commands like git or rm.

    Options handling

    Unrecognized options now output an error, no more "Why this didn't work?", syntax errors can be avoided easily.

    Drush help adopted a standard for option parameters:

    • --option=<value> for mandatory parameters
    • --option=[value] for optional parameters

    Windows compatibility

    Finally! Yes, they did a good work... Sponsored by Microsoft itself, an installer is now available, and (almost) no need of cygwin anymore.

    Usage tracking

    It is now possible to log used commands, they can be anonymized and sent to MongoLab (sponsor of Drush developers) to make Drush better.
    This can also be used by sysadmins to keep track of what developers do.
    This option is disabled by default.

    Drush make

    The famous packet manager integrates Drush core, is it now possible to create .make files out-of-the-box to install modules and themes faster and faster.
    That's not all of it, multiple downloads are now handled with concurrency (4 processes by default), more speed!
    Moreover, if you didn't know it, there is a Drush cache that prevents downloading tarballs if they have already been downloaded earlier.

    Autocompletion

    Yes, ladies and gentlemen! Site aliases, commands, shell aliases, options and modules autocompletion is now available. A context handling prevent the overflow of possibilities. For more information, the better is to test it or to watch the video.
    To enable it you just have to copy-paste drush.complete.sh into /etc/bash_completion.d, or, if you don't have the permissions, you can include a little snippet in your ~/.bashrc

    Some options are there so you can even do without the drush keyword at the beginning of the command, for example:
    @mysite dl views

    Built-in WebServer

    Drush 5 comes with a light HTTP server to execute Drupal sites. You may "what is this for", well, if you want to test a Drupal site without wondering about Apache VHosts, this command is very useful. In addition to seeing access log, it also shows watchdog messages.
    Thus, the command drush run-server :8889/ will open a page in your browser with the current Drupal site. This requires php-cgi and PHP 5.3.

    There is more, you can now do a disposable Drupal with the command quick-drupal. It's perfect if you want to impress this Joomla "friend" you have in few seconds :
    cd /tmp
    drush quick-drupal

    It will download Drupal 7, create a SQLite database (in a single file), and run standard install profile. You can then play with the multiple options:
    drush qd "My store" --core=commerce_kickstart --profile=commerce_kickstart --yes --watchdog (enjoy watching your friend having a heart attack)

    When you don't need it anymore, rm -r the directory, au revoir.

    At this point, I must confess I clapped alone at home...

    Queue API

    It seems that the new Queue API handling in Drupal 7 is a bit too hidden and only runnable within the cron, Drush solves this problem with two commands:

    • drush queue-list lists all queues registered by modules
    • drush queue-run runs these queues

    Multisites

    For people working with multisites, it can be frustrating to execute a command in the wrong site (say sites/default), Drush 5 provides the commands drush site-set and drush site-reset to make this environment persistent.

    So lots of new features, and what features! A little tip: to enjoy fresh features from Drush, clone the repository directly. These new features come along with some bugs and that would the reason why the stable version is still not here, but anyway: Kudos to them all!

    "We'll see you on the command line" — Moshe Weitzman

    The presentation video is available here.

  • Mac OSX Tip: Open current Finder folder in iTerm

    Open in iTerm toolbar icon
    Quick post for a quick tip, I use iTerm2 which is basically a Terminal on steroids offering features like search, autocomplete, growl support and many more but it's painful to navigate in Finder and willing to open the same directory in iTerm2.

    So here it is: a nice toolbar button to automatically open the selected folder inFinder (or the current one if none is selected), made from an AppleScript.

    Installation

    • Open this script into AppleScript Editor and save it as an application in ~/Library/Scripts/Applications/Finder/cd
    • Run rm \ ~/Library/Scripts/Applications/Finder/cd.app/Contents/Resources/droplet.icns
    • Run cp /Applications/iTerm.app/Contents/Resources/iTerm.icns \ ~/Library/Scripts/Applications/Finder/cd.app/Contents/Resources/droplet.icns
    • Run touch ~/Library/Scripts/Applications/Finder/cd.app, this refreshes the icon
    • Drag and drop your app into your Finder toolbar

    Now you can click on this icon and iTerm will automatically cd to the folder selected!

    Source

  • Proof of Concept: Twitter aggregator for Drupal with Drupal

    Happy new year! Oops, already Fabruary...

    As I have some time for my last semester in Dublin, I can test some little things I wanted to do.

    Concept

    I have built a little Drupal tweets aggregator, fetching only those that have links embedded (this Twitter search). It stores all these tweets, but as the nodes are not very easy to manipulate for statistics, I decided to make my own module et not use the Aggregator module from Drupal core. Four SQL tables and let's go: storing tweets, links et their authors in a hook_cron() :

    • aggreg_tweets(id, author, text, date)
    • aggreg_authors(id, name)
    • aggreg_links(id, link)
    • aggreg_links_tweets(link, tweet)

    Statistics

    Ok, that's good for now, but we have to do something with these tweets... So let's make some hook_menu entries for statistics pages:

    • One for time-related to see when drupalers are tweeting more, so when to watch
    • One for trendings tweets to see what is happening and what is relevant right now

    For that I would have been bothered by the nodes: doing some GROUP BY and ROLLUP queries on so many JOIN , no thanks!
    Some highcharts.js library to render nice charts, little tables and an ajax query to fetch which tweets are related to a link (to add some context) later and here it is: a nice Twitter aggregator

    Twitter bootstrap

    This fresh new theme (therefore in dev version) have some bugs due to Drupal integration and licensing issues but there are solved in few changes. It provides some CSS classes to render nice tables and some JS plugins to create modals (I also added bootbox.js for easier handling, thanks to @FGRibreau). It results in a simple & nice interface perfect for proofs of concept or small projects like this one.

    Drupal, a real framework

    This recipe is prepared in about 350 lines of code thanks to Drupal hooks and methods. Among them I used:

    • hook_menu() & hook_cron()
    • db_merge()
    • variable_get() and variable_set(), just essential
    • l(), truncate_utf8(), theme_table() for rendering
    • curl for HTTP requests

    Now I will be able to tweet relevant links about Drupal, so don't hesitate to follow me on Twitter !

  • Drupal Live templates for PHPStorm

    Djebbz recently draw my attention on IRC. He has put up a GitHub repository with a way to bulk export Live templates from the Drupal code.

    Explanation

    It's a perl script that parses the Hooks API files (mainly contained within the Examples module and in *.api.php files in contrib modules).

    Usage

    First, close PHPStorm as it overrides files while closing.
    Basic hooks are already available in the user.xml file in the repository, on Mac OSX all you have to do is:
    cd ~/Library/Preferences/WebIDE10/templates
    curl -O -# https://raw.github.com/DjebbZ/Drupal-PHPStorm-Live-Templates/master/user.xml

    Then start PHPStorm and in your code type h_menu<TAB> to insert a hook_menu.
    Note that typing hook_menu<TAB> will insert the full hook documentation.

    PHPStorm Live template example

    More

    The script is available in the repository if you wish to add more hooks from other contrib modules. To execute it:
    cd /path/to/drupal
    find . -name \*.php | xargs grep -l '^function hook_' | xargs /path/to/parse_drupal_api.pl > ~/Library/Preferences/config/templates/user.xml

    Enjoy!

  • Order view on string length

    Let's keep on with useful snippets. Here is, in 4 lines of code, how to order view results on title string length.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    
    <?php
     
    /**
     * Implements hook_query_TAG_alter().
     *
     * @param SelectQuery $query
     */
    function glossaire_query_views_export_alter(SelectQuery $query) {
      $query->addExpression('LENGTH(node.title)', 'title_length');
      $query->orderBy('title_length', 'DESC');
    }

    This is used in the custom module of the french glossary. The code was built from the documentation available on drupal.org.

  • How to force downloading a file with Drupal 7

    New quick post to share a feature.

    To force to download a file, as usual with Drupal, there's a module for that. In this case there are even two: Download file and File force. But you may be reticent to install a module for such a basic feature! So here is the solution in a few lines of code:

    Here is a snippet based on File API. It is more secure than the second one but it will not work on files not handled by Drupal (whatever file download method you're using) : thus I recommend it.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    
    <?php
    /**
     * Implementation of hook_menu()
     */
    function mymodule_menu() {
      $items['download/%file'] = array(
        'page callback' => 'mymodule_download_file',
        'access arguments' => array('administer site configuration'),
        'type' => MENU_CALLBACK,
      );
      return $items;
    }
     
    /**
     * Page callback for forcing a file to download
     */
    function mymodule_download_file($file) {
      if($file) {
        file_transfer($file->uri, array('Content-disposition', 'attachment; filename='.$file->filename));
      }
      else {
        return drupal_access_denied();
      }
    }

    You can download the file with a link like http://mysite.com/download/123 where 123 is the file id (fid) of the file being downloaded.

    This second snippet may present a security issue! It is recommended to use it as a last resort when files are not handled by Drupal. To increase security, this feature will be restricted to administrators, and filtered on file extensions.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    
    <?php
    /**
     * Implementation of hook_menu()
     */
    function mymodule_menu() {
      $items['download'] = array(
        'page callback' => 'mymodule_download_file',
        'access arguments' => array('administer site configuration'),
        'type' => MENU_CALLBACK,
      );
      return $items;
    }
     
    /**
     * Page callback for forcing a file to download
     */
    function mymodule_download_file() {
      if (!isset($_GET['file']) || !file_exists($_GET['file'])) {
        return drupal_not_found();
      }
      $filepath = $_GET['file'];
      $realpath = realpath($path);
      $filename = basename($filepath);
      $extension = pathinfo($filepath, PATHINFO_EXTENSION);
      // Check extension and restrict to files in DRUPAL_ROOT
      if(in_array($extension, array('jpg', 'png', 'gif', 'mp4')) && substr($path, 0, strlen(DRUPAL_ROOT)) === DRUPAL_ROOT) {
        drupal_add_http_header('Content-disposition', 'attachment; filename=' . $filename);
        readfile($filepath);
      }
      else {
        return drupal_access_denied();
      }
    }

    Then you can create your file link as in http://mysite.com/download?file=sites/default/files/myimage.png

    It's only working for the public file system handling but it is the most famous one.

Pages

Subscribe to Le blog de SebCorbin RSS