OSTraining: How to Add Audio Files to Drupal 8 Sites

Planet Drupal - Fri, 2016/09/16 - 3:58pm

This week, an OSTraining member asked us about adding audio files to their Drupal 8 site.

Using the Drupal AudioField module, I will explain how you can display a simple HTML5 player for your site's audio files.

In order to get started, you must download, install and enable the AudioField module.

Categories:

OpenLucius: Module release: 'Pop-up question redirect'

Planet Drupal - Fri, 2016/09/16 - 11:54am

The 'Popup question redirect' module allows Drupal site builders to show website visitors a pop-up in which a question can be asked. If the vistor clicks "Yes" they will be redirected to a given webpage.

Categories:

DrupalCon News: Drupal in Ireland - Project 5

Planet Drupal - Fri, 2016/09/16 - 10:00am

As part of our series of showcasing what Drupal is doing in Ireland, we are happy to bring you another awesome online experience that Drupal has created.  

Project 5 - Dún Laoghaire-Rathdown County Council

Monsoon Consulting worked with Dún Laoghaire-Rathdown County Council to build the next generation of DLR websites and internal intranet platform, using Drupal 7 as the content management system. 

Categories:

Danny Englander: Drupal 8 Theming: How to Define Variables in Twig Templates to Use as Custom HTML Classes

Planet Drupal - Fri, 2016/09/16 - 3:06am

For the past seven months, I've been designing, building, and theming with Drupal 8 for my own side project. Along the way, I've seen huge advancements in these realms versus what was possible with Drupal 7. One particular module I've been working with is Entity Construction Kit AKA "ECK".

ECK provides a way to create freestanding entities, bundles, and fields independent of traditional means via nodes, terms, users, etc... Within my project, I've implemented ECK fields that offer content editors options for layouts, colors, element padding, and so on.

Discover the array path with kint

I'll use the case of an accordion group entity that I've designed. One such field within this entity bundle is called "Slice margin." This field allows a content editor to set the top and bottom margins within a specific element by choosing values from a select list. Examining this field with kint, the value of the selected item's array path is:

$var['entity']['field_slice_margin']['0']['#markup'] Check for the field and define the variable

Now with the array path value determined, a variable in the accordion entity can be set in a Twig template:

{% if entity.field_slice_margin|render %} {% set margin_settings = 'margin__' ~ entity.field_slice_margin['0']['#markup'] %} {% endif %}

In the above code, the code checks to be sure the field is being rendered and then a variable is set for the value. In addition, margin__ is concatenated (~) as a class prefix.

Set a class using the variable

The block of code above does not do much on its own, so lets put the new variable to use in the template. For that, Drupal 8's Twig set_classes comes in handy.

{% set classes = [ 'eck', 'eck__section', eck__bundle-accordion, 'margin__default', margin_settings|clean_class, ] %}

Note in the above, the new variable is output using the Drupal Twig clean_class method, margin_settings|clean_class. clean_class cleans up any spaces and underscores in a string and converts those to standard dashes for use as a standard html class name.

Output the HTML with the classes

Now that this is done, the class can be rendered in an HTML element in the same twig template using the attributes.addClass(classes) method:

<section {{ attributes.addClass(classes) }}> <ul class="eck__collapsible collapsible popout" data-collapsible="accordion"> {{ entity.field_accordion_reference|field_value }} </ul> </section> Rendered HTML

Finally, this will render in HTML as:

<section class="eck eck__section margin__default margin__flush-above-below eck__bundle-accordion">

The key class rendered here from entity.field_slice_margin is margin__flush-above-below, that's the specific value the content editor chose from the select list on the node edit page. Now this and other values from this field can be used in theming like so using Sass:

.margin { &__default { margin-bottom: 70px; } &__flush-above { margin-top: 0; } &__flush-below { margin-bottom: 0; } &__flush-above-below { margin-top: 0; margin-bottom: 0; } } Summary

As you can see, Twig is really powerful in Drupal 8. No preprocess functions were used here which really helps streamline theming. We stayed within one Twig template for all of the functions and code above. A lot of possibilities here to give content creators more control over layout, colors, custom classes, and more.

