Why write user stories

Posted by ADCI Solutions on January 26, 2017 at 3:36pm

Does it matter what technology you stick to when it comes to delivering the right product? We develop complex Drupal projects and we know how vulnerable a development process is: a client may realize that the product should reach another goal or this goal should be implemented the other way. How to get control? We suggest writing so called user stories: it’s a requirement that clarifies what user type wants to do and why. Being written on the negotiations stage, these stories save a huge amount of time and budget. User stories is a popular method of control in Agile approach that Drupal developers are highly likely to use these days. We recommend reading this article and learning how to write stories correctly for Drupal developers, Drupal project managers and product owners. Click here.

User stories

The quest for performance improvements - 5th sprint

Posted by CiviCRM Blog on January 26, 2017 at 2:47pm

The last two days we spent another sprint at socialist party to improve performance.  And again we used a guy with database knowledge to analyze our queries. We have optimized a few things so far one of the major areas to improve next was the ACL part of queries. That is the part of the query to decide which contacts you are allowed to see. So at the socialist party they have local chapter administrator who are only allowed to see the active members in their local area.

To decide which contacts you are allowed to see a search query is rebuild to include this ACL part. So there is a join on the membership table and a join on the chapter-structure table and then a where expression is to filter on the chapter and to filter on active memberships. Meaning that the MySQL will scan all records in the table civicrm_contact which at the socialist party is around 350.000.

We have worked on a proof-of-concept solution so far which is to create a table with the user_id and which contact_ids the user is allowed to see. We then do a join on this table resulting that only that subset of contacts is scanned by mysql. Which in fact improved the search query from running a few seconds to just a few milliseconds.

When a user logs in we check how long ago it was when we last updated this table and if it is longer than 24 hours we will delete the entries for that user and re-insert the entries.

We have also reported this at the CiviCRM issue Queue see: https://issues.civicrm.org/jira/browse/CRM-19934

The next thing we are going to work on is to make the proof-of-concept stable and do some refactoring of the core civicrm_acl_contact_cache table.  As this proof-of-concept looks like a bit what civicrm_acl_contact_cache should do but does not do.  Also we want to add a setting in the user interface where site-administrators could set the value for the validity time.

We are also wondering what your thoughts are about our performance quest so far and about our proposed solution.

 

Drupal

Drupal 8 DIY: Creating Content Tabs with Theme Libraries and Slick

Posted by Acquia Developer Center Blog on January 26, 2017 at 2:22pm

Continuing from our previous post, Drupal 8 DIY: Creating a Slideshow with Theme Libraries and Slick, we wanted to build on the power of theme libraries provide us in Drupal 8.

Tags: acquia drupal planet

245: Drupal Association Board Community Elections 2017 - meet Megan Sanicki

Posted by Acquia Developer Center Blog on January 26, 2017 at 1:41pm
DrupalCon-2013-BrokenBanjo-6.jpg - Photo by Trav Williams, Broken Banjo Photography www.BrokenBanjo.net

