Drupal News

Subscribe to Drupal News feed
Drupal.org - aggregated feeds in category Planet Drupal
Updated: 2 hours 55 min ago

Oliver Davies: Include a local Drupal settings file for environment configuration and overrides

5 hours 56 min ago

At the bottom of settings.php, add the following code:

$local_settings = __DIR__ . '/settings.local.php'; if (file_exists($local_settings)) { include $local_settings; }

This allows for you to create a new file called settings.local.php within a sites/* directory (the same place as settings.php), and this will be included as an extension of settings.php. You can see the same technique being used within Drupal 8's default.settings.php file.

Tags:

Wunderkraut blog: A Medium like editor for Drupal

7 hours 53 min ago

The editor used to edit posts at medium.com is a real slick, and I find it interesting and intuitive. Davi Ferreira have made an open source clone of it, so it could easily be used in other places.

@cweagans have done great work to get the Medium editor in it's own module, but I would rather myself have it inside the WYSIWYG API. so I took some parts of his work and did a patch, so if somebody else finds it interesting to get this editor to work with WYSIWYG API, please try it out, test, review, throw stuff at it...

As a first step I just added the text editing part, with further plans on try it to get it to work with Asset for images, videos etc.

Drupal Association News: Drupal Association Board Meeting: 17 December 2014

Fri, 12/19/2014 - 12:46

This week we held our last board meeting of the year, and we covered a lot a of ground. Unlike November, where we had a relatively short public meeting, this session took the full two hours to get through. We covered a lot of topics, from DrupalCon Amsterdam to updates from the Working Groups. As always, you can review the minutes, the materials, or the meeting recording to catch up on all the details. Here's a summary for you as well.

Operational Update

The month of November was short given the US holiday (Thanksgiving), but we still have a number of initiatives that we managed to push significantly forward. Among them:

  • Licensing Working Group: We recently put out a call for volunteers for the Licensing Working Group, whose charter was approved at the November board meeting. If you are interested in licensing issues, we hope that you will consider applying. The Licensing Working Group will play a pivotal role in helping contributors navigate what is and isn't allowed quickly and in keeping our code GPL compliant and safe.
  • Social capital and the Driesnote: In Amsterdam, Dries laid out a vision for the future of contribution in our community. We also began sharing a plan for Drupal.org in 2015 at DrupalCon Amsterdam that aligns with that vision. We have been laying the groundwork over the last few months, working on commit messages and profile improvements that will make it possible to illustrate not just code contribution, but the many kinds of contribution that individuals (and soon, organizations!) make in the Drupal community.
  • 2015 workplans: Association staff have been very busy preparing workplans for 2015 as well. The DrupalCon team has been rethinking food and fun at DrupalCons based on recent survey feedback. The Drupal.org team has been working on the roadmap. Our revenue team has been planning for solidifying the new revenue programs we launched this year (like Drupal Jobs) and planning for new opportunities as well.
  • DrupalCon Latin America: We are all very excited to get to Bogota for DrupalCon Latin America next February. Everything is on track for this event from a logistics standpoint. We have speakers and space and now all we need are more people. We are planning for 400 people to be there and have about 90 registered so far. Normally, we would have a much higher percentage of tickets sold at this point, but with a very minimal price increase between rates, and with the holidays, we suspect we will see more registrations closer to the date of the Con.
Marketing & Branding Committee Update

We're coming up to a pretty pivotal time for Drupal marketing. As we near a Drupal 8 release, the Marketing and Branding Committee can help lead the community in making this the biggest Drupal release ever. In the meeting, the Board voted to approve the appointment of Gina Montoya of Blink Reaction as the new Chair of that committee. Congratualtions and thank you Gina!

DrupalCon Amsterdam Wrap

Over the last few Cons, we have worked hard to collect more data about our attendees and their experience and to analyze that data to understand what's working and what's not. We looked at a LOT of data for DrupalCon Amsterdam, and shared what we learned and what we will be applying to future Cons. In short - the Con was very successful financially, but we continue to struggle to collect session evaluations and, frankly, the food was terrible. We are very sorry about that. Basically, until the last two weeks before the Con, ticket sales looked slow, so we modified the catering order to mitigate the budget loss we were facing. When the upsurge in ticket sales began, it was too late to change our box-lunch order. We will definitely be rethinking food overall. It's one of the single biggest expenses at DrupalCons, and we know it's one of the best ways to keep attendees happy. Check out the complete overview.

2015 Budget and Leadership Plan Highlights

The board approved the 2015 Budget and Leadership Plan in executive session at the previous board meeting. We reviewed the highlights this month in the public board meeting. If you're interested in even more details, you can watch the recording of the webcast that we presented on Thursday, 18 December.

Governance Updates Board Term Limits

The Board of Directors operate under a set of rules that govern issues like how the board is structured, the length of terms, etc. This set of rules is codified into the organization's Bylaws. Like any good governance document, and like any good governance group, it makes sense to review how the group operates and what rules might need to be changed in order to provide a better framework for governance. The Governance Committee of the board is charged with ensuring that the board is operating at its best, and making recommendations when things could work better.

In the original bylaws of the organization, terms for Class Directors (nominated and approved by the board, not community-elected seats), are set at 3 years, with a limit of 3 terms. That means that any Class Director could serve a total of 9 years on the board. This is not absolutely a problem, but we do know that board operate best when members are energetic and fully committed, and when new ideas and perspectives can be added to the mix. Nine-year terms work against both of those concepts. To solve for this, the board voted to change the bylaws and limit service to two 3-year terms, or 6 years total. A board member does have the option of taking a year off at that point and could be re-appointed after a year of downtime. We are currently updating the bylaws document to reflect this vote and will update the Association site when this work is complete. 

Community Elected Candidates

One other issue that has been raised by the board is preparing community-elected board members for their service on the board. This class of directors exists to provide a balance of perspective on the board, and everyone understands that many community-elected board members will likely have little board experience prior to their service. The board wants to ensure, however, that these members can jump into their term easily and figure out how to advocate for their agenda quickly. To that end, the boad agrees that it makes sense for candidates to at least have some experience with the mechanics of the Association Board. The Governence Committee recommended that a requirement of board meeting attendance would be a low-threshold to meet, and would expose candidates to how the board operates. The proposal was that, starting in the 2016 elections, candidates will need to attend a minimum of 3 board meetings, which can be tracked by Association staff.

This proposal was voted on and adopted by the board. However, I do want to note that it was not a unanimous vote; we had 2 nay votes. The point was made that currently, all board meetings are held at noon pacific on the third Wednesday of the month. That time slot is during waking hours for the US and Europe. It's early in Australia, but doable. However, anyone in Asia, in particular, can't participate in those awkward hours. The suggestion was made that we shift some of our meeting times to accomodate these other time zones if we are going to make attendance a requirement for running. There was general agreement with this sentiment, but no clear conclusion about how to actually make that happen. The board decided to call the proposal to vote now and work out the logistics of shifting board meeting schedules at a later date.

Working Group Updates

Lastly, we got updates from all of the Drupal.org Working Groups: Software, Content, and Infrastructure. In addition to the work they are pursuing related to the Drupal.org roadmap, Working Groups are also reviewing their charters. With more than a year of operations under their belts, and with a full tech team on staff at the Association, it's important to take a look at how things have changed and ensure that charters are still in alignment.

Goodbye 2014!

It has been a big year for the Association and the Drupal community. I want to take this opportunity to thank the Drupal community for all your support for the Association. It's a joy to come to this job every day and work together to take on the challenges and opportunities we face. Your generosity, smarts, and sense of humor makes it all that much more rewarding. I can't wait to see what we tackle together in 2015!

Flickr photo: Matt Westgate

3C Web Services: How to: Drag & Drop Multiple Image Upload for Drupal 7

Fri, 12/19/2014 - 11:26

Drupal 7 provides a file field that allows for uploading files and images to your Nodes but it is limited in functionality. The core file field only allows for uploading one file at a time and does not permit drag and drop functionality. Hower, with a few modules and a little bit of configuration we can easily provide this functionality to your site.

MODULES

First download and install the following modules:

LevelTen Interactive: Video: Better Content Formatting Using CK Editor, Bootstrap & Drupal

Fri, 12/19/2014 - 09:56
*/ /*-->*/