Tags 
  • Drupal
  • Twig
  • Theming
  • Drupal Planet
  • Drupal 8
Resources 
Categories:

Cheeky Monkey Media: More than Websites

Planet Drupal - Thu, 2016/09/15 - 9:17pm
More than Websites chris Thu, 09/15/2016 - 19:17

We have established ourselves as experts in the Drupal and Web development sphere. However, few people are aware that we bring much more to the table. We are a diverse team of creative thinkers, designers, and marketers with the single-minded desire to make your project a success. It takes more than just building a Website these days, so it's important to us that our clients know that engaging with Cheeky Monkey Media can be a full spectrum experience. 

To help illustrate our hidden talents, we put together this quick little reel highlighting just some of the “Other things we do”, things like graphic design, marketing, and SEO.

Categories:

Annertech: Save Money: Security Updates and Web Hosting in One Simple Package

Planet Drupal - Thu, 2016/09/15 - 3:10pm
Save Money: Security Updates and Web Hosting in One Simple Package

Choosing proper hosting for your site shouldn't be a race to the bottom.

Hosting websites is hard. Websites themselves are complex, global traffic can mean huge numbers, big spikes in activity and always demanding users. Sites need to be served quickly, consistently and reliably. Downtime costs money, effort, and more than likely a few extra grey hairs too.

Categories:

Valuebound: What are you giving back to the Community?

Planet Drupal - Thu, 2016/09/15 - 12:33pm

The Drupal Community boasts of having more than a hundred thousand active contributors to this Open Source platform. People around the globe contribute to the codebase and more teaming up together. Businesses nowadays are staying ahead of the competition by encouraging contributions. Everything is about making together and building a better place, if you are not adding value you are already out of the league.

Why should I contribute?

You may be in one of those organizations who agree to disagree with the point above and might ask “Why should I spend my time and resources for something I don’t see value in?” Well, then my friend you should be the first ones to start volunteer contributions with whatever little…

Categories:

Third & Grove: Redirecting Node Pages in Drupal 8

Planet Drupal - Thu, 2016/09/15 - 11:46am
Redirecting Node Pages in Drupal 8 josh Thu, 09/15/2016 - 05:46
Categories:

Kodamera Screencast: Exporting and importing taxonomies

Planet Drupal - Thu, 2016/09/15 - 10:28am

There are many ways of exporting and importing taxonomies and terms in Drupal, but one of the more simpler ways is to use the Taxonomy CSV import/export module. It lets you choose one of many taxonomies, like the tag taxonomy for example, export it to a comma-separated list which you then can import in a similar way.

In this video I'll show you how to do an export from one Drupal installation, in this case a Drupal 6 version (just to show that it's possible to move tags between different Drupal versions as well) and then import it into another Drupal installation (Drupal 7 in this case).

It all starts with the export where you choose which vocabulary/ies you want to export and how you want to format it.

The second stage is to import the CSV-file into your target installation, and I'll show you this as well. 

The module has Drush support as well, so if you use Drush much you might want to use the terminal for your export and import.


Read more
Categories:

DrupalCon News: Drupal in Ireland - Project 4

Planet Drupal - Thu, 2016/09/15 - 10:00am

As part of our series of showcasing what Drupal is doing in Ireland, we are happy to bring you another awesome online experience that Drupal has created.  

Project 4 - Lámh

Lámh is a manual sign systems used by children and adults with intellectual disability and communication needs in Ireland. Lámh signs are used to support communication - they act as a stepping stone to communicating with the world. 

Categories:

DrupalEasy: DrupalEasy Podcast 185 - Amigurumi Long Beans (Ted Bowman - D8 Outside-In)

Planet Drupal - Thu, 2016/09/15 - 8:52am

Direct .mp3 file download.

Ted Bowman (tedbow) gets promoted from a lowly podcast co-host to special guest on this very special episode of the DrupalEasy Podcast. Ted has been working on the Drupal "Outside In" initiative(?), and shares his knowledge on the project. Anna Kalata and Ryan Price join Mike Anello to also discuss Drupal Association changes, new coding standards, giraffes, and manatees.

