Skip to Content

Newsfeeds

Deeson Online: PHP 5.5 Generators and Drupal

Planet Drupal - 12 September 2014 - 7:00am

PHP 5.5 introduces generator functions.  Generator functions return an object that can be iterated over - often to be used with a foreach loop, for example:

function gen_one_to_three() { for ($i = 1; $i <= 3; $i++) { // Note that $i is preserved between yields. yield $i; } }   $generator = gen_one_to_three(); foreach ($generator as $value) { echo "$value\n"; }

Which will output:

123

(Example taken from php.net).

PHP calls the generator function when it needs values - when the generator yields a value the state of the generator is saved, so it can then be resumed when the next value is required. This can lead to significant performance boosts over creating an array which only exists to be looped over as less memory is needed.

There is more detail on http://codingexplained.com/coding/php/introduction-to-php-generators.

So how can this apply to Drupal …

A render array might look like...

$wrapper = array( '#type' => 'container', '#attributes' => array( 'class' => array('class'), ), ‘item-one’ = array ( … ); ‘item-two’ = array ( … ); ‘item-three’ = array ( … ); );

The element_children function returns an array which contains the array keys of the children array elements. This breaks from the standard PHP foreach pattern where you perform operations directly on the value created by the foreach loops - I don’t think this is ideal - I had to look twice to see what was happening the first time I saw it.

Using generators, you can use a more typical php pattern - the following is equivalent to the above.

foreach(element_children_generator($variables) as $key => &$element) { ... $element[‘#example’] = ‘example’; dpm($element); ... }

As well as being a more typical PHP pattern, referencing the element within the loop is cleaner.

There are downsides to this approach too. A developer familiar with Drupal may have to look twice to see what is going on with the yield keyword. Obviously this can’t go into Drupal 7 Core (which supports php 5.2.5+), and I wouldn’t recommend it for Contrib either for the same reason. 

However since PHP 5.3 and below is EOL I think this pattern is well worth adopting in your own projects with low risk.

Read morePHP 5.5 Generators and DrupalBy Chris | 12th September 2014
Categories: Drupal

DrupalCon Amsterdam: Training spotlight: Introduction to Headless Drupal

Planet Drupal - 12 September 2014 - 5:47am

We know Drupal is an amazing platform for making websites. But did you know it’s also a world-class content API that can easily be integrated with a other technologies?

In Introduction to Headless Drupal you'll write your first Node.js application(s) and learn how to integrate Node.js's real-time wizardry into Drupal's content management magic.

Meet the Trainers from Four Kitchens

Matt Grill (drpal) Engineer at Four Kitchens
Matt taught himself HTML in 1996 while making a fansite for The Simpsons, even though he’s never actually watched the show. Matt’s interests in technology range from Arduino to automation and deployment. Matt currently maintains Is It Shaking?, a Node.js powered app for tracking and analysing earthquakes worldwide, Is It Shaking?. He has been working with JavaScript for nearly 10 years.

Michal Minecki (mirzu) Director of Technology at Four Kitchens
Mike Minecki has been building websites since 1999, and has been working with Node.js and Drupal for about a year. He has worked on www.drupalpoetry.com, a responsive web game that mimics the experience of playing with magnetic poetry on the web. He has taught Node.js in Austin and San Francisco, and has been speaking at events around the country about how to integrate Node.js and Drupal.

Attend this Drupal Training

This training will be held on Monday, 29 September from 09:00-17:00 at the Amsterdam RAI during DrupalCon Amsterdam. The cost of attending this training is €400 and includes training materials, meals and coffee breaks.

Many of our training courses, including Introduction to Headless Drupal, are nearing capacity and we will not have waitlists, so if you are planning to attend, we strongly recommend you register this week.

Register today

Categories: Drupal

20 Fun Grid Facts (Hex Grids) - by Herman Tulleken

Gamasutra.com Blogs - 12 September 2014 - 5:44am
In this post we share some of the interesting (and obscure) facts we uncover in our quest to know everything we can about grids and their use in games.
Categories: Game Theory & Design

Why Day 7 Retention is just as important as Day 1 - by Mark Robinson

Gamasutra.com Blogs - 12 September 2014 - 5:27am
In the F2P game market a lot of attention is paid to Day 1 retention, the fraction of players that return a day after install, and rightly so. In an age where it may cost $1 or more to acquire a player in the first place, focusing solely on day 1 rete
Categories: Game Theory & Design

Code Karate: Drupal 7 Entity Registration Module

Planet Drupal - 12 September 2014 - 4:57am
Episode Number: 167

The Drupal 7 Entity Registration Module makes it easy to host sign-ups or registration forms directly on your Drupal 7 website. This solution works great for event, conference, webinar, or training signup forms.

In this lesson you will learn:

Tags: DrupalDrupal 7Drupal Planet
Categories: Drupal

Tales of Terrachanics (Part 2) - by Glen Cooney

Gamasutra.com Blogs - 12 September 2014 - 4:50am
In Part 2, I discuss the specifics of our production process, and the lessons learned along the way. Contending against steep internal and external challenges, we managed to bring the game to Google Play.
Categories: Game Theory & Design

Stop Spam

New Drupal Modules - 12 September 2014 - 3:26am

The module provides some tricks to stop sending spam on your website.

Categories: Drupal

Real vs. Artificial achievements - by Dariusz Jagielski

Gamasutra.com Blogs - 12 September 2014 - 2:30am
Current trend of pushing everywhere achievements is bad method of increasing replay value. But should they be removed completely? No! In this post Dariusz talks about ways of implementing meaningful achievements.
Categories: Game Theory & Design

TurboGrafx: The Personal Story - by Christian Nutt

Gamasutra.com Blogs - 12 September 2014 - 12:57am
I wrote that giant history, but here's my personal take.
Categories: Game Theory & Design

Ctools Plural String

New Drupal Modules - 11 September 2014 - 11:33pm

The module provides a panel pane that displays plural string (including count of items string).

An example of using the module:

  • Display the number of comments
  • Proper display of the calendar day

Note: Panel pane is in the miscellaneous tab.

Categories: Drupal

2D games: Shoot photos to make better & cheaper art (Part 2) - by Junxue Li

Gamasutra.com Blogs - 11 September 2014 - 11:31pm
This series of posts are about shooting good pictures for 2D game art production. This post is Part 2.
Categories: Game Theory & Design

Country Field

New Drupal Modules - 11 September 2014 - 10:50pm

This module allows you to add a field to select a country. Useful for enityforms module.

Categories: Drupal

Tripal BLAST UI

New Drupal Modules - 11 September 2014 - 2:31pm

This module provides a basic interface to allow your users to utilize your server's NCBI BLAST+.

Categories: Drupal

Commerce Fixed Quantity

New Drupal Modules - 11 September 2014 - 1:50pm

Changes the quantity input field on add to cart forms to a select drop-down for fixed quantity steps, so for example a client can only order 1 to 10 times 12 of a product: 12, 24, 36, (etc) of a product. Quantity steps are set from a field on the product so it can differ per product.

To be released october 2014.

Categories: Drupal

Commerce Pricelist

New Drupal Modules - 11 September 2014 - 1:36pm

Set prices on products from several pricelists. This is common in B2B.

Pricelists can be assigned per role and per user.
Price list rows can apply based on quantity or order date.

So for example user 0 can have one price for product A if ordering less than 10 and another price above 10, and this discount only applies until some date. User role wholesale customer can have other prices than anonymous users and so on.

Categories: Drupal

Drush.Recipes Service

New Drupal Modules - 11 September 2014 - 11:25am

These are the modules, recipes and features used for setting up your own http://drush.recipes style web service.

These modules by them self probably aren't useful. You can build you own working drush.recipes style web service by cooking the recipe.
drush cook http://drush.recipes/sites/default/files/recipes/drecipe_uploads/drush_recipes_service_0.drecipe

Categories: Drupal

RPG design: Alternatives to magic points

Social/Online Games - Gamasutra - 11 September 2014 - 10:37am

"I find many implementations pretty tedious (buying/using MP restorative items constantly, or saving all magic for the boss), but preferences aside, it's just plain boring when so many games do the same thing." ...

Categories: Game Theory & Design

Drupal Module Development Helper

New Drupal Modules - 11 September 2014 - 10:30am

This was a personal collection of handy functions to help in Drupal Modules Development... but I decided to put everything in a more organized new module.

Categories: Drupal

Drupal Watchdog: Cooking Up Sites With Open Outreach

Planet Drupal - 11 September 2014 - 10:25am
Article

Drupal distributions can be a huge leg up in building a website, especially for those with little technical knowledge. The “ingredients” (modules) you need are already assembled, leaving you with just the task of stirring it up, and perhaps adding your own personalizing flavors. The Open Outreach distribution is specifically designed for nonprofit and grassroots groups. It comes with a wide range of apps — bundles of modules and configurations that are geared to the needs of groups, such as contact management or mapping. It also includes a number of helper features, such as a text editor, commenting, and social media handling.

For more detailed instructions on how to work with Open Outreach, see the complete user documentation.

Below you’ll find some recipes for whipping up a specific kind of Open Outreach site, giving you the apps you need: to enable; required configuration; suggested themes for the look and feel of your site; and tips on customizations to take your site further. Happy site building!

Environmental group focused on mining impacts

You’re a board member of this small but enthusiastic group. You’ve been tasked with creating a website that will serve as the public face, but more importantly also track membership contacts as well as your contacts with other groups, government bodies, and industry.

Categories: Drupal

Lullabot: Finding related content faster with Apache Solr

Planet Drupal - 11 September 2014 - 10:00am

We recently fixed a performance issue at the MSNBC project: the More Like This list of content related to the current page was stressing our database servers with slow, complicated MySQL queries. Here is a screenshot of the block in question:

Categories: Drupal
Syndicate content


Google+
about seo