Subscribe to feed Planet Drupal - aggregated feeds in category Planet Drupal
Bijgewerkt: 6 uur 42 min geleden

Wuinfo: Should or Could a Drupal Developer Practice Like a Lawyer

za, 2015/08/22 - 12:50am

For a small Drupal shop or an individual Drupal consultant, how to grow up? It seems that small Drupal shops face a glass ceiling when they want to move upward. They are not able to find a larger project because they not big enough. It is not trustworthy or not give the stack holder a confidence if there are not a team of developers. Should we solve this problem by working together in a partnership? The Drupal developer is a very technical intensive. Let us follow the way lawyers did in their practice. We get together and build a strong team.

What is the benefit to run a Drupal shop in a partnership?
1) It is easy to setup unless we want to form an LLP partnership. As a professional Drupal Freelance, we may have some client already. Initial partners sign an agreement and form a partnership with some existing customers already.

2) A good size team gives confidence to customers. It is going to be easier to win a bigger project.

3) Having a partnership formed, we can recruit more junior developers and train them.

The challenge here is we never did it before. We do may not have any ways to follow. A comprehensive partnership agreement is needed. Here are some important things that we need think through before we form a partnership:
1) Types of Partnerships (General Partnership or Limited Liability Partnership)
2) Governance and Decision-Making
3) Partner Compensation
4) Capital Contribution
5) Overhead and Liabilities
6) Parental Leaves and Sabbaticals
7) Retirement and Termination.

Professional Drupal developers will benefit by practicing partnership in professional service. A reputable good size team is capable of catch and deliver bigger and more profitable projects.

Drupal developers provide highly skilled professional service. Lawyers give professional service related law. Lawyers have lawyer office to provide their service in a decent way. Why not copy the way how they did it to provide our Drupal service.

Referred document:


Acquia Developer Center Blog: Now or later? Weighing the benefits of early adoption for Drupal 8

vr, 2015/08/21 - 5:36pm

If you’re considering a switch to Drupal 8, why not become an early adopter? Becoming an early adopter has some risks — and Acquia will work with you to mitigate those risks — but it also has huge benefits.

In this post, I want to talk to you about those benefits and also share with you my experience with Examiner and its early adoption of Drupal 7.

If you’re not familiar with it, Examiner is a news company powered by thousands of self-contributing writers. Currently, it’s read by 22 million people a month. But back in 2009, the company was having problems with its ColdFusion CMS, and those problems were hampering its growth.

Examiner decided to move away from the legacy homegrown platform to Drupal. So they acquired NowPublic, a citizen-journalism company I founded, for its Drupal expertise and leadership. That’s how I became the CTO of Examiner (I later joined Acquia in 2012).

Moving ahead, the big question we faced at Examiner was: Do we go with Drupal 6, a stable but mature technology? Or do we take a bold leap and implement the yet-to-be-released Drupal 7? Ultimately, we chose to become early adopters, going with Drupal 7.  

Here are the reasons that powered that decision:

1) You stay in front of the technology wave

While a good product at the time, there was no denying that Drupal 6 was closer to its end of lifecycle, while Drupal 7 was just taking off. We already understood the costs involved in supporting a legacy product. And we knew any extra investment early on would be offset by things like a longer lifecycle.

As a side note, unlike previous versions of the platform, Drupal 8 releases will come out every six months. So if you plan to become an early adopter of Drupal 8, not only are you taking advantage of the latest and greatest today — but you will continually upgrade to the latest features over the lifecycle of the product.

2) You differentiate yourself from the competitors

At Examiner, we wanted to set ourselves apart from the competition and we knew D7 would give us that edge. AOL was starting to invest in Patch at that time. And we felt that if we wanted to grow our audience and draw the best journalism to our site, we needed best-in-breed tools.  

3) You can attract the top talent

Great developers want to be on the cutting edge. Who wouldn’t want to jump on an opportunity to work full-time on their passion and be able to contribute back to Drupal? When we brought in a great platform at Examiner, we attracted the best Drupal developers in the world. Very quickly, we hired 15 of the top 50 developers in the Drupal community.  

4) You have the opportunity to shape your investment