Interview DrupalEasy News Three Stories
  1. MarCom changes, and how we'll keep moving forward - blog post by Bradley Fields and Changes for the Drupal Association Events Team - blog post by Rachel Friesen.
  2. Documentation overhaul - blog post by tvn.
  3. Coding standards - blog post by Howard Tyson.
Sponsors Picks of the Week Upcoming Events Follow us on Twitter Five Questions (answers only)
  1. Paddleboarding.
  2. Dick's TSHQ.
  3. Pay for kids' college.
  4. Giraffe.
  5. First Orlando meetups.
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.

Categories:

Unimity Solutions Drupal Blog: Video Annotations in Drupal 8

Planet Drupal - Thu, 2016/09/15 - 7:29am

Our first blog Video Annotations: A Powerful and Innovative Tool for Education explained power of videos in education when combined with features like video annotation and second blog Identification of an Open Source Video Annotations Tool for NVLI listed evaluation criteria of open annotation module that assisted NVLI project. This third blog in the series will involve defining the overall architecture of the Video Annotation solution in Drupal.

Categories:

Hook 42: Drupal 8 multilingual websites training at BADCamp by Hook 42 and Lingotek

Planet Drupal - Wed, 2016/09/14 - 11:18pm

Hook 42 has run four Drupal multilingual trainings at BADCamp since 2012, which has been a lot of fun. The first three years were focused on Drupal 7 only, and last year our training was split between Drupal 7 and Drupal 8. At all of these trainings, we had the great fortune of having the Lingotek team help us mentor students during the self-paced training as well as give a quick peek at their translation software.

Categories:

Gizra.com: Creating a Dynamic Email Template in Drupal

Planet Drupal - Wed, 2016/09/14 - 11:00pm

Creating a plain text email with Drupal is a simple task. However, when you want to send a nicely designed message with a logo, an article, a linked button or any other unique design with dynamic content personalized for each user, it can get complicated.

The complication stems not from the dynamic content, but rather from the fact that the CSS that can be applied inside email templates is limited. In general, targeting multiple email clients can be worse then getting your CSS to work on IE9!

This post will walk you through a solution we use to address these requirements, but before jumping in, let me first explain Gizra’s approach to themes. We don’t use custom CSS in Drupal themes. When we start building a website, we divide our work into several milestones, the first is creating a clean and static markup, using Jekyll. At Gizra, we take pixel perfect very seriously, and by doing the markup first, we can concentrate on building our App pages exactly the way they are suppose to look, test their responsiveness, show our clients a first draft, and fix bugs before getting into the logic. We use gulp to compile the SASS files into one CSS file, and after doing that, we copy the CSS file to the themes folder. Then we take our static pages, cut them into pieces, and use them in Drupal themes and plugins.

By doing this, we can focus on our logic without worrying about how it may look with different dynamic content. Focusing on Frontend and Backend as separate tasks makes building websites easier and faster. Even fixing bugs discovered while implementing dynamic content can now be easily fixed. Our No more CSS in your Drupal Theme! blog post talks more extensively about the way we work with Drupal themes.

The same approach is implemented when we create an email template. We first build the email markup with static content, and then we use it to create dynamic content messages. Oh, and we cheat, because we don’t write a single line of HTML or CSS!

A demo email template created for this post

Continue reading…

Categories:

Dries Buytaert: Can Drupal outdo native applications?

Planet Drupal - Wed, 2016/09/14 - 8:54pm

I've made no secret of my interest in the open web, so it won't come as a surprise that I'd love to see more web applications and fewer native applications. Nonetheless, many argue that "the future of the internet isn't the web" and that it's only a matter of time before walled gardens like Facebook and Google — and the native applications which serve as their gatekeepers — overwhelm the web as we know it today: a public, inclusive, and decentralized common good.

I'm not convinced. Native applications seem to be winning because they offer a better user experience. So the question is: can open web applications, like those powered by Drupal, ever match up to the user experience exemplified by native applications? In this blog post, I want to describe inversion of control, a technique now common in web applications and that could benefit Drupal's own user experience.

