Newsfeeds

Brussels Calendar

New Drupal Modules - 15 November 2017 - 11:42pm

Based on Event Calendar Widget of Paul Navasard (https://codepen.io/peanav/full/ulkof).

Ones installed, add a Calendar Block and edit settings corresponding your requirements.

Functionalities:

  • Gets data from a view.
  • Can use javascript function as trigger or click to navigate to the node.
  • Only supports timestamp (created, etc.). Could be improved.

"No events" information is using the translation engine ("t()").

What could be added:

Categories: Drupal

Designing ‘Organic’ Difficulty: A Cognitive Neuropsychology Approach (1: Introduction)! - by Ashton Philip Kehnscherper

Gamasutra.com Blogs - 15 November 2017 - 10:27pm
Current difficulty systems often focus on fixed metric manipulation to appease players when it comes to difficulty, but through the use of a different cognitive neuropsychology lens, can a more 'organic' method to game design and difficulty be produced?
Categories: Game Theory & Design

Paykings

New Drupal Modules - 15 November 2017 - 7:43pm
Categories: Drupal

PreviousNext: Reusable style guide components using field formatters and twig embed

Planet Drupal - 15 November 2017 - 6:32pm
Share:

At PNX, style guide driven development is our bag. It’s what we love: building a living document that provides awesome reference for all our front end components. And Drupal 8, with its use of Twig, complements this methodology perfectly. The ability to create a single component, and then embed that component and its markup throughout a Drupal site in a variety of different ways without having to use any tricks or hacks is a thing of beauty.

by Jack Taranto / 16 November 2017 Create a component

For this example we are going to use the much loved collapsible/accordion element. It’s a good example of a rich component because it uses CSS, JS, and Twig to provide an element that’s going to be used everywhere throughout a website.

To surmise the component it’s made up of the following files:

collapsible.scss collapsible.widget.js collapsible.drupal.js collapsible.twig collapsible.svg

The .scss file will end up compiling to a .css file, but we will be using SASS here because it’s fun. The widget.js file is a jQuery UI Widget Factory plugin that gives us some niceties - like state. The drupal.js file is a wrapper that adds our accordion widget as a drupal.behavior. The svg file provides some pretty graphics, and finally the twig file is where the magic starts.

Let’s take a look at the twig file:

{{ attach_library('pnx_project_theme/collapsible') }} <section class="js-collapsible collapsible {{ modifier_class }}"> <h4 class="collapsible__title"> {% block title %} Collapsible {% endblock %} h4> <div class="collapsible__content"> {% block content %} <p>Curabitur blandit tempus porttitor. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.p> {% endblock %} div> section>

This is a standard-ish BEM based component. It uses a js-* class to attach the widget functionality. We also have a {{ modifier_class }} variable, that can be used by kss-node to alter the default appearance of the collapsible (more on this later). There are two elements in this component title and content. They are expressed inside a twig block. What this means is we can take this twig file and embed it elsewhere. Because the component is structured this way, when it’s rendered in its default state by KSS we will have some default content, and the ability to show it's different appearances/styles using modifier_class.

Our twig file also uses the custom Drupal attach_library function which will bring in our components CSS and JS from the following theme.libraries.yml entry:

collapsible: css: component: src/components/collapsible/collapsible.css: {} js: src/components/collapsible/collapsible.widget.js : {} src/components/collapsible/collapsible.drupal.js : {} dependencies: - core/jquery - core/drupal - core/jquery.once - core/jquery.ui - core/jquery.ui.widget

This is a pretty meaty component so it’s got some hefty javascript requirements. Not a problem in the end as it’s all going to get minified and aggregated by Drupal Cores library system.

And there we have it - a rich javascript component. It’s the building block for all the cool stuff we are about to do.

Use it in a field template override

As it stands we can throw this component as-is into KSS which is nice (although we must add our css and js to KSS manually, attach_library() won’t help us there sadly - yet), but we want drupal to take advantage of our twig file. This is where twigs embed comes in. Embed in twig is a mixture of the often used include, and the occasionally used extend. It’s a super powerful piece of kit that lets us do all the things.

Well these things anyway: include our twig templates contents, add variables to it, and add HTML do it.

Because this is an accordion, it’s quite likely we’ll want some field data inside it. The simplest way to get this happening is with a clunky old field template override. As an example I’ll use field--body.html.twig:

{% for item in items %} {% embed '@pnx_project_theme/components/collapsible/collapsible.twig' %} {% block title %} {{ label }} {% endblock %} {% block content %} {{ item.content }} {% endblock %} {% endembed %} {% endfor %}

Here you can see the crux of what we are trying to achieve. The collapsible markup is specified in one place only, and other templates can include that base markup and then insert the content they need to use in the twig blocks. The beauty of this is any time this field is rendered on the page, all the markup, css and js will be included with it, and it all lives in our components directory. No longer are meaty pieces of markup left inside Drupal template directories - our template overrides are now embedding much richer components.

There is a trick above though, and it’s the glue that brings this together. See how we have a namespace in the embed path - all drupal themes/modules get a twig namespace automatically which is just @your_module_name or @your_theme_name - however it points to the theme or modules templates directory only. Because we are doing style guide driven development and we have given so much thought to creating a rich self-contained component our twig template lives in our components directory instead, so we need to use a custom twig namespace to point there. To do that, we use John Albins Component Libraries module. It lets us add a few lines to our theme.info.yml file so our themes namespace can see our component templates:

component-libraries: pnx_project_theme: paths: - src - templates

Now anything in /src or /templates inside our theme can be included with our namespace from any twig template in Drupal.

Use it in a field formatter

Now let’s get real because field template overrides are not the right way to do things. We were talking about making things DRY weren’t we?

Enter field formatters. At the simple end of this spectrum our formatter needs an accompanying hook_theme entry so the formatter can render to a twig template. We will need a module to give the field formatter somewhere to live.

Setup your module file structure as so:

src/Plugin/Field/FieldFormatter/CollapsibleFormatter.php templates/collapsible-formatter.html.twig pnx_project_module.module pnx_project_module.info.yml

Your formatter lives inside the src directory and looks like this:

<?php namespace Drupal\pnx_project_module\Plugin\Field\FieldFormatter; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FormatterBase; use Drupal\Core\Form\FormStateInterface; /** * A field formatter for trimming and wrapping text. * * @FieldFormatter( * id = "collapsible_formatter", * label = @Translation("Collapsible"), * field_types = { * "text_long", * "text_with_summary", * } * ) */ class CollapsibleFormatter extends FormatterBase { /** * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items, $langcode = NULL) { $elements = []; foreach ($items as $delta => $item) { $elements[$delta] = [ '#theme' => 'collapsible_formatter', '#title' => $items->getFieldDefinition()->getLabel(), '#content' => $item->value, '#style' => NULL, ]; } return $elements; } }

And the hook_theme function lives inside the .module file:

<?php /** * @file * Main module functions. */ /** * Implements hook_theme(). */ function pnx_project_module_theme($existing, $type, $theme, $path) { return [ 'collapsible_formatter' => [ 'variables' => [ 'title' => NULL, 'content' => NULL, 'style' => NULL, ], ], ]; }

Drupal magic is going to look for templates/collapsible-formatter.html.twig in our module directory automatically now. Our hook_theme template is going to end up looking pretty similar to our field template:

{% embed '@pnx_project_theme/components/collapsible/collapsible.twig' with { modifier_class: style } %} {% block title %} {{ title }} {% endblock %} {% block content %} {{ content }} {% endblock %} {% endembed %}

Now jump into the field display config of a text_long field, and you’ll be able to select the collapsible and it’s going to render our component markup combined with the field data perfectly, whilst attaching necessary CSS/JS.

Add settings to the field formatter

Let's take it a bit further. We are missing some configurability here. Our component has a modifier_class with a mini style (a cut down smaller version of the full accordion). You'll notice in the twig example above, we are using the with notation which works the same way for embed as it does for include to allow us to send an array of variables through to the parent template. In addition our hook_theme function has a style variable it can send through from the field formatter. Using field formatter settings we can make our field formatter far more useful to the site builders that are going to use it. Let's look at the full field formatter class after we add settings:

class CollapsibleFormatter extends FormatterBase { /** * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items, $langcode = NULL) { $elements = []; foreach ($items as $delta => $item) { $elements[$delta] = [ '#theme' => 'collapsible_formatter', '#title' => !empty($this->getSetting('label')) ? $this->getSetting('label') : $items->getFieldDefinition()->getLabel(), '#content' => $item->value, '#style' => $this->getSetting('style'), ]; } return $elements; } /** * {@inheritdoc} */ public function settingsSummary() { $summary = []; if ($label = $this->getSetting('label')) { $summary[] = 'Label: ' . $label; } else { $summary[] = 'Label: Using field label'; } if (empty($this->getSetting('style'))) { $summary[] = 'Style: Normal'; } elseif ($this->getSetting('style') === 'collapsible--mini') { $summary[] = 'Style: Mini'; } return $summary; } /** * {@inheritdoc} */ public function settingsForm(array $form, FormStateInterface $form_state) { $form['label'] = [ '#title' => $this->t('Label'), '#type' => 'textfield', '#default_value' => $this->getSetting('label'), '#description' => t('Customise the label text, or use the field label if left empty.'), ]; $form['style'] = [ '#title' => t('Style'), '#type' => 'select', '#options' => [ '' => t('Normal'), 'collapsible--mini' => t('Mini'), ], '#description' => t('See Styleguide section 6.1 for a preview of styles.'), '#default_value' => $this->getSetting('style'), ]; return $form; } /** * {@inheritdoc} */ public static function defaultSettings() { return [ 'label' => '', 'style' => '', ]; } }

There's a few niceties there: It allows us to set a custom label (for the whole field), it automatically assigns the correct modifier_class, it links to the correct section in the style guide in the settings field description, and it adds a settings summary so site builders can see the current settings at a glance. These are all patterns you should repeat.

Let's sum up

We've created a rich interactive BEM component with its own template. The component has multiple styles and displays an interactive demo of itself using kss-node. We've combined its assets into a Drupal library and made the template - which lives inside the style guides component src folder - accessible to all of Drupal via the Component Libraries module. We've built a field formatter that allows us to configure the components appearance/style. Without having to replicate any HTML anywhere.

The component directory itself within the style guide will always be the canonical source for every version of the component that is rendered around our site.

Tagged Twig

Posted by Jack Taranto
Front end developer

Dated 16 November 2017

Add new comment
Categories: Drupal

DrupalEasy: DrupalEasy Podcast 198 - Dave Hall - Drupal Distributions and Puppies

Planet Drupal - 15 November 2017 - 4:53pm

Direct .mp3 file download.

Dave Hall (skwashd), Managing Director, Dave Hall Consulting joins Mike Anello to talk about the current state of Drupal distributions and what the future may hold.

Interview DrupalEasy News Sponsors
  • Drupal Aid - Drupal support and maintenance services. Get unlimited support, monthly maintenance, and unlimited small jobs starting at $99/mo.
  • WebEnabled.com - devPanel.
Follow us on Twitter Subscribe

Subscribe to our podcast on iTunes, Google Play or Miro. Listen to our podcast on Stitcher.

If you'd like to leave us a voicemail, call 321-396-2340. Please keep in mind that we might play your voicemail during one of our future podcasts. Feel free to call in with suggestions, rants, questions, or corrections. If you'd rather just send us an email, please use our contact page.

Categories: Drupal

Battlefront II, Overwatch under scrutiny by Belgian gambling regulator

Social/Online Games - Gamasutra - 15 November 2017 - 4:39pm

The Belgian Gaming Commission's general director has told local media outlet VTM that the outfit is investigating whether the loot crate systems in Battlefront II and Overwatch qualify as gambling. ...

Categories: Game Theory & Design

Battlefront II dev: 'It's up to us to make sure that grind is fun and not overwhelming'

Social/Online Games - Gamasutra - 15 November 2017 - 4:10pm

"Crates can be a fun addition as long as you don't feel forced to engage with them in order to progress," a Battlefront II dev wrote on Reddit. "That's where the issue is with our game right now." ...

Categories: Game Theory & Design

Fantasy Flight Games Previews Quests in Legacy of Dragonholt

Tabletop Gaming News - 15 November 2017 - 3:00pm
So, there’s been some discussion about what, exactly, Legacy of Dragonholt. It’s not quite an RPG. It’s not quite a board game. It’s sort of in its own category. As such, you might wonder, “so, what do you do in the game?” Well, in this preview Fantasy Flight shows off what quests are like in […]
Categories: Game Theory & Design

Virtual reality training may be as effective as regular therapy after stroke

Virtual Reality - Science Daily - 15 November 2017 - 2:56pm
Using virtual reality therapy to improve arm and hand movement after a stroke is equally as effective as regular therapy, according to a study.
Categories: Virtual Reality

Tomb of Annihilation Set For Dice Masters Now Available

Tabletop Gaming News - 15 November 2017 - 2:00pm
Seems we’ve got a couple Dungeons & Dragons releases today that aren’t actually Dungeons & Dragons releases. In this case, it’s the Tomb of Annihilation set for Dice Masters. Want to get your dice-rolling on without your full group there? Now you certainly can, as you take on undead horrors (or control them, if you […]
Categories: Game Theory & Design

Valve is using Steam player data to power Counter-Strike: GO matchmaking

Social/Online Games - Gamasutra - 15 November 2017 - 1:13pm

The new system considers information from both a player's time in Counter-Strike and general behavior on Steam before placing them in matches. ...

Categories: Game Theory & Design

All Out War: Battleground Minis Game Up On Kickstarter

Tabletop Gaming News - 15 November 2017 - 1:00pm
You’ve got tabletop minis games. You’ve also got real-time strategy games. But what if you got your minis game into your real-time strategy game and your real-time strategy game into your minis game? You’d have All Out War: Battleground. If you’re a fan of original Warcraft and you’re a fan of Fantasy Miniatures Games, this […]
Categories: Game Theory & Design

Fantasy Flight Games Posts New A Game of Thrones Catan: Brotherhood of the Watch Preview

Tabletop Gaming News - 15 November 2017 - 12:00pm
Most of us have played Settlers of Catan. It might have been a while, but you might remember how scoring works. You want to build settlements and cities, build long roads, collect soldiers, that sort of thing. But how will scoring work in the upcoming A Game of Thrones Catan: Brotherhood of the Watch from […]
Categories: Game Theory & Design

Mediacurrent: Content as the Common Language of Web Development

Planet Drupal - 15 November 2017 - 11:21am

If there’s one thing I learned while attending DrupalCon Baltimore 2017 this past spring, it’s that those of us involved in building the web are only getting more and more specialized in how we help build it. It boggles the mind to witness the sheer amount of new session tracks, new technologies, new design patterns, and new discussions that come up each year at DrupalCon.

Categories: Drupal

Midweek Snippets

Tabletop Gaming News - 15 November 2017 - 11:00am
The week continues along. We’re halfway to the end. Just gotta put our heads down and power through. Not that the week’s been terrible, mind you. Just busy. Lots of things on my metaphorical plate before I get lots of things on my actual plate next week. But before we can get there, let’s snack […]
Categories: Game Theory & Design

Delta Green: Music From a Darkened Room

New RPG Product Reviews - 15 November 2017 - 10:20am
Publisher: Arc Dream Publishing
Rating: 5
This adventure begins with the party being asked to investigate the mysterious death of a veteran Delta Green agent (and FBI agent) in a suburban house that has a bad reputation in the neighbourhood - their task is to determine if the house itself poses a threat. The local coroner has pronounced him a suicide, and other Delta Green agents in the FBI worked to maintain this as the official story, but the organisation has doubts and wishes to know the truth... but not for it to get out. The locals feel the same way, so this is an investigation that must be carried out discreetly.

There's a What's Going On section that gives you the low-down on the house, its history and what is actually happening there: a sad story spanning over an hundred years. There are various avenues of enquiry that the party can follow, and masses of information to enable you to give appropriate responses as they investigate. The main strands that they can pursue include the house itself, official records, talking to the locals, and researching the history of the house... and of course they may choose to do all of these or more. It's well to be really familiar with the material before the game, and to keep in mind the consequences of what they do and - even more importantly - how they choose to go about it. They should find it quite easy to attract attention, and there are notes to aid you in ensuring that it's the wrong kind of attention!

It is an atmospheric and almost claustrophobic tale of small-town America. Visiting the house itself, which curious party members are almost certain to do, is a terrifying and potentially deadly experience. Play this up... it's enough to give the players nightmares if done right, never mind their characters. There are ways to clear things up, but most of the options are obscure and you may have to give even competent investigators a few hints. Suggestions are made as to how to do this, and not all the methods are successful, even if the very high price that must be paid. Overall it's an excellent creepy haunted house scenario that should haunt your group long after you have played it!
Categories: Game Theory & Design

Dog Might Games Posts New Countdown: Action Edition Preview

Tabletop Gaming News - 15 November 2017 - 10:00am
Countdown: Action Edition brings the excitement of 80s action movies to your tabletop. While most of the positions in the game are randomly determined, one player will always be the Action Hero. That player will be the final arbiter in discussions and act as a GM, of sorts, for the game. White jacket with huge […]
Categories: Game Theory & Design

Andrana Project Social Deduction Game Up On Kickstarter

Tabletop Gaming News - 15 November 2017 - 9:00am
The worlds of the digital and the real are merging more and more every day. Hell, I “work online.” Most of us have little devices in our pockets that are what just 20 years ago would be considered supercomputers. It’s only natural that this blending happens in the gaming world, too. Andrana Project is a […]
Categories: Game Theory & Design

Drupal blog: An update on the Layout Initiative for Drupal 8.4/8.5

Planet Drupal - 15 November 2017 - 8:39am

This blog has been re-posted with permission from Dries Buytaert's blog. Please leave your comments on the original post.

Now Drupal 8.4 is released, and Drupal 8.5 development is underway, it is a good time to give an update on what is happening with Drupal's Layout Initiative.

8.4: Stable versions of layout functionality

Traditionally, site builders have used one of two layout solutions in Drupal: Panelizer and Panels. Both are contributed modules outside of Drupal core, and both achieved stable releases in the middle of 2017. Given the popularity of these modules, having stable releases closed a major functionality gap that prevented people from building sites with Drupal 8.

8.4: A Layout API in core

The Layout Discovery module added in Drupal 8.3 core has now been marked stable. This module adds a Layout API to core. Both the aforementioned Panelizer and Panels modules have already adopted the new Layout API with their 8.4 release. A unified Layout API in core eliminates fragmentation and encourages collaboration.

8.5+: A Layout Builder in core

Today, Drupal's layout management solutions exist as contributed modules. Because creating and building layouts is expected to be out-of-the-box functionality, we're working towards adding layout building capabilities to Drupal core.

Using the Layout Builder, you start by selecting predefined layouts for different sections of the page, and then populate those layouts with one or more blocks. I showed the Layout Builder in my DrupalCon Vienna keynote and it was really well received:

8.5+: Use the new Layout Builder UI for the Field Layout module

One of the nice improvements that went in Drupal 8.3 was the Field Layout module, which provides the ability to apply pre-defined layouts to what we call "entity displays". Instead of applying layouts to individual pages, you can apply layouts to types of content regardless of what page they are displayed on. For example, you can create a content type 'Recipe' and visually lay out the different fields that make up a recipe. Because the layout is associated with the recipe rather than with a specific page, recipes will be laid out consistently across your website regardless of what page they are shown on.

The basic functionality is already included in Drupal core as part of the experimental Fields Layout module. The goal for Drupal 8.5 is to stabilize the Fields Layout module, and to improve its user experience by using the new Layout Builder. Eventually, designing the layout for a recipe could look like this:

Layouts remains a strategic priority for Drupal 8 as it was the second most important site builder priority identified in my 2016 State of Drupal survey, right behind Migrations. I'm excited to see the work already accomplished by the Layout team, and look forward to seeing their progress in Drupal 8.5! If you want to help, check out the Layout Initiative roadmap.

Special thanks to Angie Byron for contributions to this blog post, to Tim Plunkett and Kris Vanderwater for their feedback during the writing process, and to Emilie Nouveau for the screenshot and video contributions.

Categories: Drupal

myDropWizard.com: Agencies: Don't keep passwords in your wiki!

Planet Drupal - 15 November 2017 - 8:16am

You spend so much time writing secure code, and doing security updates, but you're putting all of that in danger with your wiki. A huge percentage of agencies put passwords into wikis - and other shared resources!!!

Using a shared Google/Office document, spreadsheet - even with black text on a black background - isn't much better! So, think of "wiki" in this context as being any "low-cost, low-security, high-accessibility, super-convenient storage."

You are putting your agency AND your customers at risk by keeping passwords in your company wiki!

Read more to find out why, and a better way to do it!

Categories: Drupal

Pages

Subscribe to As If Productions aggregator