Skip to Content

Drupal

Drop Guard: Drop Guard recipes: Configure your Drupal update behaviours

Planet Drupal - 15 April 2016 - 11:15am
Drop Guard recipes: Configure your Drupal update behaviours Igor Kandyba Fri, 15.04.2016 - 20:15

The real benefits and value of Drop Guard are not about being able to monitor, but actually perform updates by committing the newer Drupal and modules versions directly into the project's Git repository. In this article, we'll familiarise ourselves with the basic Drop Guard concepts, and go through the update behaviours configuration process to secure our website.

Drop Guard Drop Guard recipes Drupal Planet
Categories: Drupal

The Cherry Hill Company: Join us for the Drupal in Libraries BoF at DrupalCon NOLA

Planet Drupal - 15 April 2016 - 10:34am

This year's Drupal in Libraries Birds of a Feather session will be on Wednesday, May 11th from 3:45 to 4:45 in the Cherry Hill BoF Room (291) at the Morial Convention Center.

There is no agenda, so please bring your questions and stories. We would all love to see what you have been up to.

Among the things that we are interested in are the upcoming version of Islandora and summer reading programs.

Categories: Drupal

Phponwebsites: Login using email and username in Drupal 7

Planet Drupal - 15 April 2016 - 10:31am
   This blog describes about how to login using both email and username in Drupal 7. All of you know we could login using only username in Drupal 7.



       I've tried to login using email without any contrib modules. Finally i got the code. First alter form to add custom form validation. In custom form validation, get the name from user table by email and set that value into name field in form.  Let see the code:

<?php
/**
 * Implement hook_form_alter().
 */
function phponwebsites_form_alter(&$form, &$form_state, $form_id) {

  if ($form_id == "user_login" || $form_id == "user_login_block") {
    $form['name']['#title'] = t('Username or E-mail Address');
    // Ensure a valid validate array.
    $form['#validate'] = is_array($form['#validate']) ? $form['#validate'] : array();
    // login using username or email address
    array_unshift($form['#validate'],'phponwebsites_user_login_validate');
  }
}

 /**
 * Implement phponwebsites_user_login_validate()
 *
 * Return name by its email address
 */
function phponwebsites_user_login_validate($form, &$form_state) {
  if (isset($form_state['values']['name']) && strpos($form_state['values']['name'], '@') !== false) {
      $name = db_query("SELECT name FROM {users} WHERE LOWER(mail) = LOWER(:name)", array(':name' => $form_state['values']['name']))->fetchField();
    }
  if (isset($name)) {
    form_set_value($form['name'], $name, $form_state);
  }
}
   Now you can login using both username and email. I've hope you know how to login using both username and email in Drupal 7.
Categories: Drupal

Acquia Developer Center Blog: How Laura moved from Sales to Tech - a Drupal story

Planet Drupal - 15 April 2016 - 9:14am

Laura Caraker's journey at Acquia is remarkable. In this podcast, she and I talk through how she joined Acquia Sales, wanted to know more about Drupal and ended up joining the technical side of the house via her stint at Acquia U, Acquia's Drupal and tech boot camp. Her advice for others interested in technology? "Don’t be afraid to get involved."

Interview video - 12' 30"

Early days: Acquia Sales

jam: So why don’t you introduce yourself? Tell us who you are and what you do now.

Laura Caraker: Sure. So my name is Laura Caraker. I am currently on the Solutions Architecture Team as an associate solutions architect. I have been here for a little bit over two years now.

jam: I remember meeting you in Acquia’s old office a couple of times because your desk was positioned in a place that I would always walk through the office, and you and your deskmate at that time seem to be having far too much fun.

Laura Caraker: Yes. Yes, we really did and it was a great place to sit too because I could see everybody coming through. So it was nice.

jam: What was your job back then?

Laura Caraker: I was a business development representative. I think that was close to when I first started. I remember you were wearing your mustache suit, full mustache suit.

jam: Well, I mean, I have to keep up appearances, right?

Laura Caraker: Yes, of course.

jam: Now, what does a BDR do, a business development representative?

Laura Caraker: So a BDR is an entry-level sales position within the company. So, it’s generally for people right out of college or looking to jumpstart their career. If they’re looking into the business side that’s the first-level role they would take.

Love at first DrupalCon