In this podcast and video, Megan Sanicki, Executive Director of the Drupal Association, and I talk about what the DA Board is all about and why you might want to run for a community directorship. The 2nd half of the podcast is also a chance to get to know Megan. Megan fell in love with the intersection of tech and community work and has been with us in the community since 2009 (or 2010, she's not sure ...).

Talking about the business side of Drupal, I really like what she has to say:

"It's more important to me how we move through life together as a community to create amazing software."

Should you run for the Drupal Association Board of Directors?

One interesting aspect of the DA Board that sets it apart from the rest of the community is that it goes against the grain, the nature of how we usually go about things. We're a community of doers. If you want to fix something specific, there are probably better places for you in the Drupal community, places where you can get busy, help, and improve stuff. The Board is an odd corner of the Drupal community where it's not about getting things done. I imagine a lot of people would be frustrated by that.

Listen to my conversation with Megan and if you want to serve the community in this capacity, here's what you need to do:

More background info
  • Michael Schmid and I recorded a follow up and analysis of the 2016 DA Board community election that I published audio and video of as Acquia Podcast 225.
  • I recorded a conversation with the 2016 DA Board community election, Shyamala Rajaram and published audio and video of it as Acquia Podcast 243.

Skill Level: BeginnerIntermediateAdvanced

Transitioning from Drupal 7 to Drupal 8: programatically creating blocks

Posted by Blair Wadman on January 26, 2017 at 11:58am

If you are used to creating Drupal 7 modules, one of the major challenges of moving to Drupal 8 is all the changes under the hood. Almost everything has changed and that can be very overwhelming. But it doesn't have to be. One method to learn how to create Drupal 8 modules is to compare it to what you are used to in Drupal 7 module development.

Drupal and SEO: A fly-by tour

Posted by Real Life Digital on January 26, 2017 at 11:55am
Drupal SEO - written in dark blue on a light blue background. The 'O' has been replaced with the Druplicon Drupal Icon.

We are often asked by those who are new to Drupal and familiar with Wordpress - "what SEO options are available?". In order to answer this, we've put together an overview of some of the tools available for Drupal. We're only really going to scratch the surface, but here's a few things that Drupal can do for you to boost your rankings in search engine results.

AGILEDROP: The Importance of Drupal Events

Posted by Agiledrop.com Blog on January 26, 2017 at 9:01am
Drupal Global Sprint Weekend will happen at the end of this week almost all over the world, so we have made a list for you, where you can attend it. We have also analysed Drupal Camps on all continents last year and presented you the reasons why you should attend DrupalCons. All together with user group meetups, they form Drupal events. But why is organizing and attending them important? Here are the reasons. Have you ever been to any of the described Drupal events? If your answer is yes, then you'll already familiar with things. But since you probably did not take the full advantage of it,… READ MORE

Musings of a Business Track Lead

Posted by DrupalCon News on January 25, 2017 at 10:05pm

Before working on the Session Track description, I spent some time researching. There are lots of blog posts on the business of Drupal, plus surveys and articles - and, of course, what other Session Track committees have researched and put together.

What it seemed to come down to this year was our own unified experiences - and the first ever Drupal CEO survey that supports what we see and directs our topics.

Dropcast Episode 28: Ahh Fabian Franz

Posted by Mediacurrent on January 25, 2017 at 9:49pm

Recorded January 19th, 2017

This episode we are ringing in the new year and giving you all a treat, by letting someone else talk. We welcome Fabian Franz, a core committer for Drupal 7  and co-creator of Ryan’s favorite thing in the whole wide world, Big Pipe. You do have to listen to us a little as we talk about Mediacurrent’s awesome blog posts, and Drupal News. Mario brings us the first Pro Project Pick of the year and we’ll finally shut up with Ryan’s Final Bell.

University of Minnesota

Posted by Drupal.org Featured Case Studies on January 25, 2017 at 9:42pm
Screenshot of homepage at umn.eduCompleted Drupal site or project URL: http://umn.edu

Simply put, University of Minnesota is enormous. Nearly 70,000 students are enrolled at this Big Ten university with five major campuses spread throughout the state of Minnesota. Much has evolved since it was founded in 1851, but the University’s core values remain the same: enrichment by understanding, advancement of learning through education, and the search for truth through research; all of this to benefit the people of the state of Minnesota, the nation, and the world.

The University of Minnesota was planning to replace its existing Oracle Universal Content Management (UCM) system with a flexible, hosted Drupal implementation. The University’s UCM implementation had more than 600 sites, which represented a considerable amount of storage, and millions of site visitors monthly. Furthermore, while the University has a central Office of Information Technology (OIT), the system is a distributed environment where each collegiate unit has its own management structure and its own internal Web team.

OIT wanted to create a centralized platform that would be an attractive and more easily maintainable alternative to departments spinning up their own independently-hosted sites. Several pilot sites would serve to provide representative real-life examples of various use cases for the platform.

Key modules/theme/distribution used: PanopolyWorkbenchMigrateZenOrganizations involved: Palantir.netTeam members: agentrickardCrell

Drupal 8: How to Reference a Views' Block Display from a Field

Posted by Mediacurrent on January 25, 2017 at 6:49pm
Drupal bits and bytes

In Drupal 7, if you wanted to reference a view display from a node field, you had to use a module such as Viewfield. In Drupal 8, this can be done with Drupal core alone by using the built in entity reference to reference a block instance created from the view.

Step 1: Create a hidden region in your theme.

1. Open your THEMENAME.info.yml file.
2. Find the section for "regions:"
3. Add a new line: hidden: 'Hidden region for referenced blocks'

New Year New Drupal Events

Posted by LevelTen Interactive on January 25, 2017 at 6:15pm
As the first month of the new year comes to an end, the Drupal Community is ramping up for the many DrupalCamps and annual DrupalCon that are sure to happen. As part of our Web Dev Wednesday, we compiled a list of DrupalCamps in the United States everyone should attend.   

Entity Lookup & Generate migrate process plugins

Posted by MTech, LLC on January 25, 2017 at 4:06pm
Entity Lookup & Generate migrate process plugins

Thanks to the drupaleros community, Drupal 8 has two new plugins added in the migrate plus module: entity_lookup and entity_generate. These can be used to lookup and create an entity if it does not exist. I will show you a way in which we can implement these plugins and we will see for what applications they can be used.

Ada Hernández Wed, 01/25/2017 - 10:06

Learning Drupal: Time is On Your Side  

Posted by DrupalEasy on January 25, 2017 at 3:15pm
Take your time concept clockMiriam Webster defines effort as conscious exertion of power: hard work

If you want to learn Drupal, you need to put forth some effort, and if you want to do it properly, get ready to exert some power for months, not days.  People ask us all the time if they can get a job right out of our Drupal Career Online program. The truth is, it depends on how much hard work you put in to get out ready enough for an internship or junior position. Whether it’s Drupal or anything else, learning something and being able to apply it well depends on how much you absorb and practice, both of which are best done over time.

Last summer, James Dennin wrote an insightful piece of advice for those seeking careers in coding for Fusion.net. It touches on a lot of the same issues with bootcamps that we have heard about for years from students who come to DrupalEasy Academy after disappointing experiences. While we don’t like to throw barbs, we like less the sad stories of lost dollars and time in unguided crash courses where people are seated in a room, immersed in videos and teamed with other, non-skilled newbies on trying learn Drupal. A 5- or 10-day whirlwind of information overload is seldom a successful learning experience.

Becoming proficient in Drupal is no cakewalk; it includes amassing knowledge, learning best practices and developing skills as part of a challenging learning process, whatever your process may include. Education experts recognize as many as seven different styles of learning, including:  Visual, Aural, Verbal, Physical, LogicalSocial and Solitary. Most people find a combination works best. For anyone, regardless of the learning style; taking the time to really soak it in and get some hands on experience is key. The bottom line is that Drupal takes time and practice.

For those who do well on the solitary route, Build-a-Module, which routinely supports students and alumni of our career training program, has a solid, comprehensive library of instructional videos that you can take your time to work through with a modest monthly subscription.  You can also check out Drupalize.me.

For those who learn better with a formal course or need to train-up a team; our Drupal Career Online program uses live instruction; a stackable-skill designed curriculum; practical exercises; and group learning.  We also provide resources like lesson guides, screencasts for every lesson, and help when you need it. In addition to all the great feedback we get from our students and all the great graduate case studies, we ensure our program meets accepted educational standards as a career program, so we go through an annual review to ensure we remain a licensed, post-secondary institution through the Florida Department of Education, Commission for Independent Education (see page 21 of the linked PDF.)  

We are committed to Drupal and developing awesome Drupal talent, which is why we cringe when we hear about drinking-out-of-the-firehose learning scenarios. It is also why we have been perfecting our course (yes even making it longer) over the past 6 years. Best practices and allowing students the time to soak up what they’ve learned, along with hands-on projects and expert-developer instruction are fundamental elements of Drupal Career Online. It includes 84 hours of live, online instruction over 12 weeks as part of the learning community of current students and alumni. The course covers practical projects and assignments, and includes 12 co-working labs and instructor office hours, which are available to current students and alumni every week. The Spring 2017 session begins March 13, with the deadline to apply March 6.  

For most, learning anything, especially Drupal, is a process that takes an investment of time and effort, not just from the students, but from those who endeavor to help them learn.  Don’t cheat yourself and risk wasted time by trying to save time. Whatever learning styles work for you, make sure you take the time and put in the effort to follow a logical path that builds knowledge and helps you get comfortable with key skills in the way that ensures your hard work leads to your ultimate success.

For more resources about becoming a Drupal developer, take a look at our Career Resources.  To learn more about our upcoming Drupal Career Online Spring session, sign up for one of our free Taste of Drupal online information sessions in February.

take your time concept clock Photos by Pond5

Managing Microsites with Drupal 8

Posted by Convivio on January 25, 2017 at 3:04pm

There are lots of situations in which you need to run a series of microsites for your business or organisation — running a marketing campaign; launching a new product or service; promoting an event; and so on. When you’re with Drupal, though, what options do you have for running your microsites? In this article I review and evaluate the options in Drupal 8, make a recommendation and build a proof of concept.

So, I want to run some microsites …

A client brought me an interesting problem recently, something they need to solve for their production Drupal site. They are an international humanitarian agency who, alongside their main production website, want to run some microsites for a number of their public campaigns. Although they could run them on the main site, they’ve found too many limitations in trying to do that. Campaign teams, frustrated with the lack of flexibility and slow protocols for getting changes made to support their bespoke needs, have often gone off with their small budget and dynamic team to create something quick that fits their campaign with Squarespace or Wordpress or something.

That made the campaigners really happy. But, when the campaign or event lapsed, the campaign site quickly got out of date and went unloved, the campaign team moved on and no-one could remember how to log into the system and it became abandoned.

Hearing this story was so familiar — the same thing often happened when I was a senior developer at Oxfam International.

So, they said, could something be done about it? What, if anything, could be done with Drupal to support campaigners get their microsites running? What would give them the fast, bespoke solution to their microsite problems, whilst still keeping all the content well-managed and being able to share that content with the main site or other microsites?

I scratched my chin and had a think.

How about Drupal multisites?

Since some of its earliest versions, Drupal has included a feature for multi-sites — running several sites from a single codebase installation, sharing the core system, contributed and custom modules and themes. Each multisite has its own database, its own settings and configuration, its own content, and so on. Ideally, it also means updates can be done once.

So, multisites could be an option. Many people find them to be a real workhorse for their context, and often they are right on the money.

Why use multisites

The Drupal.org documentation for multisites includes a simple rule-of-thumb for when to multisite:

As a general rule on whether to use multisite installs or not you can say:
- If the sites are similar in functionality (use same modules or use the same drupal distribution) do it.
- If the functionality is different don’t use multisite.

(DrupalCon Austin [June 2014] held a interesting debate on Drupal multi-sites, its pros and cons, gotchas and suggestions, which is available on YouTube.)

There’s several compelling reasons to use them.

First, having a single codebase to maintain is a huge plus. Forked codebases can soon become orphaned, and unloved codebases become fraught with problems too quickly.

Second, multisites often mean there is also a single hosting platform to maintain, which is also a major advantage.

That can often mean, thirdly, that multisite installations can make better use of resources, both the server resources and financial, personnel or other physical resources. For example, since multi-sites share the same core and modules, that code need only go into the opcode cache once, saving server resources.

Caveat: is the end of multisites support on the horizon?

It should be noted that a proposal has been made to deprecate support for multisites in Drupal, with a view to removing it in the future.

The basic argument for this is that it’s an ‘old skool’ way of thinking about handling multiple sites. Git and Composer create practices and codebase structures that point in other directions.

The modern approach to multi-site is: git — Same code, different sites. Under your control. And well-maintainable.

There are a number of positive reactions to that proposal, which are variations on a theme:

+1. Multisite is a historical oddity at this point and I’d never tell anyone to use it.

But there are many more negative reactions, which largely go along these sorts of lines:

-1. Multisite has been a workhorse for a ton of Drupal sites and is well established in our code.

In that light, Drupal’s multi-site feature is likely to stay around for a while.

Classic problems with Drupal multisites …

It’s not all a bed of roses, though. There are some classic sticking points when working with Drupal multisites.

First off, handling traffic. One site’s traffic spike can be another site’s nightmare when the hosting resources are all hogged by The New York Times tweeting a link to a page on a site of yours; one site’s ‘BEST DAY EVA!’ can be the worst of times for all the rest.

The load on your database server may also be an issue. Multisites often use a single database server, and heavy load or slow queries in one DB can impact the performance of others. This might even be caused in the normal running of your Drupal sites, such as when running cron.

Running updates often causes headaches. When you update code, you’re updating all your sites at once. That means the updates are deployed, well, instantly across all your sites, but if they need update processes to run, such as updating the database, that can throw unexpected problems or errors.

And the worst of the worst: a small piece of poorly written, inadequately reviewed or tested code mysteriously jumps itself onto production — that never happens, right? No one ever lets that happen, do they? *ahem* — and takes down all your sites at once! It’s just an urban myth, a story to scare the children with at night, right? Never happens.

… and how to mitigate them

There are of course a number of ways to foresee these things happening and be ready for them.

On the performance questions, with smaller demands you can just ride it out — sites on the same hosting platform are fairly tolerant of resources being shared around, and the spare capacity is there for times just like there.

For larger performance demands, handling the pressure is a challenge in any hosting set-up, dedicated hosting just as much as shared. With modern cloud infrastructure, the option of scaling up your infrastructure or spinning up a new cluster when you’re experiencing ongoing heavy demand is much easier than in the past, especially if you plan for it as a possibility.

The next set of mitigations are all about best practice.

For starters, test, test, test. Don’t let any code onto production that hasn’t been tested thoroughly.

Have a solid release process that you always follow. If possible, include dev, staging and quality assurance stages. This should give you lots of points to catch things before they’re released onto your production sites.

Automate all the things. There are lots of ways of automating things to ensure they run consistently and quickly too, from shell scripts up to continuous integration tools. Use them.

And finally, be intelligent. With code changes that need database updates, for example, design your code so that it can be deployed to handle an interval before the database is updated. Or, with important but more volatile updates, be smart about choosing the time of day and week that you deploy it. Don’t ever push something out at 5pm on a Friday afternoon if you want to stay friends with your colleagues, your customers and your family.

Well, yes, in short, kinda. You could run microsites using Drupal’s multi-site feature. Things would work fine, though of course you’d have all the problems described above and have to take the mitigating actions.

However, it wouldn’t solve all the needs described above without some smart thinking. Plus, I’d suggest that you would also have some other problems to solve.

First, multisites all use different databases (sharing databases and tables is possible with Drupal multisites, but really unadvisable!) so the need of a single place for managing all the site content wouldn’t really be satisfied. The way around that would involve using web services, posting and pulling content from one site to another.

Neither would we have a unified search. There are fairly straightforward ways around that, using a tool like Apache Solr. The sites would need to share an index, with each document in the index including a site field, and there’s a contrib module that does that already (although no Drupal 8 version yet).

Lastly, and maybe more pertinently, you would still have all the ‘Drupalisms’ to live with. First of those is the visual design layer, the public user’s interface for the sites, what gets called the ‘theme layer’ in Drupal lingo. Many designers really dislike Drupal’s theme layer, and would really prefer to work with the pure frontend tools they use in other contexts. Drupal 8 has made major strides forward with the theme layer so it’s not as tough for designers as it once was, it’s true, but many (most?) frontend specialists would still rather not work with it.

Some consider influential Drupal figures consider multisites as ‘not enterprise grade’ and opinions like that are worth considering if your situation is enterprise scale.

Other approaches with Drupal

There are a few other ways of supporting microsites with Drupal that might be worth considering.

Domain Access

The Domain Access project was created to support just this kind of functionality. The project overview says as much:

The Domain Access project is a suite of modules that provide tools for running a group of affiliated sites from one Drupal installation and a single shared database. The module allows you to share users, content, and configurations across a group of sites.

This might work. However, there are many of the same problems with core multisites described above with this approach, with one additional one: everything in one database.

Our experience of using it, and this is echoed by others too, is that with a small number of very similar sites Domain Access can work well. With a larger number of fairly different sites, it’s a right pain and actually makes things quite difficult, requiring lots of complicated custom code.

Organic Groups

The Organic Groups suite of modules could be a solution for building microsites. The project allows users to create a ‘group’ within a Drupal site. The group can have its own users, admins, content, menus, even its own visual design. However, it would need every microsite to sit internally, within the main site, so does not solve the need to supporting external sites on their own domain. So, not really the perfect fit.

Best practice: with Git

I quoted above from @sun in the discussion on deprecating multisite support about the modern best practice:

The modern approach to multi-site is: git — Same code, different sites. Under your control. And well-maintainable.

This is certainly my standard recommendation and will give you many advantages: independence of sites for performance, design, etc; single codebase to maintain (though you’ll have a challenge developing and maintaining the variations you’ll want or need for each microsite); better control over updates; and so on.

You might even look writing an install profile to make a full distribution, though with Drupal 8 there is less of a need to do this. With Drupal 8, I’d advocate that you use Drupal Composer to build your site and just export your full site config into your repo (being careful to remove any sensitive settings from the repo with your .gitignore file).

Or you might also consider using Aegir to manage your multiple sites — use Drupal to deploy Drupal, if that’s not too much Inception.

Microsites and Drupal

So if multisites could work but would be a bit of a pain, the other Drupal approaches are even less appealing, and you’d rather not keep multiplying Drupal installations, how else could we do microsites with Drupal?

Well, there are two major moves in modern web development that might help here: RESTful web services, and decoupled CMS architectures (a.k.a. ‘headless’ CMS). My proposal for managing microsites in Drupal 8 depends on both these ideas:

  • Treat your Drupal site as a pure content management system (CMS) — a content hub that allows authors, editors and administrators to create, update and manage the content for which they’re responsible, but doesn’t have any meaningful frontend presentation layer to it.
  • Present the data of the content in the hub CMS via a RESTful API.
  • Implement a separate frontend for the visual presentation layer that communicates with the content hub CMS via the API.

There need be no limit to the number of frontends that use the CMS’s API (though practically you may limit access with firewalls, CORS or some other means) so you could power a primary public site, other sub-sites, native mobile apps or even another CMS or two, each potentially with their own visual design. The limit is your own imagination and situation.

RESTful web services and Drupal 8

A new addition to Drupal 8 is the RESTful Web Services API. REST resources can be exposed to allow other things to talk to/consume/feed a Drupal site. Many core entities have REST resources, but it is also fairly easy to build custom REST resources. (There a number of interesting web services contrib projects that are worth considering, such as the GraphQL project that presents a GraphQL schema, and the RELAXed Web Services project that extends the core REST resources.)

Design your own web services API

The freedom to build custom REST resources in Drupal 8 allows a lot of freedom in designing a RESTful API.

In a forthcoming blog post I’ll write in more about designing an API. For now, all I need to say is you need to actually design your API. Don’t simply use the out-of-the-box Drupal core REST resources — think about the RESTful API that would best serve the frontend you want to have.

My heartfelt recommendation is you do this, designing your API, using the skills of those who’re best at designing things — your designers. They understand best what your users want to do on your sites, will be able to describe what data they want for the frontend (content with/without markup, etc.) and help you design the API that is most appropriate to your needs.

There are some API design golden rules and best practices that you should consider. Also I’d recommend using an API design tool like Apiary.io or Swagger.io. They’re invaluable for many reasons, not least of which is the lovely documentation they generate and mock data servers they include that can help frontend devs get going quickly.

Decoupled frontend

With the content hub now presenting the managed content as RESTful data, we just need a standalone frontend system to present your website to your users: one for your primary site, and one for each of your microsites. Your frontend specialists can then work with the right tools for the task, then.

There are several advantages to consciously uncoupling the content management and the frontend.

Freedom: frontend specialists are free to the implement the user experience with native tools that are built for the job.

Performance: everything in this architecture can be streamlined. The CMS simply presents the content data. The frontend focuses on the display logic.

Experience: the website can respond to users in real time, communicating back and forth with the CMS to give real-time interactions in the browser.

Future proof: it becomes much easier to replace any part of the system as you require, such as redesigning the website without re-building the CMS.

Microsites in Drupal 8

So, how might we do this practically in Drupal 8? Here’s how I tackled it.

First, I thought about designing a quick prototype API that could be used to describe microsites and their content. I used Apiary.io to design it, and you can view the API at docs.campaignmicrosites.apiary.io.

API design at docs.campaignmicrosites.apiary.io

Next, I installed a Drupal 8 instance with Drupal Composer to act as the editors’ content hub and created a ‘Campaign’ content type with some basic fields. This ‘Campaign’ content type is the core of the microsite support. Each Campaign creates a new microsite.

Since in this client’s conundrum the microsites can be internal (i.e. sit within the main public site) or external (i.e. on their own domain or sub-domain) I added two fields:

  • external site (true/false boolean)
  • external URL (URL)

These will allow requests for the microsite from within the main site to be redirected to the external URL, and will help in constructing the right data in the API resources.

‘Campaign’ content type in Drupal content hub

I also adapted the core Article content to include an entity reference to a ‘Campaign’ node, and included a taxonomy reference field to indicate the ‘type’ of article — news; FAQ; info; etc.

The next task was to create the REST resources that matched the APIs I’d designed. For this I created a custom module, campaign_api, and created four classes, one for each of the API resource collections I’d designed, in the `Drupal\campaign_api\Plugin\rest\resource` namespace.

Drupal custom module for the new REST resources

The quick and dirty code for the `get` method on the Campaigns resource looks like this:

/**
* Responds to GET requests
*
* Returns an array of Campaign data.
*
*
@param null $unserialized
*
@param \Symfony\Component\HttpFoundation\Request $request
*
@return \Drupal\rest\ResourceResponse
*/
public function get($unserialized = NULL, Request $request) {
$build = [];
// Default langcode
$langcode = $request->query->get('langcode', 'en');

// Load campaign nodes
$query = $this->entity_query->get('node')
->condition('type', 'campaign')
->condition('langcode', $langcode);

$nids = $query->execute();
$campaigns = \Drupal::entityTypeManager()->getStorage('node')->loadMultiple($nids);

// Array of image styles to support
$image_styles = [
'large' => 'full',
'medium' => 'medium',
'thumb' => 'thumbnail'
];

/** @var NodeInterface $campaign */
foreach ($campaigns as $campaign) {
$image_array = [];
$image_file = File::load($campaign->get('field_image')->target_id);

foreach ($image_styles as $name => $style_name) {
$style = ImageStyle::load($style_name);
$image_array[$name] = [
'url' => $style->buildUrl($image_file->getFileUri()),
'alt' => $campaign->get('field_image')->alt,
];
}
$external = (integer) $campaign->get('field_external')->getValue();
$build[] = [
'id' => $campaign->id(),
'uuid' => $campaign->uuid(),
'langcode' => $campaign->language()->getId(),
'languages' => [
$campaign->language()->getId() => $campaign->language()->getName(),
'default' => $campaign->language()->getId(),
],
'title' => $campaign->getTitle(),
'created' => $this->date_format->format($campaign->getCreatedTime(), NULL, 'c'),
'external' => !empty($external),
'external_url' => $campaign->get('field_external_site_url')->getValue(),
'description' => [
'formatted' => check_markup($campaign->get('body')->value, $campaign->get('body')->format),
'raw' => $campaign->get('body')->value,
],
'image' => $image_array
];
}

$response = new ResourceResponse($build);
$response->addCacheableDependency($langcode);

return $response;
}

Enable those resources (by clicking stuff with REST UI module installed, if you like), of course, and then create some content to populate the responses — one campaign called ‘DIY succulents’ and the other ‘Slow-carb cred’ (yep, I used some Hipster Ipsum).

Enable the resource endpoints

Then you should be able to retrieve your data at the appropriate endpoints. A nice way of doing that is with the free Postman app (there’s a Chrome extension also). Postman makes a request to the endpoints you specify and pretty-prints the response. Marvellous!

The final part is the standalone frontend tool. For this I used React. I used React to build my frontend app, but there’s obviously plenty of other options depending on what the frontend needs to do. React worked for me because I just wanted the view layer, but Angular or Ember could be more appropriate if the frontend needed to be a more substantial app. You’d need to evaluate the frontend options carefully.

I’m not a frontend specialist, so my prototyping code is pretty fugly. Despite that, we’re able to serve two microsites simultaneously on different URLs, with a different theme, just by switching the campaign ID in the API request.

Bingo!

Deploying to production

There’s a few things I might do to deploy this to a production system.

Secure serving

As a good internet citizen, I’d want to put everything on SSL.

Frontend deployment

To deploy the frontend, I’d be looking at options to run the apps on a NodeJS server so that most of the scripts can run server side.

I’d probably want to put an Nginx instance in front of it, for SSL termination, caching static assets and reverse proxy.

Use Drupal multisites ;-P

I think there is actually a neat way of using Drupal’s multi-sites feature here: use a different domain for the RESTful API. For example:

Editorial interface: hub.yourdomain.com
API interface: api.yourdomain.com

Both of these point to your Drupal codebase but you can then handle requests differently on each domain. For example, you might add an authentication provider that checks the domain to give you some access control, so there’s no access to the editorial interface on the API subdomain, and none to the API on the editorial domain.

Caching etc.

This would then allow you to do some smart things with caches and other parts of your hosting stack, offloading much of the pressure on the codebase to the caching architecture and removing the actions of editorial staff from affecting the RESTful API’s performance.

Databases

It might also be possible to configure GET requests to only use a slave database, which could be useful for performance — though may be more hassle than it’s worth. POST, PUT, PATCH and DELETE requests would still need to go to the master.

In summary

This prototype worked really well for me and I was very happy with the results, and it gave me something very interesting to discuss with the client.

The advances made in Drupal 8 to operate with current standard web practices are good news for developers and for web projects big and small. For this prototype, the particular improvements with providing RESTful resources means that I was able to create a decoupled Drupal system to support a main website and unlimited microsites in an amazingly short space of time.

… and something to take away

If you’re interested in following up this thought experiment with my Drupal 8 prototype, I’ve put the code into a repo in GitHub:

ConvivioTeam/Convivio-ContentHub

Just …

$ git clone git@github.com:ConvivioTeam/Convivio-ContentHub.git {some_empty_directory}
$ cd {some_empty_directory}
$ composer install

… and you’re away.

(My React code is shamefully dirty, so I’m not prepared to share that at moment. ;-) I may tidy it up in the future and share it here.)