Native applications versus web applications

Using a native application — for the first time — is usually a high-friction, low-performance experience because you need to download, install, and open the application (Android's streamed apps notwithstanding). Once installed, native applications offer unique access to smartphone capabilities such as hardware APIs (e.g. microphone, GPS, fingerprint sensors, camera), events such as push notifications, and gestures such as swipes and pinch-and-zoom. Unfortunately, most of these don't have corresponding APIs for web applications.

A web application, on the other hand, is a low-friction experience upon opening it for the first time. While native applications can require a large amount of time to download initially, web applications usually don't have to be installed and launched. Nevertheless, web applications do incur the constraint of low performance when there is significant code weight or dozens of assets that have to be downloaded from the server. As such, one of the unique challenges facing web applications today is how to emulate a native user experience without the drawbacks that come with a closed, opaque, and proprietary ecosystem.

Inversion of control

In the spirit of open source, the Drupal Association invited experts from the wider front-end community to speak at DrupalCon New Orleans, including from Ember and Angular. Ed Faulkner, a member of the Ember core team and contributor to the API-first initiative, delivered a fascinating presentation about how Drupal and Ember working in tandem can enrich the user experience.

One of Ember's primary objectives is to demonstrate how web applications can be indistinguishable from native applications. And one of the key ideas of JavaScript frameworks like Ember is inversion of control, in which the client side essentially "takes over" from the server side by driving requirements and initiating actions. In the traditional page delivery model, the server is in charge, and the end user has to wait for the next page to be delivered and rendered through a page refresh. With inversion of control, the client is in charge, which enables fluid transitions from one place in the web application to another, just like native applications.

Before the advent of JavaScript and AJAX, distinct states in web applications could be defined only on the server side as individual pages and requested and transmitted via a round trip to the server, i.e. a full page refresh. Today, the client can retrieve application states asynchronously rather than depending on the server for a completely new page load. This improves perceived performance. I discuss the history of this trend in more detail in this blog post.

Through inversion of control, JavaScript frameworks like Ember provide much more than seamless interactions and perceived performance enhancements; they also offer client-side storage and offline functionality when the client has no access to the server. As a result, inversion of control opens a door to other features requiring the empowerment of the client beyond just client-driven interactions. In fact, because the JavaScript code is run on a client such as a smartphone rather than on the server, it would be well-positioned to access other hardware APIs, like near-field communication, as web APIs become available.

Inversion of control in end user experiences When a user clicks a teaser image on the homepage of an Ember-enhanced Drupal.com, the page seamlessly transitions into the full content page for that teaser, with the teaser image as a reference point, even though the URL changes.

In response to our recent evaluation of JavaScript frameworks and their compatibility with Drupal, Ed applied the inversion of control principle to Drupal.com using Ember. Ed's goal was to enhance Drupal.com's end user experience with Ember to make it more application-like, while also preserving Drupal's editorial and rendering capabilities as much as possible.

Ed's changes are not in production on Drupal.com, but in his demo, clicking a teaser image causes it to "explode" to become the hero image of the destination page. Pairing Ember with Drupal in this way allows a user to visually and mentally transition from a piece of teaser content to its corresponding page via an animated transition between pages — all without a page refresh. The animation is very impressive and the animated GIF above doesn't do it full justice. While this transition across pages is similar to behavior found in native mobile applications, it's not currently possible out of the box in Drupal without extensive client-side control.

Rather than the progressively decoupled approach, which embeds JavaScript-driven components into a Drupal-rendered page, Ed's implementation inverts control by allowing Ember to render what is emitted by Drupal. Ember maintains control over how URLs are loaded in the browser by controlling URLs under its responsibility; take a look at Ed's DrupalCon presentation to better understand how Drupal and Ember interact in this model.

These impressive interactions are possible using the Ember plugin Liquid Fire. Fewer than 20 lines of code were needed to build the animations in Ed's demo, much like how SDKs for native mobile applications provide easy-to-implement animations out of the box. Of course, Ember isn't the only tool capable of this kind of functionality. The RefreshLess module for Drupal by Wim Leers (Acquia) also uses client-side control to enable navigating across pages with minimal server requests. Unfortunately, RefreshLess can't tap into Liquid Fire or other Ember plugins.

Inversion of control in editorial experiences In CardStack Editor, an editorial interface with transitions and animations is superimposed onto the content page in a manner similar to outside-in, and the editor benefits from an in-context, in-preview experience that updates in real time.

We can apply this principle of inversion of control not only to the end user experience but also to editorial experiences. The last demos in Ed's presentation depict CardStack Editor, a fully decoupled Ember application that uses inversion of control to overlay an administrative interface to edit Drupal content, much like in-place editing.

CardStack Editor communicates with Drupal's web services in order to retrieve and manipulate content to be edited, and in this example Drupal serves solely as a central content repository. This is why the API-first initiative is so important; it enables developers to use JavaScript frameworks to build application-like experiences on top of and backed by Drupal. And with the help of SDKs like Waterwheel.js (a native JavaScript library for interacting with Drupal's REST API), Drupal can become a preferred choice for JavaScript developers.