jam: But Laura, that’s a sales job and now you’re doing a Drupal job! :-) So this actually totally fascinated me. So here’s what I observed that really truly captivated me. I met Laura in this entry-level sales position and then at DrupalCon Portland, I ran into you.

Laura Caraker: Austin.

jam: Was it Austin?

Laura Caraker: Austin.

jam: At a DrupalCon I ran into you and I said, “Wow! You’re here!” because that’s – at a large company like we are, I thought it was a little bit unusual that a junior salesperson would be at DrupalCon. I said, “What are you doing here?” And you said, “We won this, you know? We made this number and our prize was to come to DrupalCon,” and I asked you about it. And how was your first DrupalCon?

Laura Caraker: I loved it. It was also my first time in Austin, so that contributed to the positive experience too, but it was great having been here for just a few months at that point to go do a community event like that with coworkers you don’t usually talk to and see the community itself as well.

jam: What was your tech experience before you came to Acquia?

Laura Caraker: Slim to none. I know very basic or I knew very basic coding like HTML. It was more of a hobby. I had a WordPress blog before coming here so – but not far beyond that.

jam: Do you have a first Drupal memory?

Laura Caraker: Probably DrupalCon itself was the most prevalent Drupal memory itself. With the actual technology, the first time I used Drupal was Drupal Gardens.

Teach me all the Drupal!

jam: Okay. So what I’ve observed is you came in as a salesperson. You got excited about this thing and you’re now in a technical job. Of course, the piece in between that somehow was Acquia U, but describe working in this organization and what happened along the way, how your – what caught your attention, what got you excited.

Laura Caraker: Sure. So I’d say what got me the most excited about working here was the people. So you always want to perform very well because you enjoy the people that you’re working with and you want to work hard for them. But every day in sales I found myself on phone conversations, talking to people about Drupal and our products, but never fully understanding it to the level I wanted to, to have the confidence to really sell it, and since I was always sort of fascinated by technology in general, I wanted to learn more. So I was in that role or moving along that team for a year and a half-ish, and then I had always been interested in Acquia U and the idea behind it, but there hadn’t really been anybody internally that had wanted to do it, and when I saw that the prerequisites weren’t too demanding, I reached out to Amy and asked what she thought about it, and I talked to my boss, and then everything kind of came together.

jam: Wow! So, describe how it was going through the curriculum and getting up to speed on PHP, and version control, and Agile, and all this stuff.

Laura Caraker: Very difficult. It was difficult too because I started with a group of maybe eight to nine other people and they all had different levels of experience. Some of the kids had coded for a while just using different programs. But generally, around the room, not many of us knew Drupal very well. So that was a little less intimidating. It was definitely difficult to learn everything at once and try and put it all together, to understand what it all means together in workflow and things like that, but I made it through. I survived. I’m still learning every day.

jam: Is it fair to describe it is a boot camp?

Laura Caraker: Yes. Like a boot camp classroom, basically.

jam: What sort of – well, you’re in a technical role now at Acquia in the solutions architecture team which enables people to design their projects right, to succeed at them?

Laura Caraker: Yes.

Baking it all in

jam: What sort of career doors do you think Acquia U has opened for you?

Laura Caraker: Well, initially, my first intention was to go to Acquia U to enable me more as a sales rep. The initial plan was to come right back to the sales team. So around the end of that program, I was starting to get a feel for other departments. So right then and there that opened the opportunity to join the solutions architecture team. I had other opportunities too. It was very flexible now having the Drupal knowledge and Acquia knowledge of where you can go. So, I really liked all the different opportunities I had and the solutions architecture opportunity was the most attractive to me because it combined skills that I had already gained in sales with the new skills I had, and I knew that if I went right back to sales, I may not exercise all the new skills I was learning. So I was nervous to lose them and I wanted to actually work with them every day so...

jam: So you got – you’re baking them in now?

Laura Caraker: Yes.

jam: Right, and you’re making a broader base really, and using it every day is, of course, the best way to really make it stick?

Laura Caraker: Yes.

Biz background with tech skills - the future is bright!

jam: I see that. What was your major at college?

Laura Caraker: Sport management.

jam: Okay, but management, right?

Laura Caraker: Yes, I was in a business school.

jam: You did a business-y thing at the business school and now you’ve got all of these technical skills, and your role is actually right in between those two worlds...

Laura Caraker: Yes.