Main image: courtesy of Denys Nevozhai/Unsplash. https://unsplash.com/photos/guNIjIuUcgY

Convivio helps organisations to work better for people.

We do this mainly by helping them transform their services using digital tools, but also by spreading new ways of working.

Read our blog: blog.weareconvivio.com
Follow us on twitter:
@weareconvivio
Get in touch:
hello@weareconvivio.com
Visit our website at
weareconvivio.com

Managing Microsites with Drupal 8 was originally published in Convivio on Medium, where people are continuing the conversation by highlighting and responding to this story.

SiteDiff - Compare multiple versions of a website

Posted by Evolving Web on January 25, 2017 at 3:00pm
Different houses

Introduction and quick guide to using sitediff - a handy site version comparison tool which helps you detect changes between various versions of a website.

read more

DrupalEasy Podcast 190 - Ted Sings! (Dan Schiavone, Elizabeth Lipinski - DrupalCon Baltimore Sessions)

Posted by DrupalEasy on January 25, 2017 at 1:30pm

Direct .mp3 file download.

Dan Schiavone (schiavone), President, Snake Hill Web Agency, and local lead front end track for DrupalCon Baltimore and Elizabeth Lipinski (lizardata), Technolgy Strategist (also from Snake Hill) and the local lead business track joins Ted and Mike to discuss session submission for DrupalCon Baltimore. We also discuss Media in Core and changes to Drupal marketplace rankings before making our picks of the week!