Getting in on Drupal 7 earlier put us in the driver’s seat with the technology. That was important. We weren’t looking to adopt just any set of tools. We wanted an opportunity to shape the next generation of a platform. And we knew Drupal was going to meet our needs better than anything else out there. Plus, it’s a lot less risky than building your own CMS, because you are not going it alone. You’re going in as part of a community.  

5) It forces you to develop best practices

Being an early adopter forces you to use best practices with respect to software development. At Examiner, we were able to participate in the community and contribute code to the platform. So for us, being an early adopter forced us to do things the right way — and that set a standard within the company moving forward.

After a year of work, Examiner moved to a new platform built on Drupal 7. Thanks to Drupal 7, Examiner went from not being able to meet the needs of its users to exceeding them. We were able to deliver new features on a faster cadence. We had the best-in-breed platform, the easiest to use interfaces, and ultimately those features accelerated the growth of the company.

Examiner launched on Drupal 7 six months before the official release of the platform. We started developing on it almost a year and a half before the release. So we were really early adopters. Examiner faced tremendous risks, because at that time, Drupal 7 was nowhere near as put together as Drupal 8 is today, but we still decided to do it — and it paid off.  Today, Examiner is a top 60 website.

Being an early adopter is definitely an investment. It will cost more to be an early adopter of Drupal 8, but as Examiner has demonstrated, those costs are set off by several factors. And if you are concerned about the risks, keep this in mind: more than 400 sites are already running Drupal 8. And Acquia has already announced we are ready to support anyone with Drupal 8.

What are your thoughts? Do you have any experiences on being an early adopter of Drupal 7? And how do you feel about the risks/benefits of being an early adopter for Drupal 8? We’d love to hear back from you and get the conversation going.

Workflow: PendingFeatured: NoTags: acquia drupal planetDrupal 8 related: YesAuthor: Michael Meyers

ThinkShout: Relaunching the Southern Poverty Law Center's Website

vr, 2015/08/21 - 5:00pm

When projects get hectic around the office, we remind ourselves “We’re just pushing pixels.” We’re geeks. We sit in an air-conditioned office and play with cutting edge technologies on shiny MacBooks, drinking aeropress coffee. At the same time, we choose to work with nonprofit clients - experienced organizers and passionate advocates working on diverse issues in environmental protection, human rights, early childhood education, access to health care, and community building. We cannot do what they do; but it is wonderful to help them tell their stories and meaningfully engage their constituents online.

Over the last year, we’ve been particularly inspired to have had the chance to collaborate with the Southern Poverty Law Center (SPLC) on the redesign of its website. At the same time, our work with them brought further attention to our team about the many human rights challenges that our country has faced over the last year.

Our initial conversations with SPLC took place days before the death of Eric Garner. And over the year that we’ve been working with the Center, 16 unarmed Black people have been killed by police in the U.S. The Southern Poverty Law Center has been at the forefront of the national conversation about this issue.

If you don’t know SPLC, it is a leading advocacy and educational organization dedicated to fighting hate and bigotry and seeking justice for the most vulnerable members of society. Since 1971, SPLC has been using litigation to fight for civil rights. So hated by the Ku Klux Klan, SPLC’s offices were burned to the ground in 1983 by Alabama Klansmen. Then, in 1987 SPLC won a historic $7 million verdict against the United Klans of America for the 1981 lynching of Michael Donald - effectively bankrupting the KKK and crippling their organization.

In addition to its fight against hate and extremism, SPLC works on a range of human rights issues, such as children’s rights, immigrant justice, economic justice, mass incarceration, and LGBT rights. And so, fortunately, in addition to watching SPLC weigh in tirelessly on the police’s deadly use of force this year, we have also been able to celebrate with its staff over the landmark win over gay marriage bans, as well as the 50th Anniversaries of the March on Selma and the Passage of the Voting Rights Act of 1965.

Again, we have nothing to do with the success of this organization, but to collaborate with this team and to be close to their work has been incredible. We couldn’t be more proud of the website that we designed and implemented along with SPLC’s incredible communications team. Over the next few weeks, we will be writing about the many technical and process innovations we had the chance to implement with the SPLC team. In the meantime, we hope that you will take some time to explore their new site and to join us in celebrating and supporting their mission.