jam: ...because, essentially, you need to take business require – figure out what the business requirements are which is a set of skills, in and of itself, that’s quite tricky, and then express those in a technical architecture with our specific technology. That’s actually really exciting because I think that you’ve got an enormously – a growing and very complementary skillset that’s going to make all sorts of things possible in the future.

Laura Caraker: Right.

jam: What’s your first startup going to be then?

Laura Caraker: Oh, I have no idea. I haven’t thought that far yet.

jam: I mean in one possible set of outcomes, right? This is actually an ideal position to be like a technical founder or co-founder of something that’s wow!

Laura Caraker: Tom Erickson started as a presales guy.

jam: Career path "Tom Erickson"!

jam: No - so what I love about this is that you went from sports business background into selling and our crazy technical thing caught your eye, right? And you went for that.

Laura Caraker: Yes, and I actually did minor in IT in school in addition to the whole sport management business thing but it was pretty basic level, just binary, basic computer IT thing. So, it’s cool how both of them combined into this role, a few years later, where I am.

"Don’t be afraid to get involved."

jam: It is tremendously exciting and I want to point out that Drupal and technology today, despite how complicated things are - complex things are, and how many systems and how much there is in today’s web and digital technologies. There are enormous possibilities for people to come in. Self-taught, university-taught, you can go to boot camps. You can read books. You can really – talk about people who are – say something to the people out there who are not sure they’re doing the right thing, and talk about the chances that you see in technology today.

Laura Caraker: Well, I mean in terms of technology, there are a lot of chances. Drupal specifically? I’d say out of the different technologies I’ve seen, it’s one of the – it definitely has a learning curve, but it’s one of the easiest ones to get involved with because of how vast the community is, and all the resources that are available. So this entire journey has been a huge learning experience for me, but I’ve never had an issue finding help, whether it be with an Acquia or within the Drupal community itself.

jam: Very good.

Laura Caraker: So don’t be afraid to get involved.

jam: Don’t be afraid to get involved. That’s really cool. When are you giving your first DrupalCon session?

Laura Caraker: Someday I will. I’ve actually been doing a lot of Drupal camps, gearing up and potentially preparing some sessions here and there, demos. I’ll be doing something at DrupalCon this year hopefully. We’ll see. Nothing – maybe not a session yet, but that’s the goal one day.

jam: Awesome. But you’re definitely out there engaging with the community, showing people how to use stuff. Wow, fantastic! So thank you. So you’re passing it on straightaway as well?

Laura Caraker: Yes.

jam: I find your story so exciting. It’s really – congratulations.

Laura Caraker: Thank you.

jam: It just seems it’s incredibly – it’s exciting. I’m excited for you. I hope you’re...

Laura Caraker: Yes, I’m pumped. I feel very, very lucky to have the opportunities that I’ve had here at Acquia and with Drupal in general. So it’s very exciting.

jam: Welcome to our community.

Laura Caraker: Thank you. I love it.

jam: Thanks for taking the time.

Laura Caraker: Yes, no problem. Thanks, jam.

Guest dossier
Skill Level: BeginnerIntermediateAdvanced
Categories: Drupal

Evolving Web: Upgrading to Drupal 8: Benefits and Gotchas

Planet Drupal - 15 April 2016 - 8:32am

Thinking of upgrading your website to Drupal 8, or using it for the first time on a new project? You've surely heard about the shiny new features that the community has been cooking up. But as with any major step forward, there's a lot of changes to how things work, and not everything is fully ready, so there are challenges to be aware of before you jump into a Drupal 8 project for the first time.

read more
Categories: Drupal

Pronovix: Drupal 8 as a help center: embed documentation with the WalkHub Help Widget

Planet Drupal - 15 April 2016 - 8:20am

Even though it has become much easier to create embedded help experiences, many software products still do very little to integrate their help content into their application. In this post we will explain why embedded help leads to better experiences, why we built our Help Widget, and give you an overview of its architecture.

Categories: Drupal

Migrate views

New Drupal Modules - 15 April 2016 - 8:07am

This module is meant to be developed as upgrade path from d6/d7 views to d8

Categories: Drupal

InternetDevels: Drupal Global Training Days: the 4-part sequel by InternetDevels and Drudesk!

Planet Drupal - 15 April 2016 - 6:31am

Of course, InternetDevels Drupal development company and
 
Drudesk support service couldn’t miss Drupal Global Training
 
Days. And we bet you don’t want to miss reading more about it ;)

Read more
Categories: Drupal

Mediacurrent: Friday 5: 5 Tips to Building a Creative Team

