Planet Drupal

Subscribe to flux Planet Drupal
Drupal.org - aggregated feeds in category Planet Drupal
Mis à jour : il y a 22 min 45 sec

Leopathu: Create a custom Twig filter in Drupal 8

mar, 10/05/2016 - 22:06
Twig can be extended in many ways; you can add extra tags, filters, tests, operators, global variables, and functions. You can even extend the parser itself with node visitors. In this blog, I am going to show you how to create new custom twig filters in drupal. For example we are going to create a filter to remove numbers from string, will explain with hello_world module. Create hello_world folder in modules/custom/ folder with the following files,
Catégories: Elsewhere

Jeff Geerling's Blog: Thoughts on the Acquia Certified Developer - Drupal 8 Exam

mar, 10/05/2016 - 21:21

Another year, another Acquia Certification exam...

I'm at DrupalCon New Orleans, the first North American DrupalCon since the release of Drupal 8. In addition, this is the first DrupalCon where the Acquia Certified Developer - Drupal 8 Exam is being offered, so I decided to swing by the certification center (it's on the 3rd floor of the convention center, in case you want to take any of the certification exams this week!) and take it.

Catégories: Elsewhere

LevelTen Interactive: LevelTen and Dries Keynote at DrupalCon New Orleans 2016

mar, 10/05/2016 - 18:37

The LevelTen Team takes New Orleans! Read through our Twitter feed as we experience the opening ceremony of #DriesNote with the Drupal Community.

[View the story "Dries Note at DrupalCon New Orleans" on...Read more
Catégories: Elsewhere

Four Kitchens: Web Chefs Wild at DrupalCon 2016

mar, 10/05/2016 - 18:11

The Four Kitchens gang has landed— #4KNOLA! …

Catégories: Elsewhere

Danny Englander: Drupal 8 Theming Tutorial: How to Craft Custom Theme Hook Suggestions and Templates

mar, 10/05/2016 - 16:46

I've been theming with Drupal since version 6 back in 2009. In the intervening years, I've seen a lot of changes of how theming and front-end development is approached and have tried to keep up with the latest trends and adhere to best practices. Drupal 8 takes theming to a whole new level; it feels elegant, freeing, uniform, cohesive, and logical. So there's a lot to get excited about here.

In Drupal 8, there's templates for just about anything and with Drupal 8's new theme hooks, you can really narrow in on crafting a custom template for your specific use case. This makes getting at and altering markup far more accessible than it was in Drupal 6 and 7.

My preferred method for Drupal 8 theming is using Classy as my base theme, creating a sub-theme off of that and then overriding the parts that are necessary. An override is as simple as copying one of Classy's 100+ templates into your Classy based sub-theme. Sometimes, an out of the box template is not enough so you can create your own theme hook in that case.

In this post, I'll help you get started with creating Drupal 8 custom theme hook suggestions and templates. I also refer to various tools that I use, you can read more about them in my article, Drupal 8 Development: 5 Things to Add to Your Theming Toolbox.

Overview

The goal for this tutorial is to create a theme hook and subsequent template for a group of block regions in our site. The regions are called postscript_one, postscript_two, and postscript_three. The Drupal API function we will use for this is hook_theme_suggestions_HOOK_alter where "HOOK" is the name of the theme hook that we see in our Twig debug area. So essentially, we'll grab this theme hook and make a template suggestion for an array of these regions.

Getting Started

To start off, I'll place a block in one of my postscript regions and then examine the placed block with Web Inspector. Here is what I see when we do that:

<div class="postscript"> <!-- THEME DEBUG --> <!-- THEME HOOK: 'region' --> <!-- FILE NAME SUGGESTIONS: * region--postscript-second.html.twig x region.html.twig --> <!-- BEGIN OUTPUT from 'themes/custom/hibiscus/templates/layout/region.html.twig' -->

From the above, we see the theme hook name, region as well as a two template suggestions. What I am after here is a common region template for any of the the three postscript regions that I mentioned earlier. Time to fire up Devel Kint and see what we can learn by inspecting the region array. For this, I will initiate my theme hook function in my theme's .theme file. Of note is hibiscus, my Classy sub-theme theme name and the HOOK, "region".

/** * Implements hook_theme_suggestions_HOOK_alter(). */ function hibiscus_theme_suggestions_region_alter(&$suggestions, $vars, $hook) { }

Now I'll enable kint() as kint($vars);:

function hibiscus_theme_suggestions_region_alter(&$suggestions, $vars, $hook) { kint($vars); }

After I run drupal cr all using Drupal Console, I'll now see kint print out the region array on my page. As you can see from the below image.

Construct the theme hook

Using Kint search, we can search for and copy the path for the region name definition, $var['elements']['#region'] It is from this that we will construct our array of regions and subsequent theme hook. First I define the region name variable from the above:

$region = $vars['elements']['#region'];

Now I'll define an array of my three regions:

$region_postscript = array( 'postscript_first', 'postscript_second', 'postscript_third', );

Next I construct an if statement to make the actual theme suggestion:

if (in_array($region, $region_postscript)) { $suggestions[] = 'region' . '__' . 'postscript'; }

What this does is say, if it's any of the three postscript regions, create a theme hook that's common to all these regions.

Putting it all together

Putting the entire function all together, we now have:

/** * Implements hook_theme_suggestions_HOOK_alter(). */ function hibiscus_theme_suggestions_region_alter(&$suggestions, $vars, $hook) { // Define a variable for the #region name. $region = $vars['elements']['#region']; // Define an array of our postscript regions. $region_postscript = array( 'postscript_first', 'postscript_second', 'postscript_third', ); // If we are in any of these regions, create a theme hook suggestion. if (in_array($region, $region_postscript)) { $suggestions[] = 'region' . '__' . 'postscript'; } }

Now that I have written my theme hook, I can clear cache and reload the page to see my new theme hook suggestion in action.

<!-- FILE NAME SUGGESTIONS: * region--postscript.html.twig * region--postscript-second.html.twig x region.html.twig

We now see out new template suggestion from our custom theme hook, region--postscript.html.twig. This template would be common to all three regions so we can alter or update the markup in this new template as well as add classes as we see fit. Since I have a Classy sub-theme in my case, I copy Classy's region.html.twig and rename it to the new name within my own sub-theme folder structure. Of course if you are using stable as your base theme, you would do the same thing copying stable's template of the same name.

Summary

This is just a basic example to show what's possible with creating Drupal 8 theme hooks and template suggestions. Hopefully you can see that it's really useful and should come in handy for themers.

Tags 
  • Drupal Planet
  • Drupal
  • Preprocess
  • Drupal 8
  • Twig
  • Theming
Resources 
Catégories: Elsewhere

OSTraining: Drupal 8 console & Composer faster site development

mar, 10/05/2016 - 14:53

One of our OSTraining members asked what was the best way to install composer to manage dependencies.

While composer can be used to add module dependencies into drupal. It's more practical for DrupalConsole to handle the process. Console automatically passes the requests to composer. 

From the terminal command line running the following commands will install both Console and Composer together.

Catégories: Elsewhere

Web Wash: How to Create a Search Page in Drupal 8

mar, 10/05/2016 - 14:24

Building a search page isn't as straight forward as you'd think. At first a client will want something which users can search content, then they may want to modify the search results or even change the ranking of certain content. Long story short, something you thought would be as simple as enabling a module, ends up taking twice as long.

If you need to create custom search pages in Drupal 7, more often than not, you use [Search API](https://www.drupal.org/project/search_api) or create a [search page using Views](https://www.webwash.net/node/84). But the core Search module for Drupal 8 has become more powerful than in Drupal 7. One of the big changes, for site builders, in Drupal 8 is the ability to create custom search pages.

However, there're a few limitations to creating a search page. First, it'll have a prefix of "search/" in front but the full URL can be changed by creating a URL alias. Second, you can only adjust the content ranking on these pages. If you want to index extra fields or remove ones from being indexed, you'll still need [Search API](https://www.drupal.org/project/search_api) to do this.

In this tutorial, you'll learn how to create a custom search page and how to modify the search results by overriding a template.

Catégories: Elsewhere

Drupal core announcements: Core topic discussions at DrupalCon New Orleans

mar, 10/05/2016 - 14:12

DrupalCon New Orleans includes a full track of core conversations where you can learn about current topics in Drupal core development and participate in shaping Drupal's future.

In addition to the core conversations, we have a few meetings on specific topics for future core development. These meetings will be very focused, so contact the listed organizer for each if you are interested in participating.

Time Topic Organizer Tuesday May 10, 10:00a-12:00p Content Workflow dixon_ Thursday May 12, 12:00p-2:00p REST/API-first improvements prestonso Thursday May 12, 4:30-6:00p Theme component library Wim Leers Friday May 13, 11:00a-12:00p Migrate critical triage (round 2) mikeryan Friday May 13, 12:30p-2:00p Blocks and Layouts tim.plunkett

Also be sure to watch Dries' keynote for ideas about Drupal's future!

Catégories: Elsewhere

Blair Wadman: Resolving "Fatal error: class not found" in Drupal 7

mar, 10/05/2016 - 11:18

You have gone through your regular module update routine and cleared the cache. Suddenly you are presented with a PHP Fatal error, because a class can’t be found. Your Drupal site won’t load and you can’t run Drush commands. All you get is the fatal error blocking the site.

If you get a fatal error like above where a class is not found, a likely cause is that the Drupal registry has the old path for the class. A cache clear should update, but sometimes it all goes a bit wrong. The solution is to rebuild the registry. This will update the registry table with the new file locations. Read on to find out how...

Catégories: Elsewhere

Web Omelette: Query for nodes which reference multiple terms in Drupal 7

mar, 10/05/2016 - 09:05

Have you ever needed to run a custom query that returns all the nodes which reference two or more taxonomy terms? I have, and most of the time it was very simple because the requirement was for nodes which reference either term, rather than ALL the terms.

When we are dealing with an OR type of select query, it couldn't be easier:

$query = db_select('node', 'n'); $query->join('taxonomy_index', 'ti', 'ti.nid = n.nid'); $query->condition('ti.tid', array(1, 2)); $query->fields('n', array('nid')); $result = $query->execute();

The above example keeps things simple by assuming the term reference maintains an index in the taxonomy_index table and that we already have our term IDs.

Things get a bit more complicated when we are trying to query the nodes which reference both term 1 AND term 2. After banging my head against the wall for a bit, I came up with a solution inspired by how Views generates its query:

$tids = array(1, 2); $query = db_select('node', 'n'); foreach ($tids as $key => $tid) { $query->innerJoin('taxonomy_index', 'ti_' . $key, 'ti_' . $key . '.nid = n.nid AND ti_' . $key . '.tid = ' . $tid); } foreach ($tids as $key => $tid) { $query->condition('ti_' . $key . '.tid', $tid); } $query->fields('n', array('nid')); $result = $query->execute();

So basically the solution is to create a join for each term ID we want to filter by. A crucial part of this is that the join needs to happen on the node ID between the two tables (as expected) but also on the term ID we are using for the filter matching the record in the taxonomy_index table. This will ensure that the two joins are not the same but that they reflect the relation between the node record and each individual term ID. Are you still following? Then, we just add our conditions on the newly created joins.

Caveats

This should work, and depending on the size of your dataset, it should not have too much of a performance impact. However, as no joins should be done if not absolutely necessary, investigate the possibility of querying for the nodes that reference the first term and then filtering the rest out using PHP. This can be a viable option if you know that usual result sets are not too big so you are not running array_filter() on 2000 terms. And of course, when possible, cache the query appropriately.

Catégories: Elsewhere

Virtuoso Performance: DrupalCon NOLA - food, music, sprint (rinse and repeat)

mar, 10/05/2016 - 05:24
DrupalCon NOLA - food, music, sprint (rinse and repeat)

My apologies for those skipping through the travelogue to get to the Drupal... Or skipping through the Drupal to get to the travelogue. If I do my usual (painfully) painstaking editing job my DrupalCon posts will come out in July, so I'm settling for a chronological stream-of-consciousness here for the sake of timeliness.

Saturday was a long day - hopped onto the City of New Orleans in Carbondale just a little shy of 2am, slept only fitfully on the train, after 13 hours of sitting in the train decided to walk from Amtrak to my hotel on Esplanade (38 minute estimate on Google maps), missed a turn and the modified route took me by Café du Monde (damn, forced to stop for beignets and an iced cafe au lait, life is tough;)

Lamothe House courtyard

I've been to New Orleans three times before, always at Jazz Fest time. Always a great time - but after several hours wandering around the fairgrounds (often ankle deep in mud), or pitching in on rebuilding on non-fest days the last couple of trips, I never had energy left for the music clubs. I decided to rectify that this time, taking a room at Lamothe House on Esplanade, convenient to the Frenchmen Street scene.

Glen David Andrews and friends

Despite a long travel day, I caught a second wind and went out that night, having dinner and a few drinks at Three Muses. Really nice little place - had an excellent meat & cheese platter at the bar, and sampled a few of their cocktails (I know Sarah would have loved The Muse if she were here, but I favored the Spaghetti Western). I caught three sets of Glen David Andrews, lots of fun - three brass (tuba, trumpet, and the leader on trombone) with a pianist trying his best to be heard (no amplification).

Stepping back out onto Frenchmen Street, I was greeted by a classic street band at the corner of Chartres, really solid and tight and putting on quite a show. As I write this Monday night, I can hear them clearly from my hotel room - a part of the incredible vitality of this most American city.

Corner of Frenchman and ChartresSunday sprint

After a slow start, on the way to LaunchPad for Sunday's extended sprint I stopped by the Camellia Grill (a.k.a. The Grill) at Chartres and Toulouse for an excellent sausage and cheese omelette. Now, finally, to some Drupaling...

This day was about triage. I spent the middle of the day pulling the most important issues in various categories - potential backwards-compatibility breaks, functional changes broken down to general effects, UI, and module-specific migrations, and bugs - into a spreadsheet. In the afternoon xjm, alexpott, ryan-weal, benjifisher, and I started reviewing the "Migrate critical" issues in core (that is, issues that would have a severity of Critical if the migration system were not still experimental). We got about halfway through the list - which is better than it sounds, because this list was sorted by creation date, guaranteeing that the issues that have been open for 3 years (i.e., the hard ones) came first. This was a very productive session - identifying duplicates, reclassifying and reprioritizing some issues, and doing some brainstorming on solutions for a couple of tricky ones (Invalid passwords after D7 to D8 migration and Better handle replacement of missing filters with filter_null). Six of the 14 issues we tracked in the spreadsheet are now resolved.

My second (and third) wind gone, I stuck to a little takeout - fried chicken sandwich and small chef salad from Verti Marte. The sandwich was really good, but I found the salad kind of meh (perhaps something odd in the balsamic dressing).

Monday sprint

Breakfast on a nearly-deserted Frenchmen Street, at Cafe Rose Nicaud - had the Southern Breakfast, highlighted by rosemary cheese grits and alligator sausage.

More so than the Sunday sprint, this was a chance to reacquaint with folks from the past, and put new faces to some old names - always good, and just a start with things going into full swing on Tuesday.

My first sprint task of the day was to pick up one of those migrate-criticals - verifying that the old no_stub bug had been fixed by other means. Always good to cross stuff off the list...

The bulk of my time today was spent on Refactor EntityFile and use process plugins instead - it's been a WTF for a while how the destination plugin peeks at the source plugin configuration, and vice versa. I picked up on benjy's proposed solution and came up with a patch that works with my D6 site. Basically, the idea is to take everything dealing with the physical file out of the destination plugin and put it into a process plugin named "copy_file" - the destination plugin now only has to do a couple of truly destination-plugin things, and breaking the file copying into a process plugin (oh, and also breaking the urlencode step into a process plugin) is much more flexible - this functionality can now be used anywhere a file might need to be copied, not just when creating file entities. There are a few pieces left to this for anyone who wants to help out - manual testing with D7, fixing tests to reflect the changes, and of course review - feel free to step in now, and anything not done in the next couple of days we can address at Friday's sprint.

At the tail end of the day I started looking at Migrate D6 i18n nodes, which I think should be our first priority of the remaining tasks this week. Specifically, I was trying to figure out the mysterious D7 user migration test failure. Didn't quite get there, but hopefully I'll find a little time Tuesday for that. Beyond that, my current project has a need for this functionality, so my primary role here will be giving the patch some real-world testing with that.

Topped off the day with a trip off the beaten track to Fry and Pie - if your idea of a great meal is a plate of fries smothered in stuff (like, say, chicken andouille okra gumbo and Wisconsin cheese curds) followed by a little tart-size pie, this is the place for you! Just make your way through the Hi Ho Lounge to the back patio and tell the guy at the table in the corner what you want...

Looking forward the DrupalCon starting in earnest tomorrow morning - Prenote and Driesnote, here I come!

mikeryan Mon, 05/09/2016 - 22:24 Tags
Catégories: Elsewhere

Drupal @ Penn State: Web service requests via snakes and spiders

lun, 09/05/2016 - 23:46

First off, hope you are all enjoying Drupalcon, super jealous.

Its been almost three months since I wrote about Creating secure, low-level bootstraps in D7, the gist of which is skipping index.php when you make webservice calls so that Drupal doesn't have to bootstrap as high. Now that I've been playing with this, we've been starting to work on a series of simplied calls that can propagate data across the network in different ways.

Catégories: Elsewhere

Mediacurrent: Dropcast: Episode 19 - DRUPALCON!

lun, 09/05/2016 - 23:35

The title says it all. This episode we talk to Shellie Hutchens about all the great things we will be doing in New Orleans without Mario and Bob. As usual we have the Pro Project Pick and the Final Bell, Drupal news and some great discussions around Mark’s other project, the Friday 5.

Catégories: Elsewhere

Acquia Developer Center Blog: Search Strategies in Drupal 8

lun, 09/05/2016 - 23:28

Hatching your Search strategy for Drupal 8? 

You're in luck. 

You can tap into two recent blog posts -- one new, one refreshed -- and get a good idea of the State of Search in Drupal 8. 

Tags: acquia drupal planet
Catégories: Elsewhere

Acquia Developer Center Blog: Battleplan for Search & Solr in Drupal 8

lun, 09/05/2016 - 23:14
tl;dr

Contrib Search maintainers are committed to make Drupal 8 kick ass with Search API.

Search is a massively cool technology spectrum with loads of really tough problems such as language stemming, delivering search as a site scales and helping customers actually find what they want. However, solving these is not so easy. Let’s look at the history of Search and Solr in Drupal.

Tags: acquia drupal planet
Catégories: Elsewhere

DrupalCon News: A hundred thousand welcomes from Drupal Ireland

lun, 09/05/2016 - 20:25

 

Drupal Ireland offers you a “céad míle fáilte” - a “hundred thousand welcomes”!

Come join us for DrupalCon in Dublin which promises to be a fantastic event, held right in the heart of Dublin city.

Catégories: Elsewhere

David Lohmeyer's Blog: Adding the node class to a body HTML tag in Drupal 8

lun, 09/05/2016 - 18:26

Doing some hacking at DrupalCon New Orleans and my use case is to add a node-* class to the body HTML element in Drupal 8. With the preprocess hook in D8 it looks like there is access to different variables than previously. To get the node id one has to look at the cache tags. Here's how I did it:

In mytheme.theme:

Catégories: Elsewhere

Pantheon Blog: D8 and Drupal’s Destiny on the Open Web

lun, 09/05/2016 - 17:40
I believe that the web is Earth’s most powerful communication tool. In particular I believe in the Open Web, a place of small pieces loosely joined, true to the original architecture of the internet, the philosophy of UNIX, and of HTTP as a protocol. This technology is rewriting the way humanity operates, and I believe it is one of the most positive things to emerge from the 20th century.
Catégories: Elsewhere

Third & Grove: Nat Catchpole on Three Months at TAG as a Drupal 8 Core Committer

lun, 09/05/2016 - 16:00
Nat Catchpole on Three Months at TAG as a Drupal 8 Core Committer catch Mon, 05/09/2016 - 10:00
Catégories: Elsewhere

Pages