Interview DrupalEasy News Three Stories Sponsors Picks of the Week Upcoming Events Follow us on Twitter Five Questions (answers only)
  1. Turning conference t-shirts into other things.
  2. Avast (anti-virus software).
  3. Not afraid of anything.
  4. Storks.
  5. Dan was jazzed after DrupalCon DC.
Intro Music Subscribe

Subscribe to our podcast on iTunes, Google Play or Miro. Listen to our podcast on Stitcher.

If you'd like to leave us a voicemail, call 321-396-2340. Please keep in mind that we might play your voicemail during one of our future podcasts. Feel free to call in with suggestions, rants, questions, or corrections. If you'd rather just send us an email, please use our contact page.

Set up a guided tour on Drupal 8

Posted by Flocon de toile | Freelance Drupal on January 25, 2017 at 9:00am

Drupal 8 has a new core module, the Tour module, which allows us to set up a contextual help to guide users of a Drupal 8 site for their first steps on it, whether for the discovery of their user profile, the possibilities offered to them, how to create content or the overall management of the site's contents.

Set up a guided tour on Drupal 8

Posted by Flocon de toile | Freelance Drupal on January 25, 2017 at 9:00am

Drupal 8 has a new core module, the Tour module, which allows us to set up a contextual help to guide users of a Drupal 8 site for their first steps on it, whether for the discovery of their user profile, the possibilities offered to them, how to create content or the overall management of the site's contents.

Benefit Cosmetics Drupal Case Study

Posted by Third & Grove on January 25, 2017 at 8:00am
Benefit Cosmetics Drupal Case Study antonella Wed, 01/25/2017 - 03:00

Pages

Subscribe with RSS Subscribe to Drupal.org aggregator - Planet Drupal