Planet Drupal - 15 April 2016 - 6:18am

We made it to the finish line of another busy work week!

Thanks for joining us for the sixth episode of The Mediacurrent Friday 5. This week, Creative Director Dante Taylor provides 5 Tips to Building a Creative Team. 

He discusses some key points to consider when working with a creative team. Watch the video to learn more about how there are no rules, putting people first, giving sandwich critiques, always keeping your door open, and trusting your teammates.

Categories: Drupal

Migrate Reports

New Drupal Modules - 15 April 2016 - 2:57am

Provides reports for all migrations in the system.

Categories: Drupal

TimOnWeb.com: JQuery.cookie in Drupal 7

Planet Drupal - 15 April 2016 - 1:26am

A quick tip for all Drupalistas outhere: if you want to use jQuery.cookie in your project, you actually don't have to download and install the library. jQuery.cookie is a part of Drupal 7 and can be included as easy as typing: 

  1. drupal_add_library('system', 'jquery.cookie');

Wondering to ...

Read now

Categories: Drupal

Wunderkraut Belgium: Drupal 8 will be released on November 19

Planet Drupal - 15 April 2016 - 1:26am
We're ready to celebrate and build (even more) amazing Drupal 8 websites.  On November 19 we'll put our Drupal 8 websites in the spotlight...be sure to come back and check out our website.
Categories: Drupal

Wunderkraut Belgium: 77 of us are going

Planet Drupal - 15 April 2016 - 1:26am
People from across the globe who use, develop, design and support the Drupal platform will be brought together during a full week dedicated to networking, Drupal 8 and sharing and growing Drupal skills. As we have active hiring plans we’ve decided that this year’s approach should have a focus on meeting people who might want to work for Wunderkraut and getting Drupal 8 out into the world. As Signature Supporting Partner we wanted as much people as possible to attend the event. We managed to get 77 Wunderkrauts on the plane to Barcelona!  From Belgium alone we have an attendance of 17 people. The majority of our developers will be participating in sprints (a get-together for focused development work on a Drupal project) giving all they got together with all other contributors at DrupalCon. We look forward to an active DrupalCon week.   If you're at DrupalCon and feel like talking to us. Just look for the folks with Wunderkraut carrot t-shirts or give Jo a call at his cell phone +32 476 945 176.
Categories: Drupal

Wunderkraut Belgium: Open Monumentendag

Planet Drupal - 15 April 2016 - 1:26am
Once again Heritage day was a huge succes. About 400 000 visitors visited Flanders monuments and heritage sites last Sunday.  The Open Monumentendag website received more than double the amount of last year's visitors. Visitors to the website organised their day out by using the powerful search tool we built that allowed them to search for activities and sights at their desired location.  Not only could they search by location (province, zip code, city name, km range) but also by activity type, keywords, category and accessibility.  Each search request being added as a (removable) filter for finding the perfect activity. By clicking on the heart icon, next to each activity, a favorite list was drawn up.  Ready for printing and taking along as route map. Our support team monitored the website making sure visitors had a great digital experience for a good start to the day's activities. Did you experience the ease of use of the Open Monumentendag website?  Are you curious about the know-how we applied for this project?  Read our Open Monumentendag case.  
Categories: Drupal

Wunderkraut Belgium: Very proud to be a part of it

Planet Drupal - 15 April 2016 - 1:26am
Drupal Association Executive Director Holly Ross is thrilled that Wunderkraut is joining as first and says: "Their support for the Association and the project is, and has always been, top-notch. This is another great expression of how much Wunderkraut believes in the incredible work our community does." As Drupal Signature Supporting Partner we commit ourselves to advancing the Drupal project and empowering the Drupal community.  We're very proud to be a part of it as we enjoy contributing to the Drupal ecosystem (especially when we can be quircky and fun as CEO Vesa Palmu states). Our contribution allowed the Drupal Association to: Complete Drupal.org's D7 upgrade - now they can enhance new features Hired a full engineering team committed to improving Drupal.org infrastructure Set the roadmap for Drupal.org success.
Categories: Drupal

Wunderkraut Belgium: Adapting solutions based on client input