Creating and promoting content is crucial for your business, and it can be very frustrating at times.... Read more

Annertech: Code that makes Programmers Perform

Fri, 12/19/2014 - 08:36
Code that makes Programmers Perform

Code that performs well should be an assumption, not a requirement. I've never had a client ask me, “will your code make my site run slower?" Clients just assume that I'm going to deliver a codebase that does not hold things up.

Mediacurrent: New Year's Resolutions: Drupal Edition

Thu, 12/18/2014 - 14:46

Lose weight. Eat better. Run a 5K. Travel more. These are resolutions we all make year after year. But this year, we challenged our team to think outside the box and inside the drop. Now that 2014 has come and gone, and we prepare to countdown to 2015, we asked our team what they are looking to accomplish in Drupal in the New Year.

“Get more of my modules out for D8.” - Andrew Riley

Drupal Watchdog: At Your Request

Thu, 12/18/2014 - 11:29
Feature

In the beginning there was the Common Gateway Interface, commonly known as CGI – a standard approach used to dynamically generate web pages. Originally devised in 1993 by the NCSA team and formally defined by RFC 3875 in 2004, CGI 1.1 took seven years to go from the original RFC to an endorsed standard.

In 1994, not long after the original CGI standard was documented by NCSA, Rasmus Lerdorf created Personal Home Page tools (PHP Tools), an implementation of the Common Gateway Interface written in C. After going through a number of iterations and name-changes this grew to be the PHP language we know and love.

One of PHP's strengths was the way in which it made many of the request and server specific variables, as defined by the CGI standard, easy to access – through the use of superglobals, namely $_POST, $_GET, and $_SERVER. Each of these is an associative array. In the case of $_POST, the request body is parsed for you and turned into an array of user-submitted values, keyed by field name, and conveniently supporting nested arrays. Similarly for $_GET, the query string is parsed by PHP and turned into a keyed array. In the case of $_SERVER, the gamut of server-specific variables are available for your script to interrogate.

Blink Reaction: Try Drupal 8 now

Thu, 12/18/2014 - 11:08

You may have heard and read a lot about Drupal 8 lately, without much support to go along with it. Well here at Blink Reaction, we are working on changing that and contributing as much help as we can to the community with the issues that we’ve come across so far in Drupal 8. In this post I will show you how you can try Drupal 8 by installing dependencies such as composer and drush so you can have a Drupal 8 site running on your local machine.

Cheeky Monkey Media: My BADCamp 2014 Experience

Thu, 12/18/2014 - 10:00

I have been privileged to be able to attend a number of conferences and events, such as DrupalCon Austin, Portland etc,  since we started Cheeky Monkey Media. In the past, we’ve talked about having your DrupalCon Survival kit prepared before you head out the door to help make...Read More

Blair Wadman: What is a Drupal developer?

Thu, 12/18/2014 - 07:30

As the Drupal market continues to rock and roll, more and more clients need "Drupal Developers". But what exactly is a Drupal Developer? A Drupal Developer is someone who knows Drupal right? Right?!

Drupalize.Me: Adventures in Porting a D7 Form Module to Drupal 8

Thu, 12/18/2014 - 06:26

Got some Drupal 7 modules that use the Form API lying around? Want to learn how to port them to Drupal 8? The process could just be the crash course you've been looking for in Drupal 8, object-oriented, module development.

Code Karate: Drupal 7 Rules Filter: Manage and search your Drupal rules

Thu, 12/18/2014 - 06:18
Episode Number: 186

The Drupal Rules Filter Module is a simple module that makes it easy to sort through a long list of Drupal Rules. This is a module that is especially useful on those larger scale Drupal websites that rely heavily on the rules module and have many contributed Drupal modules installed.

Tags: DrupalRulesDrupal 7Drupal PlanetSite Administration

Drupal Association News: Meeting Personas: The Drupal Expert

Thu, 12/18/2014 - 05:00

This post is part of an ongoing series detailing the new personas that have been drawn up as part of our Drupal.org user research.

Kate Marshalkina has been using Drupal for three and a half years. A web developer by trade, Kate was approached by a friend who wanted her to do Drupal work with him. After doing some research on the system, Kate agreed.

“It’s quite difficult to learn Drupal without paid work because it requires a lot of time and experience to learn the Drupal way of doing things,” Kate said. “I had joined a security startup, and a security company obviously cares about security on the web. So we decided to use Drupal because it’s a safe, well known open source system. I learned a lot while I was working on my tasks, but I spent a lot of my free time to learn Drupal. Once I started learning, I couldn’t stop— I’d previously worked with other content management with less documentation and information and then I started learning Drupal and... because of the community, and all of the learning resources and videos that are available, I was hooked."

“After working with Drupal for three months, I started my blog and not long after that I presented a session at DrupalCamp Moscow. Now, I’m a Drupal lover after three and a half years working with the platform."

Drupal.org: A Valuable Resource

Every day, Kate checks in to Drupal.org: she says she visits the site to find new modules, check the issue queues, and check API documentation. “I’m very comfortable with Drupal.org, but it was hard getting used to it when I started. Initially, it was a question for me why I should even use Drupal.org, and I didn’t know what the benefits are.

"I really like my dashboard on Drupal.org,” said Kate. “It’s a great page where I can see daily updates on my issues — and of course I follow a lot. It’s nice that I can also easily view updates on issues in critical bugs in core and so on, see crucial updates, core releases, and of course I also follow the Drupal Planet RSS feed."

Drupal Planet is one of the most helpful tools for Kate when it comes to getting new Drupal knowledge, and she often encourages her colleagues to follow it. "I think Drupal Planet is an exciting part of Drupal.org. It’s a great resource for Drupal related articles for everyone; beginner to expert, frontend to backend to sysadmin, the information for all these people is usually very high quality on Drupal Planet. When I’m working with fellow developers who have questions, I always ask them to look on Drupal Planet because I know that the information there is of a high quality, and that anyone can find the knowledge they need in there."

It's About the People

Some of the recent changes made on Drupal.org, including the addition of user pictures to the issue queue, have made Kate’s Drupal experience vastly better.

“[The pictures] are great because it makes Drupal.org more personalized, and you can more easily remember the people you talked to because of their photos. And, it reminds people that Drupal isn’t just a CMS, it’s a community, and the people are important.”

“It’s a big question for me how to enroll younger developers,” said Kate. “Looking at the contribution opportunities, [new people] may feel like they can’t be a contributor. So sometimes, they may encounter a bug they don’t know how to fix and think, “oh no, a bug!” instead of recognizing it as an opportunity to learn and grow. If we can encourage more people to become contributors, they will benefit from it and Drupal will benefit from them."

Kate’s advice for new Drupalers is to “start right out and register on Drupal.org. Share modules, create patches, learn how to use git and so on… it’s not easy, but it’s worth it."

Growing With the Project

As for herself, Kate hopes to increase her skill level by contributing to Drupal 8 core.

"I participated in DrupalCon Amsterdam, and really liked what Dries said about getting more benefits to small companies who contribute so that it will be easier for employers to understand why they spent their time and pay for developers on core. I would be much more experienced if I could participate in Drupal core development."

"I also want to someday give a session at DrupalCon,” Kate added. "I give a lot of sessions in my local community, camps and so on. I’ll be speaking at Moscow Drupal Camp in November, but hope to speak at a DrupalCon soon."

We all wish you the best of luck, Kate, and hope to see you on a stage at DrupalCon soon!

Personal blog tags: drupal.org user researchpersona interviews

Pixelite: Installing Solr for development

Wed, 12/17/2014 - 17:00
Intro