Six Mile Tech: Making a Drupal 8 Contrib Module - The Movie: Raw and Uncut

vr, 2015/08/21 - 4:44pm

As a contrib module developer that is starting to delve into Drupal 8 I wanted to share my experience working with Drupal 8. This is a video of me going through the process of re-creating the contrib module Token Conditions that I had created the week before. Along the way I delve into some new systems in Drupal 8 and give examples of how to figure out how to add functionality to this vastly changed version of Drupal.  


InternetDevels: How DruDesk works: a closer look at our Drupal support service

vr, 2015/08/21 - 2:49pm

Created and powered by InternetDevels Drupal development company

If your website could speak, there’s one most important thing you would probably hear. And this thing is “Please send me to DruDesk!”. Such a silent request can come up in many cases — let’s see when.

Read more

Midwestern Mac, LLC: Vagrant web development - is VMware better than VirtualBox?

vr, 2015/08/21 - 2:42pm

My Mac spends the majority of the day running at between one and a dozen VMs. I do all my development (besides iOS or Mac dev) running code inside VMs, and for many years I used VirtualBox, a free virtualization tool, along with Vagrant and Ansible, to build and manage all these VMs.

Since I use build and rebuild dozens of VMs per day, and maintain a popular Vagrant configuration for Drupal development (Drupal VM), as well as dozens of other VMs (like Ansible Vagrant Examples), I am highly motivated to find the fastest and most reliable virtualization software for local development. I switched from VirtualBox to VMware Fusion (which requires a for-pay plugin) a year ago, as a few benchmarks I ran at the time showed VMware was 10-30% faster.


Drupal Easy: DrupalEasy Podcast 161 - No Custom Code (Jay Epstein - Relativity Data Model)

vr, 2015/08/21 - 9:26am
Download Podcast 161

Jay Epstein (jeppy64), Senior Developer with TrakTek joins Mike, Ted, and Ryan to talk about his Relativity Data Model and why he feels it is a superior method for architectuing Drupal sites with a limited number of modules and no custom code. We dive into the techniques, contrib modules, and benefits of the model before our weekly roundup of Drupal news and events.

read more


Savas Labs: Sassy Drupal theming: Setting up Bourbon and Neat

vr, 2015/08/21 - 2:00am

When Savas built a custom Drupal 8 theme, we needed to include a grid framework and chose Bourbon's Neat for its ease of use, its light weight, and the library of useful Sass mixins provided by Bourbon. In this post I detail how to set all of this up and use Compass to compile SCSS.

Continue reading…


Promet Source: Responsive Design Testing the Promet Way

do, 2015/08/20 - 11:07pm

Responsive design is a watchword for many web design gurus, and it has become a kind of unspoken rule for online experiences: If your website can’t respond to users on every device, then it is an affront to those users. This rule, which maybe doesn’t have to include such unforgiving terms as “affront,” has to be acknowledged well before a user even has a chance to set their eyes and cursor on a website.

Responsiveness is arguably the first barrier to creating good user experiences. So if it’s such common knowledge, then why are we all still talking about it?


Four Kitchens: drupal_practice_group_install()

do, 2015/08/20 - 9:26pm

How do you prepare for the inevitable, yet moving target of Drupal 8 when you’re busy with client work? Join Four Kitchens Web Chefs as we take the plunge with a practice group.


Acquia Developer Center Blog: Five Ways to Leverage Third-Party APIs: The Drupal-Zendesk Integration

do, 2015/08/20 - 8:36pm

When Acquia’s Global Support Team outgrew their ticketing system in 2013, it was time to make a change. An outdated ticketing system was taxing their team and compromising their ability to support customers. In addition to lacking the core functionality required to meet increasing customer expectations, the third-party vendor lacked visibility and integration with existing systems like JIRA and Toggl, reporting was slow, and SLA was waning.

The Global Support Team decided to look for a new, flexible API that would deliver tight integration with existing systems and generate responsive channels for quick, direct and clear communications. Reporting needed to be real-time and fast, and the customer and agent UX needed to be streamlined. Acquia needed a new system.

In Walks Zendesk

After systematic vendor vetting, Acquia’s Global Support Team quickly determined that Zendesk’s documented API provided the flexibility needed to do things the Acquian way. Zendesk is a customer service platform that provides the ideal framework for an enterprise environment. Zendesk offers an out-of-the-box solution, which provides a front-end customer interface and a back-end agent UX. Instead of just “drinking their own champagne,” Acquia decided to split a bottle with Zendesk’s REST API and develop the front-end of their Acquia Help Center in Drupal.

Drupal-Zendesk Integration

With a Drupal-Zendesk solution, Acquia built a powerful ticket request system that provides unparalleled support to their customers and internal teams. Here are five ways Acquia’s Support team leveraged a third-party API to build a new ticketing system.

1. Using Zendesk’s API to create customer requests in Acquia’s Help Center on Drupal

Acquia needed to migrate nearly 100k pre-existing tickets into Zendesk. This kind of overhaul required some reconciliation. Reorganization consisted of deleting completed tickets, cleaning up the open ticket queue, and configuring data into Zendesk.

The new Acquia Help Center was built using Zendesk’s REST API in Drupal, providing a Customer UX that is easy to navigate. The Agent UX, utilized internally by the support team, is outfitted with all of Zendesk’s built-in functionality. Zendesk also offered Acquia’s Global Support Team the ability to customize their apps to guarantee top performance.

2. Additional Info Block Application

The flexibility of the Zendesk Apps Framework allows companies to extend the capabilities of the framework to leverage tickets, users and knowledgebases. Acquia customized their solution with an Additional Info Block Application, embedded in the Agent UX. The info block provides a global and integrated view of the customer.

The info box displays information such as the product the customer is using, the number of application support tickets their subscription enables them to register, what networks they are connected to, special handling notes and their account management team.

“This heightened customer visibility allows diverse members of Acquia’s Global Support Team to best support the customer’, says Jeannie Finks, Director of Global Support Systems and Programs at Acquia. “This supplementary ticket data is a necessity for our team to provide customers with the personalized assistance they need and now expect”.

3. Time Tracking App

By leveraging the flexibility of the Zendesk Apps Framework, Acquia was able to aggregate all of their systems in one place. Existing systems like JIRA and Toggl are essential to Acquia’s workflow, and needed to remain accessible in the Agent UX. Toggl is a time tracking app that allows you to sync your entries in real time. Toggl’s cloud based framework is Acquia’s default time tracking interface. Acquia’s custom Toggl-Zendesk app pushes ticket time to a central repo of daily agent activity:

Additionally, Zendesk’s partnership has enhanced the view of the customers through expert reporting. The Zendesk toolkit allowed Acquia to track tickets rolled in by account, customer backlog, and a root cause report. The introduction of expert reporting offers support teams a comprehensive overview of the customer. Real-time reporting provides Acquia’s Support Leadership with the resources needed to proactively identify critical issues and solve them quickly. This Info Block increases customer visibility, allowing Acquia to see what their customer needs, right when they need it.

4. Custom SLA Monitoring and Notification within Zendesk

The ticketing system also monitors the status of tickets based on a customer’s Service Level Agreement. Acquia continues to take advantage of Zendesk’s flexibility by configuring SLA data from a central customer data warehouse. This customization generates alerts that flow into all key communication channels, such as mail and chat. This custom monitoring system notifies teams when SLA expiration time is appended to a ticket, providing support teams with the visibility needed to best assist the customer.


5. JIRA and Zendesk Linked Tickets

In addition to Toggl, JIRA is a ticketing system that Acquia’s Global Support Team utilized internally. It was a workflow necessity to have continued access to JIRA, and Zendesk’s robust API enabled Acquia to do so. Acquia further customized their API with a mini app that linked tickets filed in JIRA and Zendesk.

The system scans Zendesk ticket comments, subject, and internal URL fields. After scanning, it will match any Acquia JIRA project keys. The system will then display the JIRA key, subject, status, time created, updated time, reporter and assignee. Comment links can also be added to any JIRA ticket.

“The benefit of these customized applications is that all of Acquia’s support systems are connected in one place”, says Finks. “The convenience of having JIRA, Toggl and a customer info block in the Agent UX relieves the major pain points that were taxing our internal teams. Through our integration with Zendesk, Acquia’s Help Center is able to offer unparalleled global support to customers 24/7”.

The next installment of our series will examine best practices when integrating with a third-party API.

Blog series: Integrating Drupal and ZendeskWorkflow: PendingFeatured: NoTags: acquia drupal planetDrupal 8 related: NoAuthor: Georgianna Anderson

OSTraining: How to Use the AdvAgg Drupal Module

do, 2015/08/20 - 7:51pm

Over the last couple of years, I've seen one module appear on almost every high profile Drupal site.

That module is Advanced CSS/JS Aggregation, or AdvAgg, for short.

AdvAgg really helps to improve the frontend performance of your site. This module really helps to improve the aggregation and optimization of your site's CSS and Javascript files.

Here are two videos that will help you install and configure AdvAgg:


Drupal Watchdog: Drush: The Swiss Army Knife for Drupal

do, 2015/08/20 - 6:21pm

By now, if you have been using Drush for a while I assume you are comfortable with all the basics. (I consider the basics to be things like downloading modules or updating a site.) I also assume you are aware that Drush has plenty of other features built in, but you probably don't take advantage of them. In this article I want to show you a few things that are just as easy to use as the “basics” and only require a little upfront setup to use them. Once you learn them, they will quickly find their way into your daily workflow.

Shell Aliases

Consider how much time you spend typing out commands. Now think of all the commands you type over and over again. Next, think about all the commands that have a lot of options and how often you refer to help resources to remember which options you need to use. Wouldn’t it be better if we simplified those things? Conveniently, Drush allows you to do exactly that: create shortcuts or aliases in a file called drushrc.php. I'll refer to it as the command file later in this article.

Let's start with an easy example: the clear cache command. This command isn't very long but we can still improve on it. Plus, it's probably one of the most frequently used.

Edit your drushrc.php file; if it doesn't exist create it. It's typically in your home folder at:


Add this line to the bottom of this file and save it:

$options['shell-aliases']['ca'] = 'cache-clear all';

We just added a shell alias. Now instead of typing this:

$ drush clear-cache all

You only need to type:

$ drush ca

That wasn't too hard, right? That was one line of code, and you just improved on an already very simple command.


Chapter Three: Decapitated Drupal: The Downsides of Decoupling

do, 2015/08/20 - 2:57am

Anyone who has attended a Drupal event in the last few years has had plenty of opportunities to learn all about the technical details of implementing a headless Drupal site. If you haven't already been exposed to this concept the TLDR version is: Headless aka decoupled Drupal is the process of using your Drupal site as the backend for another framework, most typically a Javascript framework.

"The right time to add an abstraction to a design is at the point when you start feeling the pain of not having it."



Wuinfo: A Good Content Strategy Secures a Profitable Business

wo, 2015/08/19 - 11:45pm

Small and medium-size businesses can benefit with a good content strategy backed by a content management system (CMS) like Drupal. The internet is evolving fast. A good content strategy helps business keep a close pace with the trend.

More and more people are using mobile phones to get information and connect with others. A CMS website can quickly turn into responsive design. A responsive website provides better user experience for mobile users. Hence, Google ranks a responsive website higher than none responsive ones.

It is beneficial for a business to have a long term and short term digital plan. It saves money in a long run. If a company has a consistent plan for next 5 to 15 years, it helps avoid costly overhaul of previously built software and redo anything just because it did not fit into a big picture.

Here is an example of my customer who is doing great in the travel insurance business. Their consistent content strategy help them take a lion share of a niche market, a Chinese travel insurance market.

They are focusing on Chinese travel insurance market. At the very beginning, the owner of the business Jun Niu has an excellent long-term goal for his business. He built a comprehensive Drupal based system for his insurance business. With Drupal powerful Multi-lingual support, he built a website having three languages. The website is serving as a primary marketing tool. Mr. Niu published unique content that are valuable for Chinese travelers to Canada. There is an online insurance quotation system built from a Drupal contributed module. With the quotation system, people can easily compare insurance policies from different insurance companies. They can place an insurance order online. Other than that, backend system catches other customers' leads.

A system built on Drupal is well SEO-tuned. Niu's website rank high in Google search result. Keywords like "Canada travel insurance" in the Chinese language is on the first page of both Google and Baidu. Their website rank high in the search result of other search engines. As I am writing this article, their keyword "Canada travel insurance" in Chinese rank #1 on Google search result and also on the first page of Baidu. It brings thousands of organic search visit and hundreds of high-quality leads every week. Without spending any other marketing dollars, the company doing great with the solid content strategy.

Mr. Niu's had the great vision at the beginning. He built his insurance business on a top of Drupal-based software system. Supported by an active and diverse community of people around the world, Drupal is an enterprise standard open source software. Mr. Niu's system serves as a marketing tool that bring hundreds of quality leads every week. The content management system lets Mr.Niu's employees easily publish blogs and articles. Recently, they hired us a Toronto Drupal shop for a main Drupal version upgrade.

If the software is a pillar of a successful business, building a system from Drupal is a cornerstone of it. A good content strategy secures a profitable business.


DrupalCon News: Eating Vegan in Barcelona

wo, 2015/08/19 - 11:17pm

DrupalCon attendees can enjoy their visit to Barcelona taking a walk around some of the many 

Categorieën: frontpage posts for the Drupal planet: Drupal 7.39 and 6.37 released

wo, 2015/08/19 - 10:45pm

Drupal 7.39 and Drupal 6.37, maintenance releases which contain fixes for security vulnerabilities, are now available for download. See the Drupal 7.39 and Drupal 6.37 release notes for further information.

Download Drupal 7.39
Download Drupal 6.37

Upgrading your existing Drupal 7 and 6 sites is strongly recommended. There are no new features or non-security-related bug fixes in these releases. For more information about the Drupal 7.x release series, consult the Drupal 7.0 release announcement. More information on the Drupal 6.x release series can be found in the Drupal 6.0 release announcement.

Security information

We have a security announcement mailing list and a history of all security advisories, as well as an RSS feed with the most recent security advisories. We strongly advise Drupal administrators to sign up for the list.

Drupal 7 and 6 include the built-in Update Status module (renamed to Update Manager in Drupal 7), which informs you about important updates to your modules and themes.

Bug reports

Both Drupal 7.x and 6.x are being maintained, so given enough bug fixes (not just bug reports) more maintenance releases will be made available, according to our monthly release cycle.


Drupal 7.39 is a security release only. For more details, see the 7.39 release notes. A complete list of all changes in the stable 7.x branch can be found in the git commit log.

Drupal 6.37 is a security release only. For more details, see the 6.37 release notes. A complete list of all changes in the stable 6.x branch can be found in the git commit log.

Security vulnerabilities

Drupal 7.39 and 6.37 were released in response to the discovery of security vulnerabilities. Details can be found in the official security advisory:

To fix the security problem, please upgrade to either Drupal 7.39 or Drupal 6.37.

Update notes

See the 7.39 and 6.37 release notes for details on important changes in this release.

Known issues


Front page news: Planet DrupalDrupal version: Drupal 6.xDrupal 7.x

Drupal Easy: Long Form Drupal Training For Long Term Success

wo, 2015/08/19 - 8:33pm

It's that time of year again - the next session of the Drupal Career Online program is about to get underway. Interested in learning Drupal best practices, common development shop workflows, as well as a bunch of the tools that modern Drupal professionals use every day? Looking to expand your current development team but don't have the time or the resources to train existing or new staff? If so, the Drupal Career Online program was designed with your needs in mind!

This will be the seventh time we've taught our curriculum, and the ninth time overall that is has been used for long-form Drupal training (Acquia has used it for their Acquia U program). We're confident that it provides students with the knowledge and experience to compress the amount of time it takes to become a Drupal professional.


read more


Lullabot: A PHP Developer’s Guide to Caching Data in Drupal 7

wo, 2015/08/19 - 8:30pm

If there’s one thing in programming that drives me up the wall, it’s patterns that I use once every few months, such that I almost remember what to do but inevitably forget some key detail. Lately, that has been when I’ve needed to cache data from remote web services. I end up searching for A Beginner's Guide to Caching Data in Drupal 7 and checking it’s examples against my code. That’s no fun at all.