Planet Drupal - 15 April 2016 - 1:26am
But in this post I'd like to talk about one of the disadvantages that here at Wunderkraut we pay close attention to. A consequence of the ability to build features in more than one way is that it's difficult to predict how different people interact (or want to interact) with them. As a result, companies end up delivering solutions to their clients that although seem perfect, turn out, in time, to be less than ideal and sometimes outright counterproductive.  Great communication with the client and interest in their problems goes a long way towards minimising this effect. But sometimes clients realise that certain implementations are not perfect and could be made better. And when that happens, we are there to listen, adapt and reshape future solutions by taking into account these experiences.  One such recent example involved the use of a certain WYSIWYG library from our toolkit on a client website. Content editors were initially happy with the implementation before they actually started using it to the full extent. Problems began to emerge, leading to editors spending way more time than they should have performing editing tasks. The client signalled this problem to us which we then proceed to correct by replacing said library. This resulted in our client becoming happier with the solution, much more productive and less frustrated with their experience on their site.  We learned an important lesson in this process and we started using that new library on other sites as well. Polling our other clients on the performance of the new library revealed that indeed it was a good change to make. 
Categories: Drupal

Wunderkraut Belgium: A brief history of Support at Wunderkraut Benelux

Planet Drupal - 15 April 2016 - 1:26am
A few years ago most of the requests started with : "Dear Wunderkraut, we want to build a new website and ... "  - nowadays we are addressed as "Dear Wunderkraut, we have x websites in Drupal and are very happy with that, but we are now looking for a reliable partner to support & host ... ". By the year 2011 Drupal had been around for just about 10 years. It was growing and changing at a fast pace. More and more websites were being built with it. Increasing numbers of people were requesting help and support with their website. And though there were a number of companies flourishing in Drupal business, few considered specific Drupal support an interesting market segment. Throughout 2011 Wunderkraut Benelux (formerly known as Krimson) was tinkering with the idea of offering support, but it was only when Drupal newbie Jurgen Verhasselt arrived at the company in 2012 that the idea really took shape. Before his arrival, six different people, all with different profiles, were handling customer support in a weekly rotation system. This worked poorly. A developer trying to get his own job done plus deal with a customer issue at the same time was getting neither job done properly. Tickets got lost or forgotten, customers felt frustrated and problems were not always fixed. We knew we could do better. The job required uninterrupted dedication and constant follow-up. That’s where Jurgen came in the picture. After years of day job experience in the graphic sector and nights spent on Drupal he came to work at Wunderkraut and seized the opportunity to dedicate himself entirely to Drupal support. Within a couple of weeks his coworkers had handed over all their cases. They were relieved, he was excited! And most importantly, our customers were being assisted on a constant and reliable basis. By the end of 2012 the first important change was brought about, i.e. to have Jurgen work closely with colleague Stijn Vanden Brande, our Sys Admin. This team of two ensured that many of the problems that arose could be solved extremely efficiently. Wunderkraut being the hosting party as well as the Drupal party means that no needless discussions with the hosting took place and moreover, the hosting environment was well-known. This meant we could find solutions with little loss of time, as we know that time is an important factor when a customer is under pressure to deliver. In the course of 2013 our support system went from a well-meaning but improvised attempt to help customers in need to a fully qualified division within our company. What changed? We decided to classify customer support issues into: questions, incidents/problems and change requests and incorporated ITIL based best practices. In this way we created a dedicated Service Desk which acts as a Single Point of Contact after Warranty. This enabled us to offer clearly differing support models based on the diverse needs of our customers (more details about this here). In addition, we adopted customer support software and industry standard monitoring tools. We’ve been improving ever since, thanks to the large amount of input we receive from our trusted customers. Since 2013, Danny and Tim have joined our superb support squad and we’re looking to grow more in the months to come. When customers call us for support we do quite a bit more than just fix the problem at hand. Foremostly, we listen carefully and double check everything to ensure that we understand him or her correctly. This helps to take the edge off the huge pressure our customer may be experiencing. After which, we have a list of do’s and don’t for valuable support. Do a quick scan of possible causes by getting a clear understanding of the symptoms Do look for the cause of course, but also assess possible quick-fixes and workarounds to give yourself time to solve the underlying issue Do check if it’s a pebkac and finally, do test everything within the realm of reason. The most basic don’t that we swear by is: never, ever apply changes to the foundation of a project. Support never covers a problem that takes more than two days to fix. At that point we escalate to development. We are so dedicated to offering superior support to customers that on explicit request, we cater to our customers’ customers. Needless to say, our commitment in support has yielded remarkable  results and plenty of customer satisfaction (which makes us happy, too)
Categories: Drupal