Inversion of control as the rule or exception?

Those of you following the outside-in work might have noticed some striking similarities between outside-in and the work Ed has been doing: both use inversion of control. The primary purpose of our outside-in interfaces is to provide for an in-context editing experience in which state changes take effect live before your eyes; hence the need for inversion of control.

Thinking about the future, we have to answer the following question: does Drupal want inversion of control to be the rule or the exception? We don't have to answer that question today or tomorrow, but at some point we should.

If the answer to that question is "the rule", we should consider embracing a JavaScript framework like Ember. The constellation of tools we have in jQuery, Backbone, and the Drupal AJAX framework makes using inversion of control much harder to implement than it could be. With a JavaScript framework like Ember as a standard, implementation could accelerate by becoming considerably easier. That said, there are many other factors to consider, including the costs of developing and hosting two codebases in different languages.

In the longer term, client-side frameworks like Ember will allow us to build web applications which compete with and even exceed native applications with regard to perceived performance, built-in interactions, and a better developer experience. But these frameworks will also enrich interactions between web applications and device hardware, potentially allowing them to react to pinch-and-zoom, issue native push notifications, and even interact with lower-level devices.

In the meantime, I maintain my recommendation of (1) progressive decoupling as a means to begin exploring inversion of control and (2) a continued focus on the API-first initiative to enable application-like experiences to be developed on Drupal.

Conclusion

I'm hopeful Drupal can exemplify how the open web will ultimately succeed over native applications and walled gardens. Through the API-first initiative, Drupal will provide the underpinnings for web and native applications. But is it enough?

Inversion of control is an important principle that we can apply to Drupal to improve how we power our user interactions and build robust experiences for end users and editors that rival native applications. Doing so will enable us to enhance our user experience long into the future in ways that we may not even be able to think of now. I encourage the community to experiment with these ideas around inversion of control and consider how we can apply them to Drupal.

Special thanks to Preston So for contributions to this blog post and to Angie Byron, Wim Leers, Kevin O'Leary, Matt Grill, and Ted Bowman for their feedback during its writing.

Categories:

DrupalEasy: Using Panels to Override Existing Pages in Drupal 8

Planet Drupal - Wed, 2016/09/14 - 7:34pm

While working with one of our project coaching (see below for details) clients recently, I was asked to show their developer how to override the default user profile display page with a custom Panels layout.

In Drupal 8, the process a bit different than in Drupal 7, but the main concepts are the same. We want to use the Page Manager module to override a particular existing system path ("user/{uid}", for example), then create a variant that uses Panels as the builder. The custom layout is created (quite easily) using the Layout Plugin module.

If you were just creating a standard landing page (and not overriding an existing system path), you'd have all you need at this point, just place blocks in the Panel and you're done. But, when you're overriding something like the user display page (or a node display page), you're probably going to want to place fields attached to the user entity in the panel as well. There's a couple of steps required to make this happen.

