Subscribe: Group 42
Added By: Feedage Forager Feedage Grade B rated
Language: English
content  directory  drupal  drush  echo echo  echo  files  module  redirect  script  settings  site  source        
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: Group 42

Group 42


Drupal Site Reset BASH Script

Fri, 23 Jun 2017 20:57:45 +0000

I'm experimenting with Drupal 8 and some its new features like migration and configuration management. A reset script is a convenient timesaver and many people have shared their techniques for doing so. Having benefited from other's generosity I wanted to return the favour by sharing my current work-in-progress. This script: Leaves the codebase as-is Deletes and reinstalls the database Deletes the 'files' directory Deletes the specified configuration management directory Enables additional modules, as required Deletes settings.php and allows Drupal install to recreate Updates the new settings.php $config_directories['sync'] entry Adds a settings-migrate.php include to settings.php I call the script via Drush with an entry in drushrc.php: $options['shell-aliases']['428-reset'] = '!sh /Users/dale/.drush/sha-scripts/'; The script is evolving as I learn more about Drupal 8 and refine my workflow. Comments and suggestions are welcome. #!/bin/bash# Reinstall a Drupal instance to reset it back to a know state.# A file base and Drush alias must already be configured.DRUSH8='/Users/dale/bin/drush8/vendor/bin/drush'DRUPALDIR='/Users/dale/Sites/group428'CONFIGDIR='sites/default/group42config/sync'DRUSHID='@g428'SITE_NAME='Group 428'ACCOUNT='admin'PASS='staring-password'EMAIL=''DB_URL='mysql://group428:group428@localhost/group428'# Nuke the database$DRUSH8 $DRUSHID sql-drop --yes# Nuke the filebaseecho "Resetting files"chmod -R u+w $DRUPALDIR/*rm $DRUPALDIR/sites/default/settings.phprm -r $DRUPALDIR/sites/default/filesrm -r $DRUPALDIR/$CONFIGDIR# Fresh Drupal installcd $DRUPALDIR$DRUSH8 site-install standard --db-url=$DB_URL --site-name=$SITE_NAME --account-name=$ACCOUNT --account-pass=$PASS --account-mail=$EMAIL --yes# Base configuration$DRUSH8 $DRUSHID en admin_toolbar,admin_toolbar_tools --yes# Allow upcoming changes to settings.phpchmod u+w $DRUPALDIR/sites/defaultchmod u+w $DRUPALDIR/sites/default/settings.php# Configuration Managementsed -i '' "/config\_directories\['sync'\]/d" $DRUPALDIR/sites/default/settings.phpecho "\$config_directories['sync'] = '$CONFIGDIR';" >> $DRUPALDIR/sites/default/settings.php# Migrateecho "\ninclude 'settings-migrate.php';" >> $DRUPALDIR/sites/default/settings.php$DRUSH8 $DRUSHID en migrate,migrate_drupal,migrate_plus,migrate_tools,migrate_upgrade --yes# Login$DRUSH8 $DRUSHID uli Tagged: DrupalDrupal 8bash scriptdrushPlanet Drupal AttachmentSize Drupal Reset BASH Script1.43 KB [...]

H5P - Portable Interactive Content in Drupal

Mon, 08 May 2017 16:24:24 +0000