Wunderkraut Belgium: I'm running Drupal 6, what do I do?

Planet Drupal - 15 April 2016 - 1:26am
If your website is running Drupal 6, chances are it’s between 3 and 6 years old now, and once Drupal 8 comes out. Support for Drupal 6 will drop. Luckily the support window has recently been prolonged for another 3 months after Drupal 8 comes out. But still,  that leaves you only a small window of time to migrate to the latest and greatest. But why would you?  There are many great things about Drupal 8 that will have something for everyone to love, but that should not be the only reason why you would need an upgrade. It is not the tool itself that will magically improve the traffic to your site, neither convert its users to start buying more stuff, it’s how you use the tool.   So if your site is running Drupal 6 and hasn’t had large improvements in the last years it might be time to investigate if it needs a major overhaul to be up to par with the competition. If that’s the case, think about brand, concept, design, UX and all of that first to understand how your site should work and what it should look like, only then we can understand if a choice needs to be made to go for Drupal 7 or Drupal 8.   If your site is still running well you might not even need to upgrade! Although community support for Drupal 6 will end a few months after Drupal 8 release, we will continue to support Drupal 6 sites and work with you to fix any security issues we encounter and collaborate with the Drupal Security Team to provide patches. My rule of thumb is that if your site uses only core Drupal and a small set of contributed modules, it’s ok to build a new website on Drupal 8 once it comes out. But if you have a complex website running on many contributed and custom modules it might be better to wait a few months maybe a year until all becomes stable. 
Categories: Drupal

Wunderkraut Belgium: Introduction to customer journey mapping

Planet Drupal - 15 April 2016 - 1:26am
So how does customer journey mapping work? In this somewhat simplified example, we map the customer journey of somebody signing up for an online course. If you want to follow along with your own use case, pick an important target audience and a customer journey that you know is problematic for the customer. 1. Plot the customer steps in the journey   Write down the series of steps a client takes to complete this journey. For example “requests brochure”, “receives brochure”, “visits the website for more information”, etc. Put each step on a coloured sticky note. 2. Define the interactions with your organisation Next, for each step, determine which people and groups the customer interacts with, like the marketing department, copywriter and designer, customer service agent, etc. Do the same for all objects and systems that the client encounters, like the brochure, website and email messages. You’ve now mapped out all people, groups, systems and objects that the customer interacts with during this particular journey. 3. Draw the line Draw a line under the sticky notes. Everything above the line is “on stage”, visible to your customers. 4. Map what happens behind the curtains   Now we’ll plot the backstage parts. Use sticky notes of a different color and collect the persons, groups, actions, objects and systems that support the on stage part of the journey. In this example these would be the marketing team that produces the prod brochure, the printer, the mail delivery partner, web site content team, IT departments, etc. This backstage part is usually more complex than the on stage part. 5. How do people feel about this? Now we get to the crucial part. Mark the parts that work well from the perspective of the person interacting with it with green dots. Mark the parts where people start to feel unhappy with yellow dots. Mark the parts where people get really frustrated with red. What you’ll probably see now is that your client starts to feel unhappy much sooner than employees or partners. It could well be that on the inside people are perfectly happy with how things work while the customer gets frustrated. What does this give you? Through this process you can immediately start discovering and solving customer experience issues because you now have: A user centred perspective on your entire service/product offering A good view on opportunities for innovation and improvement Clarity about which parts of the organisation can be made responsible to produce those improvements In a shareable format that is easy to understand Mapping your customer journey is an important first step towards customer centred thinking and acting. The challenge is learning to see things from your customers perspective and that's exactly what a customer journey map enables you to do. Based on the opportunities you identified from the customer journey map, you’ll want to start integrating the multitude of digital channels, tools and technology already in use into a cohesive platform. In short: A platform for digital experience management! That's our topic for our next post.
Categories: Drupal

Wunderkraut Belgium: Taming Facet API paths