First, you'll need to create a new panel context for the entity whose display you're looking to override. This was something that was provided by default in Drupal 7.

Second - and this is where the non-obvious solution comes in - there's another module that must be enabled to get access to the fields. The "Chaos Tools Blocks" module (obviously, part of the Chaos Tools module provides each of the entity's fields as blocks. So, when you are adding content to the panel, all of the entity's fields are available through the "Add block" button.

As mentioned previously, we offer project coaching to clients as a way of guiding and training developers on the organization's own projects. Rather than a traditional training course where most of the curriculum is pre-determined, our project coaching clients receive customized training and best-practice guidance during the development phase of their projects on an as-needed basis. This allows the organization's developers to build sites with confidence knowing that they're getting a solid foundation while they're still in the learning phase of their Drupal journey. Contact us for more information.

Categories:

EchoDitto Tech Blog: What to Know Before You Host a Drupal 8 Site

Planet Drupal - Wed, 2016/09/14 - 5:55pm

We’ve really been enjoying working with Drupal 8 so far, and as Peter wrote about previously, there are some big improvements that make the investment worthwhile. But your beautiful design and carefully crafted content doesn’t mean a thing if your website doesn’t perform well — especially when we know that improving page load times by just a second has a meaningful impact on bounce rates and attention from visitors.

So while hosting a Drupal 8 site is not entirely different than Drupal 7, there are a few differences and we thought it would be helpful to share a few of the lessons we’ve learned about hosting Drupal 8 websites so far.

Be prepared to update Drupal 8’s core more frequently

The reality for any major software release is that not everything gets done in version 1.0. Or, in this case, 8.0. There are bugs to fix, occasional features to add, compatibility with other systems, etc. That’s why after any major software release you can expect updates—especially on the bug front—to come more frequently than for software that’s matured over years.

These issues are exacerbated on a system like Drupal 8 where the architecture has been rebuilt and there exists a large number of modules provided by such a large community. Although we expect the pace of updates will gradually slow down to where Drupal 7 is today, you should expect that Drupal 8 core will receive frequent updates at least over the next year. If you do your own updates or pay hourly for the service, you should expect to budget a little more, either in time or money, to perform this maintenance.

Note: If you host your site with Echo, have no fear. At Echo, we offer concierge hosting which, in addition to standard hosting services like backups and monitoring, includes security updates to Drupal core as well as your modules.

Look beyond the basic system requirements

As with any piece of software, Drupal 8 has some basic system requirements. But, if you want to make sure you’ve set your site up to run as smoothly as possible and to cause as few issues as possible when it comes to fixing things, we have a little advice: use PHP 5.6.

There are a few reasons. First, PHP 5.5 has already reached its end of life. Then, there’s the boost to performance and stability your Drupal 8 site will have. Lastly, paired with the requirement to use DRUSH 8, when managing a Drupal 8 site, PHP 5.6 provides the best cross support between the two.

What’s next?

As with the versions before it, Drupal 8 will continue to evolve over the coming years, and as it does we’ll be here to guide you through it. If you have any questions about Drupal 8, get in touch and we may just cover it here.

Tags: drupaldrupal 8hostingdrush
Categories:

clemens-tolboom opened issue docker-library/drupal#56

On github - Wed, 2016/09/14 - 5:11pm
Sep 14, 2016 clemens-tolboom opened issue docker-library/drupal#56 Make this work similar as WordPress using docker-compose

SystemSeed: How UNC achieved a multi-site search using Feeds and SearchAPI

Planet Drupal - Wed, 2016/09/14 - 10:08am

Handling clients with more than one site involves lots of decisions. And yet, it can sometimes seem like ultimately all that doesn’t matter a hill of beans to the end-user, the site visitor. They won’t care whether you use Domain module, multi-site, separate sites with common codebase, and so on. Because most people don’t notice what’s in their URL bar. They want ease of login, and ease of navigation. That translates into things such as the single sign-on that drupal.org uses, and common menus and headers, and also site search: they don’t care that it’s actually sites search, plural, they just want to find stuff.