Solr is an open source search engine with many powerful features.

I encounter a lot of experienced developers that either don’t know how to use it or avoid it as it’s in the to hard/scary basket. In this introductory article we’ll talk briefly about how to install Solr in order to use it for development.

There are many ways to install and configure Solr but in this article I’ll show you how to set it up quickly so you can get started developing with it. While the installation and setup will be generic to any framework you want to develop with, I’ll also, show you a couple of extra steps if you’re using Drupal.

Requirements

The only real hard requirement/prerequisite for running Solr is Java. Version 1.6 is recommended for Solr version 4 and upward. Ubuntu and Mac should come with Java pre-installed.

I’m not a windows guy so sorry you guys are on your own There’s pleant of resources out there.

You can find out the version of Java you are running with the following command.

$ java -version java version "1.7.0_72" Java(TM) SE Runtime Environment (build 1.7.0_72-b14) Java HotSpot(TM) 64-Bit Server VM (build 24.72-b04, mixed mode)

I am using Ubuntu 14.04 but the instructions in this article should work if you’re on a Mac or another variant of *nix

Download

Open a terminal and make a folder we can use for working in, and change to that directory:

$ mkdir solr $ cd solr

Navigate to the Solr download page and find the closest mirror for you. At the time of this article the latest version of Solr is 4.10.2.

Copy the download link for either the solr-VERSION.tar.gz or the solr-VERSION.zip. You don’t want the solr-VERSION-src.tgz (this is the source code and will need to be compiled) and download it with wget.

$ wget -c http://mirrors.sonic.net/apache/lucene/solr/4.10.2/solr-4.10.2.tgz Unpack

Once downloaded (it’ll be about 150M) we can un-compress it and change into the directory.

$ tar -zxvf solr-4.10.2.tgz $ cd solr-4.10.2/ Make a working copy

In the current directory there is a folder called example we want to make a copy of this folder.

We could just use the example folder but it’s nice to leave that clean on case you want to use this copy of Solr for other sites as well. So we’ll make a copy and then change directory into the newly created copy.

$ cp -prv example my_solr $ cd my_solr Make it work

Now we’re ready to run it for the first time. To run Solr it’s really simple. Simply run:

$ java -jar start.jar

You should see a whole bunch of output (to stop solr press CTRL^C). After a few seconds if you open your browser and navigate to http://0.0.0.0:8983/solr/ you should see something similar to the following (the actual screen may differ depending on your version)

That’s it. Solr is now set up and ready to use. Depending on your client frame work you may need to makes some config changes to Solr itself. Consult the installation instructions of your chosen framework. If you’re using Drupal keep reading and I’ll show you the steps required to make Solr ready for Drupal integration. First lets stop SOlr from running by hitting CTRL^C in your terminal.

Modules

There are a couple of modules you can use for Drupal integration with Solr. I wont go into the Drupal configuration side of things (I’ll leave that for another day) but will talk about the steps required to get the Solr server we’ve set up ready for Drupal usage depending on the Solr module you’ve chosen.

Search API and ApacheSolr

If you’re using the search_api you will need to ensure you have the search_api_solr module installed. Otherwise the apachesolr module is the way to go.

In both the search_api_solr and apachesolr modules, you’ll find a folder called solr-conf in this folder there will be version folders 4.x, 3.x etc. Choose the version of Solr you downloaded. This folder contains all the config files you need to install in your Solr install. I could probably write a whole bunch of articles about the contents of these files but since this is a beginner tutorial we’ll just take the easiest route.

You want to copy the contents of the solr-conf/4.x/ folder into your solder core. We can do this with the following, go back to your terminal, and run (change the path to your Drupal module):