Planet Drupal - 15 April 2016 - 1:26am
In combination with the FacetAPI module, which allows you to easily configure a block or a pane with facet links, we created a page displaying search results containing contact type content and a facets block on the left hand side to narrow down those results. One of the struggles with FacetAPI are the URLs of the individual facets. While Drupal turns the ugly GET 'q' parameter into a clean URLs, FacetAPI just concatenates any extra query parameters which leads to Real Ugly Paths. The FacetAPI Pretty Paths module tries to change that by rewriting those into human friendly URLs. Our challenge involved altering the paths generated by the facets, but with a slight twist. Due to the projects architecture, we were forced to replace the full view mode of a node of the bundle type "contact" with a single search result based on the nid of the visited node. This was a cheap way to avoid duplicating functionality and wasting precious time. We used the CTools custom page manager to take over the node/% page and added a variant which is triggered by a selection rule based on the bundle type. The variant itself doesn't use the panels renderer but redirects the visitor to the Solr page passing the nid as an extra argument with the URL. This resulted in a path like this: /contacts?contact=1234. With this snippet, the contact query parameter is passed to Solr which yields the exact result we need. /** * Implements hook_apachesolr_query_alter(). */ function myproject_apachesolr_query_alter($query) { if (!empty($_GET['contact'])) { $query->addFilter('entity_id', $_GET['contact']); } } The result page with our single search result still contains facets in a sidebar. Moreover, the URLs of those facets looked like this: /contacts?contact=1234&f[0]=im_field_myfield..... Now we faced a new problem. The ?contact=1234 part was conflicting with the rest of the search query. This resulted in an empty result page, whenever our single search result, node 1234, didn't match with the rest of the search query! So, we had to alter the paths of the individual facets, to make them look like this: /contacts?f[0]=im_field_myfield. This is how I approached the problem. If you look carefully in the API documentation, you won't find any hooks that allow you to directly alter the URLs of the facets. Gutting the FacetAPI module is quite daunting. I started looking for undocumented hooks, but quickly abandoned that approach. Then, I realised that FacetAPI Pretty Paths actually does what we wanted: alter the paths of the facets to make them look, well, pretty! I just had to figure out how it worked and emulate its behaviour in our own module. Turns out that most of the facet generating functionality is contained in a set of adaptable, loosely coupled, extensible classes registered as CTools plugin handlers. Great! This means that I just had to find the relevant class and override those methods with our custom logic while extending. Facet URLs are generated by classes extending the abstract FacetapiUrlProcessor class. The FacetapiUrlProcessorStandard extends and implements the base class and already does all of the heavy lifting, so I decided to take it from there. I just had to create a new class, implement the right methods and register it as a plugin. In the folder of my custom module, I created a new folder plugins/facetapi containing a new file called url_processor_myproject.inc. This is my class: /** * @file * A custom URL processor for cancer. */ /** * Extension of FacetapiUrlProcessor. */ class FacetapiUrlProcessorMyProject extends FacetapiUrlProcessorStandard { /** * Overrides FacetapiUrlProcessorStandard::normalizeParams(). * * Strips the "q" and "page" variables from the params array. * Custom: Strips the 'contact' variable from the params array too */ public function normalizeParams(array $params, $filter_key = 'f') { return drupal_get_query_parameters($params, array('q', 'page', 'contact')); } } I registered my new URL Processor by implementing hook_facetapi_url_processors in the myproject.module file. ** * Implements hook_facetapi_url_processors(). */ function myproject_facetapi_url_processors() { return array( 'myproject' => array( 'handler' => array( 'label' => t('MyProject'), 'class' => 'FacetapiUrlProcessorMyProject', ), ), ); } I also included the .inc file in the myproject.info file: files[] = plugins/facetapi/url_processor_myproject.inc Now I had a new registered URL Processor handler. But I still needed to hook it up with the correct Solr searcher on which the FacetAPI relies to generate facets. hook_facetapi_searcher_info_alter allows you to override the searcher definition and tell the searcher to use your new custom URL processor rather than the standard URL processor. This is the implementation in myproject.module: /** * Implements hook_facetapi_search_info(). */ function myproject_facetapi_searcher_info_alter(array &$searcher_info) { foreach ($searcher_info as &$info) { $info['url processor'] = 'myproject'; } } After clearing the cache, the correct path was generated per facet. Great! Of course, the paths still don't look pretty and contain those way too visible and way too ugly query parameters. We could enable the FacetAPI Pretty Path module, but by implementing our own URL processor, FacetAPI Pretty Paths will cause a conflict since the searcher uses either one or the other class. Not both. One way to solve this problem would be to extend the FacetapiUrlProcessorPrettyPaths class, since it is derived from the same FacetapiUrlProcessorStandard base class, and override its normalizeParams() method. But that's another story.
Categories: Drupal
Syndicate content


Google+
about seo