After some searching for a different project, I found the Drupal Doctrine Cache project and thought "what if I could chain the static and Drupal cache calls automatically?" - and of course, it’s already done with Doctrine’s ChainCache class. ChainCache gives us a consistent API for all of the usual cache operations. The class takes an array of CacheProvider classes that can be used to cache data. When fetching data, it goes through them in order until it finds the object you’re looking for. As a developer, caching data in memory in a static cache is no different than caching it in MySQL, Redis, or anything else. On top of that, ChainCache handles saving and deleting entries through the entire chain automatically. If you update the database (and invalidate your cached data), you can clear the static and persistent caches with a simple $cache->delete(). In fact, as someone using the cache object directly, you might not even know that a static cache exists! For example, the ChainCache could be updated to also persist data in a local APC cache. Or, the persistent Drupal cache could be removed if it turned out not to improve performance. Calling code doesn't need to have any knowledge of these changes. All that matters is you can reliably save, fetch, and delete cached data with a consistent interface.

What does all this mean? If you’re already using Composer in your Drupal projects, you can easily use these classes to simplify any of your caching code. If you’re not using Composer, this makes a great (and simple) example of how you can start to use modern PHP libraries in your existing Drupal 7 project. Let’s see how this works.

Adding Drupal Doctrine Cache with Composer

The first step is to set up your module so that it requires the Drupal Doctrine Cache library. For modules that get posted on, I like to use Composer Manager since it will handle managing Composer libraries when different contributed modules are all using Composer on the same site. Here are the steps to set it up:

  1. Install Composer if you haven’t installed it yet.
  2. Create a Drupal module with an info file and a module file (I’ve put an example module in a sandbox).
  3. In the info file, depend on Composer Manager: dependencies[] = composer_manager
  4. Open up a terminal, and change to the module directory.
  5. Run composer init to create your initial composer.json file. For the package name, use drupal/my_module_name.
  6. When you get to the step to define dependencies (you can modify them later), add capgemini/drupal_doctrine_cache to require the library. You can add it later by editing composer.json or using composer require.

When you enable your module with Drush, Composer Manager will download the library automatically and put it in the vendor folder. For site implementations, it’s worth reading the Composer Manager documentation to learn how to configure folder paths and so on.

Using the CacheProvider for a Static and Persistent Cache

We’re now at the point where we can use all of the classes provided by the Drupal Doctrine Cache library and Doctrine Cache in our module. In a previous implementation, we might have had caching code like this:

function my_module_function() { $my_data = &drupal_static(__FUNCTION__); if (!isset($my_data)) { if ($cache = cache_get('my_module_data')) { $my_data = $cache->data; } else { // Do your expensive calculations here, and populate $my_data // with the correct stuff. cache_set('my_module_data', $my_data); } } return $my_data; }

We can now replace this code with the ChainCache class. While this is nearly the same amount of code as the previous version, I find it much easier to read and understand. One less level of nested if statements makes the code easier to debug. Best of all, to a junior or non-Drupal PHP developer, this code doesn’t contain any "Drupal magic" like drupal_static().

function my_module_function() { // We want this to be static so the ArrayCache() isn’t recreated on each function // call. In OOP code, make this a static class variable. static $cache; if (!$cache) { $cache = new ChainCache([new ArrayCache(), new DrupalDoctrineCache()]); } if ($cache->contains('my_module_data')) { $my_data = $cache->fetch('my_module_data'); } else { // Do your expensive calculations here. $my_data = 'a very hard string to generate.'; $cache->save('my_module_data', $my_data); } return $my_data; }

If the calling code needs to interact with the cache directly, it’s entirely reasonable to return the cache object itself, and document in the @returns tag that a CacheProvider is returned. Your specific caching configuration is safe and abstracted, avoiding sporadic drupal_static_reset() calls in your code.

Interfaces are the Future, and they’re Already Here

Even if you prefer the Drupal-specific version of this code, there’s something really interesting about how Doctrine, a small bit of glue code, and Drupal can now work together. The above is all possible because Doctrine ships a set of interfaces for caching, instead of just creating raw functions or concrete classes. Doctrine is helpful in providing many prebuilt cache implementations, but those can be swapped out for anything - including a thin wrapper around Drupal’s cache functions. You can even go the other way around, and tie Drupal’s cache system into something like Guzzle’s Cache Subscriber to cache HTTP requests in Drupal. By writing our code around interfaces instead of implementations, we let others extend our code in ways that are simply impossible with Drupal-7 style procedural programming. The rest of the PHP community is already operating this way, and Drupal 8 works this way as well.

Do you know about other PHP libraries that are great at working with Drupal 7’s core systems? Share them here by posting a comment below.


Axelerant Blog: How to build an amazing Drupal radio

wo, 2015/08/19 - 8:00pm

We love our hackathons at Axelerant, and we are always trying to build something that helps spread happiness. We thought it would be nice to have an internal web-based online radio, where people would be able to listen to songs along with some fun social characteristics.

Thus, one of our hackathons saw us getting down to build a Drupal radio website, with the following features.

  • Ability to upload songs
  • Ability to dedicate a song to anyone with a message
  • Play a random song when the dedicated song queue is empty
  • Integrate the radio site with Slack, and display the current track being played
  • Display the Up Next queue
  • Build the radio site using only Drupal, without any radio streaming software

Described below is how we went about putting the various components of the online radio together.

Uploading a song on the online radio

We created a content type called Song with the following fields:

  • Song field of type File to upload music files
  • Art field of type Image, to upload the album art
  • Tags of type Term Reference to tag artists, genres, etc.
  • Duration of type Number to track the song duration

An interesting part was the song duration. The getID3 library helped us fetch the song duration, and so, in the content type song feature I created a hook that added song duration on the creation of a new song. As it is automatically calculated and added, the song duration field is hidden from end users.

Uploading a song on an online radio, built using only Drupal

Dedicating a song on the Drupal radio

We created a content type called Request with the following three fields:

  • Song field of type Entity Reference that points to the song nodes
  • Dedicated-to of type Entity Reference that points to the User to whom the song is dedicated
  • Message of type Text for the message he/she wants to dedicate.
  • Played-at of type Date to keep track of when the song started playing
  • Default-request of type Boolean to know if this node is a song that is played by default or if its a request.

After a request is saved, the resulting node would be added to a nodequeue. The fields Played-at and Default-request are hidden.

Dedicating a song on an online radio, built using only Drupal

The Magic

We created a method that simulated a constantly playing playlist. It did three things

  1. Check if the requested song is playing.
  2. If not, play it.
  3. If the song is done playing, remove it and pull up the next requested song and play it.

The detailed logic looks like this:

  1. Check if there are any songs in the node_queue.
  2. If there are any, then check if the first song has already started playing by seeing if the Played-at is set or not.
  3. If it is not playing, set Played-at field to the current time, which means that this song has started playing.
  4. If it is playing, check if the current time has passed the Played-at + Duration time of the song being played. If it has passed, it means the song is done playing.
  5. If the song is done playing, remove the request, populate Played-at field for the top request with the current time.
  6. If there is no request, get a node marked as Default-request and put some random song, update Played-at to the current time and add it to the top of the queue.

This above function would be called twice, once by the cron and once just before the page that serves the song would be rendered.

Whenever a new song would get pulled, the site would send a Slack channel notification.

The View

The now playing song is rendered by the Views module. The view displays whichever song is at the top of the node_queue. We wrote a tiny .tpl file to stream the song rather than display the link to the song file. We used the HTML5 <audio> tag to render the MP3.

There was one more hurdle that we had to cross before we were done - we wanted the song being heard by everybody to be in sync. If we had rendered as-is, everybody would start hearing the song from the beginning. To avoid this, we also rendered the Played-at field to the front-end.

Thanks to the HTML5 audio object’s CurrentTime attribute, we could start a song with an offset. A tiny .js file would compute the difference between the current time and the Played-at time, and add that as an offset to the audio object, and voila! The song starts playing with a certain offset, achieving a sync across requests, and simulating an actual online radio.

Once the song ends, the js callback would reload the page, and our magic function would run again. The latest song would be pulled up or a newly dedicated song will be rendered by the view.

The View - An online radio built using only Drupal

If no one is listening, the cron keeps playing the next song at random, and Slack keeps notifying us of the currently played songs.

Slack notifications for the online radio using Drupal

We do a lot more cool stuff like this Drupal radio at Axelerant. To join us, visit our careers page or contact sales so we can do this for you.

The post How to build an amazing Drupal radio first appeared on Axelerant.