$ cp -v **/path/to/apachesolr/or/search_api_solr/**solr-conf/4.x/* solr/collection1/conf/

That will copy the config for your Drupal site into the my_solr/solr/collection1/conf/ directory.

Conclusion

Solr is now ready for use by your Drupal install. You can run it whenever you like by changing into the my_solr directory and starting it.

$ java -jar start.jar

I wouldn’t recommend using this setup in production. However, for developing on your local machine, it’s perfectly fine.

In the next article, I’ll talk about how to configure the search_api and search_api_solr to use Solr as a search engine for your Drupal site.

Drupal Watchdog: The Drupal 6 to 8 Upgrade Challenge - Part 1

Wed, 12/17/2014 - 14:52

Nathaniel Catchpole , the Drupal 8 release maintainer and Tag1 Senior Performance Engineer, suggested that Drupal shops everywhere could support the release of Drupal 8 by upgrading their own sites and addressing the issues they find along the way. This series chronicles the journey from Drupal 6 to Drupal 8.

Part 1: Readiness Assessment

Before performing a major version upgrade, I usually go through a series of steps that help me determine:

  1. What compelling business needs or new functionality are prompting the move? In this case, the site builder view on the status of D8 will help us identify and hopefully address real barriers to adoption, as well as to prepare materials that help document the journey.
  2. What does the site do? If there are functional tests or test plans, I review those. Then, I manually review the site, paying attention to functionality for particular roles. I also check with at least one or two of the stakeholders with each role to learn what features they regularly use, what improvements would better support them, and what they’d really like to see. I don’t normally act on that wish list answer as part of the upgrade proper, but knowing what new functionality they desire can help make decisions about the new modules to use.
  3. Are there features that are no longer in use? I’m always surprised, though by now I really shouldn’t be, by the number of things that seemed like a good idea at the time to someone which were never used at all or which are no longer in use.
  4. Is now the right time? Are the contributed modules on which the site depends ready or is there a new way to achieve the required functionality.
1- Compelling Functionality

As noted above, this particular journey is compelled by the desire to identify and fix bugs during the Beta period of Drupal 8. That doesn’t mean we’re not excited by:

  • WYSIWYG in Core- I am ecstatic at the prospect of NOT having to choose and configure basic WYSIWYG functionality.
  • Views in Core - I pay a lot of attention to the experience of content contributors. They’re the everyday users that Dries talked about back at DrupalCon San Francisco, people who use the interface of Drupal as their day job. What a site builder does for them (or fails to do) can make or break the success of the site as well as cement the organizational satisfaction with Drupal itself.

I want Tag1’s busy staff to find it a pleasure to keep their blogs, community contributions, and case studies up-to-date.

2 - Current Functionality

Our speciality is performance and scalability for complex websites, which never necessitated building a complex external site for ourselves. We have internal sites that put Drupal 6 though its paces, but the main Tag1 site is a combination of blogs and brochure:

  • Review what the current site does
    I start any readiness evaluation looking at the site from the user perspective, clicking around, then reviewing any documentation. The site revealed no surprises. I jotted notes about those user-facing features, mapped to Drupal functionality, and stored them as a sheet in the Readiness spreadsheet. For a basic site, the notes aren’t too impressive, but the process was a valuable refresher on what the site does.
  • Inventory the enabled modules
    After looking at the site from the user interface, I make an inventory of enabled modules. The following Drush commands make nice spreadsheets: drush pm-list --no-core drush pm-list --core

    You can take a look on Sheets 2 and 3 of the Readiness spreadsheet to see the entirety of what was and and wasn’t available.

    In our case there are just two areas of concern:

    Blogs have been removed from core, but with views moved in, this won’t be daunting to rebuild. They may work a little differently, but odds are that will be for the better!

    The only missing module that had no alternative and looked like it might hurt was Pathauto. It’s nice to keep URLs tidy and hard to remember to set them, but wouldn’t be strictly necessary for our purposes and there were were no other glaring show stoppers.

    Note: It looks like upgrade work is happening on Github so I updated the spreadsheet to make note and will evaluate the status as part of the process.

  • Look for customizations
    In addition to custom and contributed modules, it’s good to check for inappropriate customizations done directly to core or contrib. Whatever reason they had for being done back then may need to be accounted for, hopefully in a best-practices way, on the new site.

    Although it seemed unlikely that any relevant changes had been done, for good measure, I always run Hacked. It’ll let you know about files that have been changed from the source.

    There were some theme customizations and a .gitignore file was missing, so as suspected, nothing to worry about.

3 - Features no longer in use

I’ve learned over the years that not every module that is enabled is in use! I try to find a link that illustrates somewhere on the site that the module is visibly in play. Even when there is a place in production where the module is used, it’s entirely possible that the production feature itself doesn’t make sense to upgrade. A serious investigation of analytics and logs can be insightful. Data can guide conversations with product owners about what’s still valuable and support decision-making.

On our straightforward site, there’s not much to not use. As I learned running the first migration, though, even features that were briefly explored but never used can come into play. More on this later.

4 - The right time

Once you’ve completed your archaeology, you’ll need to find the right time for your organization. Talk with stakeholders about the change and be on the lookout for in-process or upcoming feature requests that you might not be prepared to accommodate.

In our case, because the motivation for this upgrade is process, not product, we’ll proceed and go as far as we reasonably can with the upgrade. At the time of this writing, I’ve done a D8 install and begun running a migration. (That’s how I know to be on the lookout for certain disabled modules!) I’m feeling confident that we can get a long way.

Unless the migration process is flawless and the Drupal 8 to Drupal 8 update path is in place I'd be unlikely to recommend deployment of the work, especially with an impending re-design. While re-entering some data manually has always been a part of previous major version upgrades, I’d be loathe to commit to beta adoption if I thought we’d find ourselves stranded in the latest version. Fortunately, all the preparatory work can be done without the upgrade path in place!

Coming next in this blog series, Part 2: Preparing to Migrate.

What modules and processes do you use to prepare for a major version upgrade?

Acquia: Drupal & PHP: Linking Islands, the podcast – part 1

Wed, 12/17/2014 - 14:14
Language Undefined Drupal & PHP: Linking Islands, the podcast – part 1

Phase2: Play with Display: Altering Drupal Field Collections

Wed, 12/17/2014 - 13:43

How do you insert a text field into a rendered entity, all within a field collection? This question came to mind on a recent Drupal 7 build. What at first sounded complicated turned into a concise and elegant solution.

The basis of the requirement broke down into the need for events to list those participating in the event. The build already had existing Event and Profile content types, so the new functionality would only require implementing the list of Profiles participating in an event. Each participant would include their role at the event, along with links to contact them.

To implement this, an Event Participant field collection was added as a field to the Event content type. Each instance of the field collection included a single Profile content type and a single text field for their role at the Event. The Profile would then be displayed as a rendered entity within the field collection so that the Profile’s image and contact links could be displayed. The point at issue then arose. How would the Participant’s role at the event be placed within the rendered Profile teaser, along with the other Profile fields? To the user it needed to look like a single unified entity, with the Profile’s image, role at the Event, Profile name, and contact links all included.

After some initial brainstorming a handful of different approaches came to mind. The initial impression was to use template_preprocess_field() since it allows the alteration of values in the theme layer. The participant role field would be removed from it’s initial location and inserted into the participant profile object. This did not work though. Despite the repositioning of elements within the render array, the changes occur too late in the rendering execution. The render array had already been rendered and thus the display remained the same.

After quickly realizing a theme function wasn’t the answer, hook_node_view() came to mind. The hook allows for the alteration of a node before it is rendered and so all that would be needed would be to shift the location of the Participant Role field within the $node array. The issue with this implementation and the reason it wasn’t chosen, is that it would require reaching out to the global state to determine what changes are needed. In other words hook_node_view() doesn’t realize what context it is called under and would thus require a hack of sorts to determine when it was being called under an Event node. This could be worked around by checking the URL path, but this is not best practice as it is brittle and prone to breaking with future site updates.

As they say the third time’s the charm. The final solution was to use hook_field_collection_item_view(). This hook allows for the alteration of a field collection item before rendering. Unlike many of the other options, this hook is called for each field collection item, allowing one to both check the field collection name and adjust it’s internal field ordering, before any rendering occurs. Using this hook, each Event Participant field collection item is altered, removing the Role field and inserting it into the Profile rendered entity. Simple as that. Now each Event Participant is correctly displayed as a single unified entity, with an image, name, and a set of contact links.

function hook_event_field_collection_item_view($field_collection_item, $view_mode, $langcode) { if ($field_collection_item->field_name == "field_event_participants") { $role = $field_collection_item->content['field_event_participants_role']; $profile_id = $field_collection_item->field_event_participants_profile[LANGUAGE_NONE][0]['target_id']; // Remove Participant Role from previous location in field collection output unset($field_collection_item->content['field_event_participants_role']); // Insert Participant Role into the Participant Profile output $field_collection_item->content['field_event_participants_profile'][0]['node'][$profile_id]['field_event_participants_role'] = $role; } }

Through several quick, small, iterations an elegant, straight-forward solution was found to what at first sounded like a complicated feature request. Now users viewing an Event can see a list of Participants, with each Participant displayed as a single item. Check out more on field collections on the Phase2 blog!

Drupal Association News: Meeting Personas: The Skilled Drupal User

Wed, 12/17/2014 - 13:00

This post is part of an ongoing series detailing the new personas that have been drawn up as part of our Drupal.org user research.

Chris Ohmstede is based out of Los Angeles, California. An experienced programmer, Chris is new to Drupal but already identifies as a skilled persona. Several months ago, Chris discovered Drupal as he was looking for solutions to build a website for hosting a program he wrote.

"I spent a number of years in the banking industry, and in that industry banks are constantly making connections to everything. I was always running in to problems when things couldn’t connect— it was always an issue trying to figure out what was actually going on. Over the years, I wrote a bunch of applets here and there to figure out what the problems were, and my program whycanticonnect is a conglomeration of those applets that work across operating systems, mobile— I’ve got cloud services approaching me about it, too.

Wanted: Custom Functionality

“Originally, I was hosting my project for download using a different CMS option, but things weren't working properly. Finally, I hit a point where I said “I’ve got to make a change.” I initially went to Drupal because I use Linux as my OS, and Drupal is one of the only CMSs available out of the repositories. I saw that, went and did some research, and Drupal looked big and well organized. One of the cool things that caught my attention is that I could Google around and see that everything I needed was already built. I never had to ask for any help — I was able to roll on through and put my site together easily."

“Also, one of the reasons why I selected Drupal was that I've released my product in 12 different languages, and Drupal looks like it has some decent translation services coming in. I want my site to be usable in all 12 languages I support."

After downloading Drupal, Chris relied on his technical knowledge to carry him through. Though he initially encountered some difficulty getting the modules to do what he wanted, he found after some searching that deriving his theme would fix his problems.

"Once I derived the theme, everything got easier— the way drupal derives themes is perfect. It’s very object oriented, which is fantastic. The nice thing about Drupal was that I could figure out what I wanted to mess with, and I could build variables on the local scope and carry them through the whole page and process, which is surprisingly difficult to do with other systems."

"It gives me everything I need"

“The great thing about Drupal is that you're not limited in how to inject code,” said Chris. "I like my download module because it gives me everything I need. It figures out intelligently what’s the best download to go with, it builds a link and launches the javalaunch, so it’ll work whether java is enabled or not— which was a problem I’d had before. I’m very happy with it, and very happy with Drupal."

For the time being, Chris doesn’t plan to put together more Drupal sites — rather, he’s going to focus on maintaining the one he has.

"I have no desire to become a web designer,” Chris said. “I built my site because I know I'll need to change it often, and with Drupal it doesn’t cost me anything. As far as giving back to the community, I’m mostly focused on working with my product. I need to write an Android, Mac, and iOS version. I’m planning on submitting some of my modules to Drupal.org once I’ve got them in shape, and I’ve made posts for people asking the same questions and encountering the same problem as I have. Maybe someday down the road I’ll have time to do more, though I certainly wouldn’t make any promises about it."

Personal blog tags: drupal.org user researchpersona interviews

Pages