H5P is an open source platform-independent authoring and display system for interactive content. Presentations, quizzes, and other interactive content can be created and displayed using building blocks known as H5P content types (different from Drupal content types). Once a piece of content is created it's easily exported to another H5P system. The development environment is open and well documented, allowing the creation of custom H5P content types. H5P attributes include: Available in Drupal 7, WordPress, and Moodle Open Source Content is exportable to any other H5P system Uses JavaScript and HTML 5 Results tracking for content types such as quizzes xAPI (Tin Can) integration Drupal 7 hook system integration Drupal development environment Unfortunately there is no Drupal 8 version yet. There are a variety of H5P content types, including containers such as accordions and sliders which can nest other content types. Some examples are: Arithmetic Quiz Course Presentation Dialog Cards Drag the Words Fill in the Blanks Timeline Interactive Video The complete list is at H5P defines a file packaging format named the ".h5p specification", or simply, H5P file. An H5P file is a zip archive bundling HTML, JSON, JavaScript, and media files. It can contain one or more of a content type, content export, API implementation, application, or JavaScript library. Drupal Integration H5P is installed in Drupal in two steps. Drupal H5P module The H5P module is installed using the standard module installation process. It handles the Drupal integration. H5P Content Types and support files H5P content types and the files to support them are installed into a H5P Library manager provided by the H5P module. An H5P archive file of the content types and other support libraries is downloaded from the H5P site and uploaded into the Drupal H5P library. Screenshot of H5P Content Library in Drupal Content Creation The Drupal integration contains a H5P node type named, “Interactive content”. When a H5P node is created there is a selector for the H5P content type. For example, quiz, presentation, or dialog card. When a H5P content type is selected the editor for the content type is loaded interactively. The author then creates the desired content. Screenshot of H5P content type selector   Screenshot of editor for H5P Flashcards content type Once saved the content is presented when the node is viewed. H5P Development The H5P project provides a Drupal development environment (including a developer mode), online documentation, and a forum. The various specifications and basics for getting started are well documented, and include a “hello world” example. H5P at its heart is JavaScript with a PHP wrapper for integrating with a website. Someone's ability to learn the framework will depend on their comfort with JavaScript. Coding the editor component that creates and edits the content type typically requires as much work as coding the display for the content type. Custom editor widgets can be written. Existing H5P editor widgets can also be used though they are not documented. The H5P Drupal hooks provide a clean method of adding CSS stylesheets and modifying H5P behaviour without modifying the base H5P code. Some tasks are complicated by the asynchronous nature of JavaScript loading and the use of iFrames. Pros and Cons H5P is continuously changing and improving. These pros and cons are a snapshot of my experience as of May 2017. Pros: Plug and play interactive content Easy to share content Option for turning off content sharing feature Large variety of content types Open source The H5P team is approachable There is a good content development environment for Drupal The content creators I worked with were able to quickly and easily generate content using H5P Drupal hooks available Cons: Documentation on some content types is lacking Trial and error is often required to figure out options for some of the sophisticated content types Though some of the c[...]

VanDUG April 2017 Meeting

Tue, 02 May 2017 06:10:09 +0000

At our April 2017 meeting Renée Stephen gave the Vancouver Drupal User Group (VanDUG) an encore of her Pacific Northwest Drupal Summit (PNWDS) presentation: No more performance anxiety! The presentation walked us through the formal process of server load testing. Renée's current gig as Technical Consultant at Acquia gives has given her lots of experience on the subject and she knows how to present. It's always a pleasure when someone deeply steeped in domain knowledge gives a great presentation. I can't begin to summarize the entire presentation. Renée's slide-deck is available for download at the presentation description on the PNWDS website: No more performance anxiety: get your Drupal site tuned and ready to take the stage! Direct PDF link: PNWDS 2017 - No more performance anxiety.pdf Here are the take-aways that surprised me: The standard definition of load testing is backend server oriented and does not include front-end performance issues. For example, large hero images or JavaScript widget rendering. While these are important they are not part of this discipline and usually require different tool sets. You'll want at least 2 days, possibly more, to familiarize yourself with jMeter. I was also reminded of how much server and tool knowledge is required if you're the one doing the remediation. No single detail is exceedingly complicated but each technology in the stack has its particulars, tools, and metics. Here are the tools Renée mentioned in her presentation: Profiling Toolkit Blazemeter Recorder Postman HAR jMeter Dynamic & Static Analysis Blazemeter / jMeter Apachebench (ab) New Relic / TraceView / XHProf WebPage Test Chrome Inspector Server logs and stats varnishstat / varnishlog Redis monitor / memcached-tool Drupal Devel module WebProfiler She also made a repo of her jMeter example files available at A big thank you to Renée for presenting. I missed the presentation at PNWDS and was happy for the second change to see it. Tagged: VanDUGDrupalPNWDSRenee StephenPerformancePlanet Drupal[...]

Adding and Controlling TinyMCE Fonts in Drupal

Sun, 17 Nov 2013 22:26:03 +0000

Customizing the TinyMCE editor's font selection is straight forward thanks to a hook provided by the Drupal Wysiwyg module. The hook_wysiwyg_editor_settings_alter() function allows a module to update the settings passed to the editor. The programming is simple. Discovering and understanding the values of the settings can be a challenge. Font selection is enabled in the Wysiwyg profile. Edit the profile (Administration > Content authoring > Wysiwyg profiles > Edit) and enable the Font Family dropdown selector by checking the Fonts checkbox in the Button and plugins section. This is as far as the user interface takes us. In the TinyMCE initialization code the font selector drop down is configured by a JavaScript string variable named theme_advanced_fonts. The string is a list of font selections with fall backs, separated by semi-collons: Display name 1=font1,font_fallback1,font_fallback2;Display name 2=font2,fallback_font3, fallback_font4 A real example: Andale Mono=andale mono,times;Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde If the specified fonts are natively available in the web browser no further work is required. If the font is defined using @font-face the definition needs to be in a style sheet loaded by TinyMCE or it will not be displayed during the editing session. The list of stylesheets loaded by the editor is defined in the JavaScript variable named content_css. Both the theme_advanced_fonts and content_css variables are available in hook_wysiwyg_editor_settings_alter() in a PHP array. In my testing I found the theme_advanced_fonts variable was not pre-populated with the TinyMCE default fonts, even though content_css and other values were. To work around this I pulled the values for theme_advanced_fonts out of the JavaScript configuration file and redefined them in my code. For the following example the client has declared, "Friends don't let friend's use comic sans, remove it from the list! And please add this font I found on Font Squirrel named Architects Daughter". In a module for site customizations the hook_wysiwyg_editor_settings_alter() function is defined. This hook fires for all editors so logic is added to specify TinyMCE. The editor fonts are defined in an array to make the list easy to update. In the sample code a line for the Architects Daughter font is added and the line for Comic Sans is commented out. The font list is then assigned to the theme_advanced_fonts variable in the $settings array. The CSS file containing the @font-face definition for Architects Daughter is appended to the content_css variable. This only defineds the font in the editor. The font will also need to be defined for the entire site in the theme CSS. editor == 'tinymce') {    $font_styles = array(      "Andale Mono=andale mono,times",      "Architects Daughter=architects_daughterregular",      "Arial=arial,helvetica,sans-serif",      "Arial Black=arial black,avant garde",      "Book Antiqua=book antiqua,palatino",      /* "Comic Sans MS=comic sans ms,sans-serif", */      "Courier New=courier new,courier",      "Georgia=georgia,palatino",      "Helvetica=helvetica",      "Impact=impact,chicago",      "Symbol=symbol",      "Tahoma=tahoma,arial,helvetica,sans-serif",      "Terminal=terminal,monaco",      "Times New Roman=times new roman,times",      "Trebuchet MS=trebuchet ms,geneva",      "Verdana=verdana,geneva",      "Webdings=webdings",      "Wingdings=wingdings,zapf dingbats",    );    $settings['theme_advanced_fonts'] = implode(';', $font_styles);    $settings['content_css'] .= ',' . drupal_get_path('module', 'site_customizations') . '/additional_fonts.css';  }}?> And the result: The Wysiwyg profile has a num[...]

Creating A Personal E-Book

Sun, 03 Nov 2013 05:15:16 +0000

Ever since I bought my first electronic book reader I've wanted to create my own e-book1. Not because I want to self-publish a book, because I want move the notes and cheat-sheets I have on paper to something I can reference on my e-book reader. My first experiment was with PDFs. They're easy to create but the results are underwhelming. While there are exceptions, PDFs generally don't display well on e-book readers, especially technical documents. It was clear that I needed to produce an ePub document. I've noodled around with different options. Last week I decided to give it a concerted effort. My criteria was: Ability to have source chapters or sections in individual files Ability to have the files readable on a website as well in ePub format Easy to update the ePub document (i.e., as simple a workflow as possible) Have the source formatting as straight forward as possible The formatting issue meant that working in a word processor such as Open Office or MS Word was not an option. EPub is very structured document. Word processors are excellent at achieving a good visual look but create the crappiest structured document I have ever seen. If you don't believe me, see how much space the Smash Words Style Guide devotes to telling authors how to make MS Word behave. I didn't want to deal with cleaning up the output. Knowing that many people had written books using text files and Github, I started researching options in that direction. There are a lot of examples out there! My research wasn't exhaustive or systematic. I basically stopped at the first option that appeared to meet my criteria: the technique used by Addy Osmani for his book Developing Backbone Applications. It's a very software developer approach involving command line tools. The build process: The Make utility is used build the different documents from source files written in markdown2 Make uses the awk command to concatenates individual text files into a master document A utility named pandoc3 converts the master document into a number of different formats, including ePub and HTML. This technique meets all of the criteria. Having seen the technical layouts in Osmani's book I have some assurance this technique can handle technical formatting requirements. It has the added advantage of being hostable on Github, which displays the markdown files visually formatted, not as plain text. And although I hadn't considered writing in the open and allowing collaboration, I have a some technical writing project ideas that might be fun to do this way. I've only just started converting my notes, so no experiences to talk about so far. In the spirit of open source I've uploaded the template to Github as ss-edoc-template: Single Source Document Publishing Example Template.  It is entirely derived from Osmani's example and I encourage you to take a look at Developing Backbone Applications to see the breadth of formatting options. If you have any experiences or comments you'd like to share, please leave a comment! [1] The shortened form of electronic book is variously e-book, ebook, or eBook. E-book seems to be the preferred spelling from the official usage bodies. Given the evolution of e-mail to email, I expect the same trajectory with e-book. For now, though, I'll go with the official usage. [2] Markdown is a plain-text formatting convention designed to both human readable and easy to convert to a formatted document, usually HTML. There are a number of different standards. For more information: [3] Pandoc is a utility program the converts between different document formats. For more information: Tagged: ePubbook publishingebooksmarkdownpandoc[...]

Creating URL Redirects with Migrate Module

Tue, 08 Jan 2013 20:25:04 +0000

New versions of websites often have new content organizations with new URL patterns. When old content is assigned a new URL it's almost always desirable to redirect traffic from the content's old URL to its new URL. The redirect preserves external links to the site content (i.e., prevents "link rot") and helps maintain search engine page ranking. If the Drupal Migrate module is used to create the content for the new site there's an easy code addition for creating the redirect at the same time as the content is created. This method uses the code described in the post: Programatically Create 301 Redirects. The Migrate framework calls the complete method when an entity, for example a node, is successfully created. Information on the complete method can be found in this documentation: Commonly implemented Migration methods. The complete method is passed the entity created and the row data used to create it. This provides a place to create a redirect using the Redirect module. In the following example, the old path is part of the row data. Depending on your situation this information could alternatively come from a pre-generated lookup or separate function call. old_path)) {      // Create an object with our redirect parameters      $redirect = new stdClass();      $redirect->source = $row->old_path;           // From URL      $redirect->source_options = array();      $redirect->redirect = 'node/'. $entity->nid;  // To URL      $redirect->redirect_options = array();      $redirect->status_code = 0;                   // Redirect Status      $redirect->type = 'redirect';      $redirect->language = LANGUAGE_NONE;          // Create the redirect      redirect_save($redirect);    }  }  }?>Tagged: DrupalDrupal 7Migrate Modulecode exampleRedirect moduleURL RedirectPlanet Drupal[...]

Programatically Create 301 Redirects

Sat, 29 Dec 2012 07:10:15 +0000

The Drupal 7 Redirect module gives a site the ability to redirect from one URL to another using a proper HTTP redirect status (e.g., 301 - Permanently moved). In addition to the user interface there is a programmatic method for entering redirects. The aptly named redirect_save function takes an object containing the details of the redirect and creates a redirect for the URL. Here is an example of creating a redirect. A status code of 0 uses the default redirect setting which is 301, unless changed in settings. source = 'the-old-url';     // From URL  $redirect->source_options = array();  $redirect->redirect = 'node/1';        // To URL  $redirect->redirect_options = array();  $redirect->status_code = 0;            // Redirect Status, 0 is default  $redirect->type = 'redirect';  $redirect->language = LANGUAGE_NONE;  // Create the redirect  redirect_save($redirect);?>Tagged: Drupal 7DrupalURL RedirectRedirect modulecode examplePlanet Drupal[...]

Simple Drupal Remote Backup

Sun, 18 Mar 2012 03:47:09 +0000

Like many web types I have a number of small websites I look after, and I've never been happy with my backup solution. Until today.

My requirements are simple, create a backup of the database and files and save it on a local backup drive. The sites don't warrant anything fancy (like a cloud based solution that costs money). The procedure until now involved multiple, fussy steps. It turned out a single script solution is simple once a few key technologies are in place.


  • SSH no-password/public-key access
    Use your favourite search engine to search on the words: ssh public key authentication for a list of articles on setting up no-password, public-key ssh access. If you don't have public key ability, I suspect the script could be modified to use a password.
  • Drush 4.5 on the host
    If you have root access just follow the drush installation instructions. This article by Robin Monks provided the missing step for my shared-host sites: Installing Drush on a Shared DreamHost Account. The information in this article on setting up an alias, i.e. @site-name, is still valid in drush 4.5: New features in Drush 3

The Backup Script

The backup script uses the drush archive-dump command, available as of drush 4.5, to create a backup tarball that includes the database and files. The backup tarball is scp'ed to the backup drive and deleted from the host.

# Backup the Group 42 live site
FILENAME=`date "+group42-%Y-%m-%d.tar"`
drush @g42live archive-dump --destination=/home/site/backuptemp/$FILENAME
scp$FILENAME /Volumes/Memory-Alpha/Backups/Group42/.
ssh rm /home/site/backuptemp/$FILENAME

Four lines of script (plus comments) and whenever I need a site backup it's one done in one command!

Drupal 7 Upgrades with Scripts and Drush

Tue, 12 Jul 2011 04:56:48 +0000

A Drupal upgrade between major versions rarely means doing the upgrade procedure once. A new configuration, changing content, or needing to test different module versions typically means redoing the upgrade from scratch a number of times, a tedious, error-prone and time consuming process. Fortunately there's a solution: automation! Scripting was always possible, but Drush has made it so much simpler. What follows is a review of the Drush commands I used via script to upgrade my Group 42 website to Drupal 7. The hand full of shell commands are basic and covered many other places on the net. The full upgrade scripts are at the end of the post. If you're familiar with Drush I recommend jumping directly to the scripts. Starting Notes -y / --yes option: This option skips the yes/no confirmation question required by some Drush commands. Since the examples in this post come from scripts this option is shown in the examples. Drush site aliases: I almost always use a Drush site alias (the "@site-name) parameter, with a command. Some of the commands outlined in this post will only work if you have a site alias. Among other things, it means you can run the command from anywhere. Drush site-upgrade command: One command you won't find in this post is the Drush site upgrade command. After 20 minutes of trying to use it I gave up. As nearly as I can tell my site wasn't configured the way the command needed it configured. Your results could be different so you'll want to check it out. Watchdog Log Commands At various points in the upgrade it's a good idea to check the watchdog log: drush wd-show Module Commands The term module is commonly used to refer to an entire Drupal project even though a typical Drupal project contains more than one module. This can be confusing if the project also has a module with the same name, such as Views. Drush downloads and uninstalls projects, but lists, enables, and disables modules. For example, to remove the Views project in Drupal 6 you disable the Views, Views UI, and Views Export modules, then uninstall the Views project. Multiple modules can be acted on at once. Examples are shown for both a single and multiple modules. Listing modules Drush is an easy way to list installed modules. This is useful for module research lists and creating a list of modules to cut and paste into your script. For a full summary: drush pm-list For a lists all of enabled contributed modules displayed one module per line: drush pm-list --no-core --type=module --status=enabled –pipe Downloading Projects Download the current recommended version of the project: drush @g42dev dl -y backup_migrate drush @g42dev dl -y codefilter google_analytics mollom Download a specific version of the project (required for development versions): drush @g42dev dl -y cck-7.x-2.x-dev globalredirect-7.x-1.x-dev Enabling Modules drush @g42dev pm-enable -y toolbar drush @g42dev pm-enable -y toolbar overlay shortcut update.php (Database Updates) Running update.php using Drush means you don't need to log on as user 1 or use $update_free_access if you forget. Although Drush will tell you if an update error occurred, I like displaying the watch dog log as well. drush @g42dev updatedb --yes drush @g42dev wd-show Disabling Modules drush @g42dev -y pm-disable backup_migrate drush @g42dev -y pm-disable views views_export views_ui Uninstalling Projects drush @g42dev -y pm-uninstall views drush @g42dev -y pm-uninstall admin_menu tagadelic advanced_help Theme Commands Themes are enabled and disabled in the same way modules are. You can also set the current theme, administration theme, and theme settings from the Drush command line. Enable a theme drush @g42dev -y pm-enable garland Disable a theme drush @g42dev -y pm-disable barron Set the default theme drush @g42dev -y vset theme_default garland Set t[...]

Drupal File Upgrade Bash Script

Mon, 04 Jul 2011 03:59:19 +0000

Replacing files during a Drupal upgrade can be tedious, especially for those of us who have to worry about SVN files in every directory. The following script automates this part of the Drupal upgrade, making it much faster and less error prone. I've been using the script in its current form for almost a year and it has served me well. And though most of my other bash scripts have been replaced by Drush commands, this script has proven better suited to my workflow than its Drush equivalent. Overview The script does the following: Deletes the current Drupal distribution files while preserving: directories SVN files all files in the /sites directory tree all files in /files directory tree(I have a number of sites using the old file directory location) the Komodo (.kpf) project file Downloads and expands the Drupal distribution tarball if it has not already been done Copies the new Drupal distribution files to the target directory Removes the unrequired text files. e.g., CHANGELOG.txt, INSTALL.mysql.txt One thing this script doesn't do is remove unused directories. On the few occasions directories are removed from a release I remove them manually, and in my experience there's no harm done when I've missed one. The overall time savings is well worth this small manual detail. Usage Exact usage will depend on how you set up scripts on your system. I have a scripts directory in my path, so the script is treated like a command. Once you placed the script on your system, you'll need to create a directory for the Drupal distributions and update the script's SOURCE_DIRECTORY variable with the location. Usage is simple: cd to the directory of your Drupal installation Issue the command: drupalupgrade {version number} e.g.: $ drupalupgrade 6.22 or $ drupalupgrade 7.4 If you don't have a scripts directory you'll need to place the script file in an appropriate directory and reference the path. The script CAN NOT be in the same directory you are upgrading. Drupal File Upgrade Script (It's also available below as a textfile download, remove the .txt extension) #!/bin/bash # # Remove all of the core files from the current directory and replace them the # files from the specified version. Files in the /site directory are left alone # as well as files in the /files directory for sites that use the old file # standard. CURRENT_DIRECTORY=`pwd` SOURCE_DIRECTORY=~/DrupalSource echo "Drupal Upgrade Script" if [ -z $1 ] ; then echo Please provide a version exit fi echo "" echo "**" echo "*" echo "* Removing old files" echo "*" echo "**" rm -v `find . -type f | grep -v '/.svn' | grep -v './sites' | grep -v './files' | grep -v '.kpf'` if [ ! -d $SOURCE_DIRECTORY/drupal-$1 ] ; then echo "" echo "**" echo "*" echo "* Don't have Drupal source for version $1" echo "* Fetching Drupal source" echo "*" echo "**" cd $SOURCE_DIRECTORY wget$1.tar.gz echo "**" echo "*" echo "* Expanding tarball" echo "*" echo "**" tar xvzf drupal-$1.tar.gz cd $CURRENT_DIRECTORY fi echo "" echo "**" echo "*" echo "* Copying files" echo "*" echo "**" cp -vR $SOURCE_DIRECTORY/drupal-$1/* . cp -v $SOURCE_DIRECTORY/drupal-$1/.htaccess . echo "" echo "**" echo "*" echo "* Removing unrequired .txt files" echo "*" echo "**" rm -v CHANGELOG.txt COPYRIGHT.txt INSTALL.mysql.txt INSTALL.pgsql.txt INSTALL.txt LICENSE.txt MAINTAINERS.txt UPGRADE.txt INSTALL.sqlite.txt README.txt echo "" echo "**" echo "* Done" echo "**" Although some of the ideas in this script are my own, many others came from fellow Drupal colleagues and bloggers whose names I have forgotten. My thanks to them for sharing.Tagged: DrupalDrupal 6Drupal 7bash scriptupgradePlanet Drupal AttachmentSize drupalupgrade.txt1.46 KB [...]