For the University of North Carolina, who have a network of sites running on a range of different platforms, a unified search system was a key way of giving visitors the experience of a cohesive whole. The hub site, an existing Drupal 7 installation, needed to provide search results from across the whole family of sites.

This presented a few challenges. Naturally, we turned to Apache Solr. Hitherto, I’ve always considered Solr to be some sort of black magic, from the way in which it requires its own separate server (http not good enough for you?) to the mysteries of its configuration (both Drupal modules that integrate with it require you to dump a bunch of configuration files into your Solr installation). But Solr excels at what it sets out to do, and the Drupal modules around it are now mature enough that things just work out of the box. Even better, Search API module allows you to plug in a different search back-end, so you can develop locally using Drupal’s own database as your search provider, with the intention of plugging it all into Solr when you deploy to servers.

One possible setup would have been to have the various sites each send their data into Solr directly. However, with the Pantheon platform this didn’t look to be possible: in order to achieve close integration between Drupal and Solr, Pantheon locks down your Solr instance.  That left talking to Solr via Drupal.

SearchAPI lets you define different datasources for your search data, and comes with one for each entity type on your site. In a datasource handler class, you can define how the datasource gets a list of IDs of things to index, and how it gets the content. So writing a custom datasource was one possibility.

Enter the next problem: the external sites we needed to index only exposed their content to us in one format: RSS. In theory, you could have a Search API datasource which pulls in data from an RSS feed. But then you need to write a SearchAPI datasource class which knows how to parse RSS and extract the fields from it.  That sounded like we’d be reinventing Feeds, so we turned to that to see what we could do with it. Feeds normally saves data into Drupal entities, but maybe (we thought) there was a way to have the data be passed into SearchAPI for indexing, by writing a custom Feeds plugin?  However, we found we had a funny problem of the sort that you don’t consider the existence of until you stumble on it: Feeds works on cron runs, pulling in data from a remote source and saving it into Drupal somehow. But SearchAPI also works on cron runs, pulling data in, usually entities. How do you get two processes to communicate when they both want to be the active participant?

With time pressing, we took the simple option: we defined a custom entity type for Feeds to put its data into, and SearchAPI to read its data from. (We could have just used a node type, but then there would have been an ongoing burden of needing to ensure that type was excluded from any kind of interaction with nodes.)

Essentially, this custom entity type acted like a bucket: Feeds dumps data in, SearchAPI picks data out. As solutions go, not the most massively elegant, at first glance. But if you think about it, if we had gone down the route of SearchAPI fetching from RSS directly, then re-indexing would have been a really lengthy process, and could have had consequences for the performance of the sites whose content was being slurped up. A sensible approach would then have been to implement some sort of caching on our server, either of the RSS feeds as files, or the processed RSS data. And suddenly our custom entity bucket system doesn’t look so inelegant after all: it’s basically a cache that both Feeds and SearchAPI can talk to easily.

There were a few pitfalls. With Search API, our search index needed to work on two entity types (nodes and the custom bucket entities), and while Search API on Drupal 7 allows this, its multiple entity type datasource handler had a few issues we needed to iron out or learn to live with.

The good news though is that the Drupal 8 version of Search API has the concept of multi-entity type search indexes at its core, rather than as a side feature: every index can handle multiple entity types, and there’s no such thing as a datasource for a single entity type.  With Feeds, we found that not all the configuration is exportable to Features for easy deployment. Everything about parsing the RSS feed into entities can be exported, except the actual URL, which is a separate piece of setup and not exportable. So we had to add a hook_updateN() to take care of setting that up.

The end result though was a site search that seamlessly returns results from multiple sites, allowing users to work with a network of disparate sites built on different technologies as if they were all the same thing. Which is what they were probably thinking they were all along anyway.

Author: Joachim Noreiko

Categories:

DrupalCon News: Drupal in Ireland - Project 3

Planet Drupal - Wed, 2016/09/14 - 10:00am

As part of our series of showcasing what Drupal is doing in Ireland, we are happy to bring you another awesome online experience that Drupal has created.  

Categories: