Software
Web Omelette: How to remove all the Voting API results for a given node type
Have you ever needed to remove in bulk a bunch of voting results for, let's say, a given content type? There is no option in the UI but you can find in the votingapi.module some handy functions that will allow you to write a customized update hook.
So let's say that we need to remove all the results for the article content type. If we look in the votingapi_vote table, we don't see any bundle or content type column, but we see an entity_id. So we need to get all the ids of our article nodes:
$query = db_query("SELECT nid FROM node WHERE type = 'article'"); foreach ($query as $res) { $nids[] = $res->nid; }Now we have the $nids array containing all of our node IDs. Next, let's load all the votes for these IDs:
module_load_include('module', 'votingapi', 'votingapi.module'); $votes = votingapi_select_votes(array('entity_id' => $nids));First we include the right module file and then we use one of its functions to select all the votes that match some criteria (in our case an array of IDs). Next, we need to worry also about the votingapi_cache table which contains the results of the voting per entity. We need to remove that as well. So we'll use another helper function from Voting API:
$results = votingapi_select_results(array('entity_id' => $nids));Now we have also the result objects we need to delete so we can proceed with the actual removal. For this, we can use two more handy methods from the Voting API module:
votingapi_delete_votes($votes); votingapi_delete_results($results);And that's it. This will remove all the votes and their aggregated results from both tables. It may take some time so make sure you have enough server resources to perform this task.
To use this code, I recommend creating an update hook in a custom module that you run once. But make sure you properly test it on your test environment before deploying and running the code on production servers. Always keep in mind the possibility of the server running out of resources depending on how many votes you have in the database.
Do you have any better way of batch deleting votes/results? This is what I found and I'm curious if you know of any better ways. Let me know.
var switchTo5x = true;stLight.options({"publisher":"dr-8de6c3c4-3462-9715-caaf-ce2c161a50c"});KYbest: Applying node access on a non-node based view
The Views module automatically joins the node_access table only for node based views. In any other case we need to take care of the proper access handling ourselves.
PreviousNext: Talk to the CMS end users: content editors
Have you ever delivered a project that was met by the content team with a collective sigh? There's a simple way to avoid that - talk to them!
Robert Douglass: How did DrupalCon change your life?
DrupalCon is the heart and soul of the Drupal Community. Thousands of us have attended over the past 9 years. Many of us, myself included, have had life-changing experiences at DrupalCon. How did DrupalCon change your life? Now is the time to share your story with thousands of your closest friends! ... or the Drupal community.
What is this for? It's for the "Prenote" session at DrupalCon Amsterdam. Every DrupalCon, Jam and I collaborate to show some aspect of the Drupal experience through humor, drama, song, cheesy costumes, and famous Drupal guest stars. We'd like to include some of these stories in Amsterdam!
Thanks for sharing!
Which DrupalCon? * Austin, 2014 Prague, 2013 Portland, 2013 Sydney, 2013 Munich, 2012 Denver, 2012 London, 2011 Chicago, 2011 Copenhagen, 2010 San Francisco, 2010 Paris, 2009 Washington, D.C., 2009 Szeged, 2008 Boston, 2008 Barcelona, 2007 Sunnyvale, 2007 Brussels, 2006 Vancouver, 2006 Amsterdam, 2005 Portland, 2005 Antwerp, 2005 Which DrupalCon changed your life? Tell your story * What happened that changed your life? Was it meeting a specific person? Attending a session? Being in the right place at the right time? What aspect of your life now would not have been the same if you hadn't attended DruaplCon. Will you be attending DrupalCon Amsterdam? * Yes No E-mail * Skype or phone How can we contact you? What's your Skype ID or phone number?Drupal Watchdog: Decoupling Drupal
The latest rage in the Content Management world is the idea of a “decoupled CMS.” That is, rather than having a single monolithic system that handles everything from content entry to management to display and theming in one program spread, that responsibility is assigned to different systems: one that is really really good at content storage, one that's really really good at content management, one that's really really good at display and theming, etc.
At the same time, there has been a huge push for web services in almost every market. If you want content to be available anywhere besides an HTML page, then your answer is web services.
Drupal 8 will make huge strides in this area, but alas it's not out yet. Fortunately the answer to the second problem is the first; it is entirely possible to build a solid, scalable, performant RESTful web service with Drupal 7 by decoupling Drupal from the web service.
Recently, Palantir.net did exactly that for a major media client, video hosting service Ooyala, and it really drove home both the power of web services and the potential of a decoupled architecture.
The ProblemOoyala wanted us to build a video curation service for one of their customers.
The first part of the problem was that the customer had data that was regularly updated, but this existing data source was incomplete, occasionally unreliable, and could be enriched with additional metadata, so human management was required before it could be used in the desired context (to describe video content in end-user-facing video-on-demand applications). The solution to this particular problem was the CMS.
The second part of the problem was getting the data in the desired context: highly interactive video-on-demand applications where users could purchase access to individual movies or episodes, collections of movies, seasons of a show, or other arbitrary groupings. The solution here was a REST API separated from the CMS.
Not complex enough? Add in a requirement to merge in data from a third-party video service to compensate for incomplete data.
Károly Négyesi: PhpStorm debugging is indispensable
I was given a problem: the (somewhat usual) error message showed up Warning: Invalid argument supplied for foreach() in element_children() (line 6396 of common.inc).. Trying to debug it with the usual print-and-see is entirely and totally hopeless. If you print just $elements from element_children? You get picture. If you try to print the backtrace? It's impossibly big. One hope is printing the backtrace with DEBUG_BACKTRACE_IGNORE_ARGS and then manually opening up every step in the rather big backtrace. Or you can set a conditional breakpoint on the problematic line with !is_array($elements) as a condition and immediately have access to the backtrace in a very nice structured/collapsed format where you can see the parent, grandparent etc render arrays, reach every caller with one click and eventually find this in a template:
<?php foreach ($content as $key => $item): ?>
<?php print render($item); ?>
I have worked for years without a debugger -- finding this without is really frustrating and slow. Finding it with one is a matter of minutes. And PhpStorm debugger is literally zero config.
4Sitestudios.com Drupal Blog: Inventing the future of… websites.
You know how every box of LEGO® comes with that pretty picture on the front of what it’s supposed to look like at the end...and how you might build it that way once, just once, to see how it looks, before tearing it down and making a spaceship out of the oxcart? It’s the same with websites. We all start off with this great picture in our mind of what a website will look like. And yes, the website might actually make it to that glorious utopia...until someone decides, no, they don’t actually like that thing there. No, this should be bigger. Or smaller. “I know I asked for an oxcart, but please tear it down and make a spaceship out of it.”
At 4Site, when we go about ‘designing’ a website, we think of the website as a sum of parts--planning ahead to how the site’s going to look at the end, how it’s going to feel. It’s not just a set of fields that then get some css (or scss!) and js/php applied. It’s something that’s eventually going to be touched by dozens, hundreds, thousands of people, both as users and as content managers behind the scenes. It’s something that needs to be flexible. Something that can move on the fly, something that can be used on a wide-variety of platforms, in a variety of uses, by a variety of users. Something easy. Something modular.
Like LEGO®.
That’s the beauty of Drupal and other modular CMS. You can take these pieces and make damn near anything out of them. So where is this metaphor leading? You need a great workflow to start, a great system to work within. You need your giant tub of pieces.
Once you have your basic “what do we need?” question answered, you can expand on what else you might want. The beauty of Drupal is that you have this extraordinarily flexible system--you can modify your content types on the fly. You can add taxonomies if you want to suggest related content to users. Your layouts are flexible, so you can use them to organize all types of content, albeit with a few minor tweaks. Add some fields to your content types and you can build a brand new view. Add some taxonomy terms and you can link your leaders together and allow them to connect with people that share the same interests.
The point of this is that you need the pieces first. To build a spaceship, you need to start with the 4x4 squares, the crystal cylinder things, and the LEGO® head with the 70s hair. It’s the same with websites. Karen McGrane says to use chunks, not blobs. So you break down your content into consistent and logical pieces. And that will give you the most flexibilty on the back end to organize and display that information, for different audiences, on different platforms, and over time as your needs evolve.
What don’t you want to do? You don’t cram every last bit of information you have into a WYSIWYG, because if you need it later, too bad, you’re writing it again. That would be akin to gluing your LEGO® together. If you ever want to use those pieces for anything else, too bad.
If you had a custom field or post type, you’ve got that piece already at your fingertips, ready for use wherever and whenever you want. You need that information later? No worries, it’s a custom post type. It’s a taxonomy reference. It’s right there in front of you. You decide you want your author on something else? It’s a term reference. An entity reference. A node reference.
So go build your castle or spaceship, your saloon or alien moon-base. Just make sure you have your big tub of pieces first, in case you decide later you want to add a mean laser cannon on the top. Or a Mars rover. I don’t know. You're the designer.
We just provide the pieces.
This blog post is an extrapolation of a session I presented at FuseCon 2014. Please let us know if you'd like any help sorting out your content into manageable, reuseable pieces.
Drupal Watchdog: Testing, Testing, One... Two... Three...
The Drupal community's commitment to cooperation and sharing is one of its defining characteristics, and the Drupal Extension to Behat and Mink is a powerful example of that cooperation in action. It is not a Drupal module. Rather, it extends the functional testing framework of Behat and Mink in order to provide Drupal-specific functionality. You'll find its detailed documentation at Read the Docs.
The extension helps site builders automate tests for Drupal 6, 7, and 8 without having to write custom code for common Drupal features. It currently provides support in three major areas: setting up test data, mapping page regions, and auto-discovery of Behat tests provided by modules and themes.
Setting Up Test DataTo test any Drupal site, at some point you'll need to set up test data. You can do this in a blackbox fashion, using pre-built steps to create a user – and log in via the interface – then fill out the appropriate form. This approach takes time to write, time to run, and becomes tedious to read. Adding data in this detailed way is warranted at times, but you're typically better off inserting data as a single step in the Given section of your scenario. The Drupal extension provides a driver system to help you.
BlackboxThe default driver assumes you have no privileged access to the Drupal site. All your data setup has to take place through the normal user interface. The blackbox driver exists so you can benefit from other Drupal Extension features.
Drupal APIWhen your tests run on the same machine as your Drupal installation, you can use the Drupal API directly to create users, nodes, taxonomy vocabularies, and taxonomy terms, without writing any supporting PHP code and without the tedium of blackbox steps. To do so, you configure your testing instance to point at the local path to the Drupal site, tag the scenario with @api, and then use pre-built steps.
@api Scenario: Given I am viewing “article” node with the title “Drupal API”This will:
Clemens Tolboom: Extending a Widget for numeric fields.
number field.
IXIS: The Amsterdam Sessions 2014
With the 2014 European Drupal conference fast approaching, the Ixis team members attending this year have scoured the schedule for their must see see sessions this year, and why.
For the Developers
Content Staging in Drupal 8 (Wednesday 10:45) - moving content about from dev to production has always been a huge pain in Drupal, so hopefully we'll get a chance to see how this might work in Drupal 8 and finally put an end to the question of when and where the client should start adding their conent during the development phase.
DrupalCon Amsterdam: DrupalCon for Frontend developers
DrupalCon Amsterdam is less than one month away! I'm excited to meet up with all the Frontend developers who are coming to learn new things from each other.
Ruben and I have worked really hard as chairs of the Frontend track. We defined the track theme Futuristic Tools and Techniques. We aimed to select the right sessions with the best variety and balance that also flow together into one cohesive track.
The State of FrontendWe wanted to kick off the track with a big keynote-style history lesson and insight into the future of Frontend development. Have you ever felt overwhelmed by the ever-changing evolution of front-end development? Me to. After David and Brian's excellent session at DrupalCon Austin, My brain is Full, we really wanted them to continue that theme and aim for something bigger.
David and Brian are also working really hard to create an introduction to the entire track, pointing signposts towards other sessions in that track that can fill in more in-depth knowledge about particular subjects. I would encourage everyone with an interest in Frontend development to attend the session if only to better understand which sessions in the Frontend track are right for them.
We also have a few session that compliment and feed in to each other. Here are a few sessions we think work really well together.
Managing Complex Projects with Design Components & Layout Design Patterns & GSS - The CSS Layout System that's 2 Generations AheadJohn Albin led the initiative to bring OOCSS-style CSS standards into Drupal 8, so I'm inclined to say he knows a thing or two in this area. Managing Complex Projects With Design Components, is a great introduction to to whys, hows, and gotchas of writing better CSS.
After you know your component variants from your component modifiers (spoilers!), you can take a really deep dive into another color of the SMACSS rainbow with Layout Design Patterns. I really like the structure of this walk, that covers the foundations of CSS layouts, grid systems, and implementation in Drupal.
You think you know layouts? Maybe you think flexbox is cool? Prepare to get your *mind blown* by Alan Burke in GSS - The CSS Layout System that's 2 Generations Ahead. A grid system that is unlike any other.
*I've been informed that the Drupal Association™ does not encourage nor condone the projection or discharge of any grey matter. Goggles are not provided and any stain susceptible clothing is worn at the attendees own risk.
Getting a Clue at the Command Line & Automated Frontend TestingAs a designer/front-end dev, I've never had a formal education on the command line, it's always been something I've picked up as I've needed it. It used to scare me. I'm so happy Emma Jane is talking on the command line in Getting a CLUE at the Command Line in the same vein as her introduction to Git at DrupalCon Prague last year. The command line is an immensely powerful and productive tool and I'm looking forward to picking up a few tips.
Now that you no longer fear the command line, you'll definitely be better equipped to take in Chris's session Automated Frontend Testing. He's already told me that he won't hold back, and I know he has little fear for live demos. This session is going to be jam packed with useful information on how to keep your Frontend looking good and loading fast, using some automated scripts.
We also have some great sessions on some really focused areas. I can't imagine walking out of any of these sessions without my brain sparkling with new knowledge and ideas.
Getting Content to a Phone in less than 1000ms1000ms. The holy grail of performance. Can it be done? Or is it just fantasy?
I'm really glad Ian submitted this talk. It's great to have a performance talk with a focused goal. Performance is still as important as ever.
The future of Drupal and CSSHTML5 and CSS3 is so last decade. No one wants your border radius any more. If you hate the idea of trawling through W3C specifications then this is a good talk for you. Preston presents another forward facing talk that we can also make use of today, a nice roundup of where browser technology is heading.
If you love the idea of trawling through W3C specifications then I can't help you.
Building Modern Web Applications with Ember.js and Headless DrupalEmber.js is an excellent framework with a vibrant community. There are many frameworks out there and Ember.js is only one of them, but we felt it's important for DrupalCon to be introducing new perspectives and ideas. I'm really glad Mikkel is covering both sides of an Ember.js project using Drupal 7 or 8.
--
Lewis Nyman (LewisNyman)
DrupalCon Amsterdam Frontend Track Chair
Drupalize.Me: Unravelling the Drupal 8 Plugin System
Plugins play an important role in Drupal 8, and understanding how the entire plugin system works will help us better understand how, when, where, and why we use plugins.
Matthew Saunders: Anatomy of a Drupalcamp - Tasks and Timing
This is the second post in my Making A Drupalcamp Happen series. I've been involved in camps for about 7 years and recently was the main project manager for Colorado. The first post was around tools, coordination and management. This post is really focused on tasks and when they need to be done to not go crazy.
There are certain things that need to happen every year. The earlier you can sort them out, the easier things will be as you approach the deadline of your event. So, I've listed some tasks below along with some rough timing and notes on some of the items. This is by no means an exhaustive list and the timing might be a little off on tasks, but I think it does give a sense of task, scope, and order.
drupaldrupalcampevent planningtasksAcquia: Help Adam and Angie build the Drupal Module Upgrader!
This week: Meet Adam "phenaproxima" Hoenich! Learn what the Drupal Module Upgrader can do for you! And what you can do for it! Come to Webchick's BoF at DrupalCon Amsterdam! Contribute!
Mediacurrent: Death to Field Arrays!
KnackForge: Adding custom menu tabs and menu items to navbar
Mobile Friendly Navigation Toolbar, shortly known as navbar, is a back-port of toolbar in Drupal 8. The problem it tries to solve is pretty obvious from it's name.
Navbar is an often used module in our Drupal projects. In our recent project we were asked to develop a bunch of menus to quickly access admin pages as and when needed. Unlike Shortcuts, we want this appear dynamically like notification.
For instance, if there are any new comments awaiting approval, the menu should show up and a few more items similar to this. Thought, Navbar could be leveraged for this requirements.
This mighty developer friendly module makes this possible for any module by implementing hook_navbar(). Similar to hook_menu(), an array of menu items to be returned but in renderable array format. If you need an example, function navbar_navbar() is a good place to get started.
The menu it offers can be seen as,
- The navbar tab by its name acting as menu item (e.g. Home)
- The navbar tab on click expands to show menu item(s) it has got underneath (e.g. Shortcuts) depends on the way navbar item defined in the hook_navbar().
Example code for #1,
Blair Wadman: Why you should not always use Drupal Features for settings, and what you can use instead
The Drupal Features module covers a lot of our needs with automating the deployment of database settings for Drupal 7. It allows you to export configuration to code and nicely wrap it up as a module. This means you easily deploy your changes to the live site (or a staging site) without having to repeat the configuration changes. It also means you can apply the changes to a different site.
But using Features is not always the best approach. Even if you can export something using Features, it doesn't mean you always should. Read on to find out when it is not appropriate to use Features and what you can use instead.
Tags: Drupal Module DevelopmentDrupal DeploymentFeaturesPlanet DrupalBluespark Labs: The Business Value of DevOps in Drupal Survey
tl;dr:
We will be presenting a session on the business value of DevOps at Drupalcon Amsterdam and would greatly appreciate your response to this (very) brief survey on Drupal and DevOps from a business perspective.
The wordy version:
At the upcoming Drupalcon in Amsterdam, Adrian Rollett and I will be presenting work we did to derive the true business value of the DevOps activities within Bluespark through real life analysis. This will be a particularly useful session for those who either plan on, or are in the process of introducing devops within their organization and need some concrete arguments to help them with the process.
To measure the success of DevOps implementations within Bluespark, we developed a framework that allows us to quantify various aspects of our processes into specific business gains. We then inspected a number of different projects, analyzing a range of issues such as time logs, number of times a specific activity took place, etc. As a result we were able to quantify the efficiencies gained by implementing automated testing, continuous integration and other DevOps principles. We will be presenting this framework and the results obtained in Amsterdam.
In addition, we are seeking to get a sense of the current adoption of DevOps in the Drupal world from a business perspective. We have created a very brief survey to gather this information. This is a complementary effort to the very excellent and more technically-oriented survey that is planned (http://www.krisbuytaert.be/blog/upcoming-conferences) for a different Drupalcon session. We will of course be sharing the insights we gather with the entire community.
Many thanks in advance for your responses, and we hope to see you in Amsterdam!
Click here to fill in the survey
Tags: DrupalconDevOpsDrupal PlanetLullabot: Drupal as a Services Platform
The next issue of Drupal Watchdog features articles about Drupal as a Services Platform. Several authors in the issue and the executive editor will be sharing various perspectives on web services in Drupal and in the wider world. With hostess Amber Himes Matz and her guests Peta Hoyes, Scott Hooker, Lin Clark, and Larry Garfield.
Liran Tal's Enginx: “Oh you lazy cron!” – learning on Drupal cron issues
We’re still working with Drupal 6 at work, and we’re triggering our notifications and other cron related tasks through a small script that crontab is running, and with the help of drush at the command line. The following problem and description of the scenario we had applies to Drupal 7 too as these are pretty much close with regards to implementation.
Drupal’s cron job will most often run smoothly and without any issues, it will appear to “just work”. The reason for that is that behind the scenes, anything related to creating scheduled tasks in Drupal will have to implement hook_cron, and simply enough, not a lot of modules will be doing that. So when you first setup your Drupal application and get it to run, you’ll wrap up any issues with cron and from there it’s smooth sailing… Or not! There are practices you should be aware of when you program modules in Drupal that are not related to cron, yet can still mess it up.
So back to the story, at some point we noticed our notifications aren’t being sent out in our development environment, and because cron is responsible for running the notifications, then that’s the immediate suspect. Problem is, debugging cron isn’t that easy, mainly because Drupal will just fire off those hooks and you’ve got no idea where the culprit code is.
Search for the problem begins by checking quickly all the modules that implement hook_cron, primarily your very own and recently added modules are the prime suspects. If that yields no results, as did in my case you’re going to have to broaden the search and a good way to quickly figure out where this happens is by inspecting Drupal’s module.inc to catch the cron hook. One way of doing that is through a debugger, another quick and easy way is by using Drupal’s own watchdog (or PHP’s own errorlog) function to capture this data:
function module_invoke_all() {
$return = array();
foreach (module_implements($hook) as $module) {
$function = $module .'_'. $hook;
if ($hook == 'cron') watchdog('cron', "hit $module cron"); // add line to log in db log
…
}
}
Inspecting the information there from the change or through the debugger we’ll be able to see which cron hook last ran successfully.
I will spare the rest of the debugging process but the research led to Drupal’s own implementation of hook_cron which further led to module calls of node_invoke and node_invoke_nodeapi where it was then failing. At that point, all custom, and recent changes to anything the codebase related to hook_nodeapi revealed the culprit:
function my_module_nodeapi($op...) {
switch ($op) {
case ‘view’:
drupal_goto(”);
break;
}
}
This makes perfect sense. Nodes get loaded through the node_load() and the rest of Drupal’s hooks for the sake of handling the notifications, which in turn calls nodeapi hook all around, and having a drupal_goto() doesn’t really help drush when its running from the command line.
Lesson learned.
(adsbygoogle = window.adsbygoogle || []).push({});The post “Oh you lazy cron!” – learning on Drupal cron issues appeared first on Liran Tal's Enginx.