Promotion ended
Sorry! This promotion has now ended. But please subscribe to our newsletter, and we'll notify you of future promotions.
In this lesson we'll get started with Context by installing the module on our site, and then walking through the user interface we have to work with. We'll discuss things like conditions and reactions, and see how things are set up.
In this lesson we will discuss different use cases for when one would use Context module. We will demo a site that has a home page and a user dashboard that acts as an authenticated users home page. We will demonstrate one of the advantages of Context by placing blocks in different locations depending on which page we're looking at.
One of the key problems with the block system in core is it's very limiting. You are limited to a small set of tools for when and how to show a block. Once you lay out your blocks you are basically done—blocks can't be placed in multiple regions. Most importantly, block configurations are not exportable. With the Context module, you lay things out based on the context of your site. A block can exist in one region for one context and a different region for another. Essentially Context is a more advanced block placement form.
In this lesson we will go over one of the main reason for using Context over core blocks; exportability. Using the Features module we are able to take all of the work we do in the Context UI and export it as standalone or with other features. The advantage of this is now all of our settings are stored in code and are deployable.
In this lesson we will perform a simple operation that site builders do when using the Context module. This is not necessary, but a good idea if there are multiple people managing your site. We will disable all blocks in the block UI since we will be using the Context module to manage this part of our website. The core block UI will then only be used to manage block titles as Context does not allow for this (a disadvantage we learned about previously).
As Drupal site-builders and developers we are all very aware that Drupal 7 is not the most useful product out of the box. We constantly add modules and custom code to make Drupal do what we need. There is nothing wrong with this, in fact it is what attracts people to using Drupal in the first place. The block system that comes with core is what we get after installation as our real only means to laying "stuff" out for our website. People have done things like turning nodes into blocks, or making every block on our a site a view. These concepts work, but have a lot of draw backs for usability and performance. There are lots of layout tools to use, but this series is going to take a look at the Context and Bean modules. These two modules are really two completely different modules but when used together give us some pretty powerful options in place of Drupal's core block system.
Ready to get up to speed on current PHP tools and techniques? This week we're excited to provide to our wonderful members more new PHP videos from our partners over at KnpUniversity, a leading provider of PHP and Symfony video tutorials. All of this week's tutorials are also completely FREE!
It is claimed that "every HTML table in Drupal 8 is responsive." What this actually means is that tables in the Drupal 8 admin UI are responsive and also that in Views, if you select a Table format, you have the opportunity to prioritize columns that will hide upon reaching narrower breakpoints. The strategy that is employed is that of adding "priority" classes to table cells and a "responsive-enabled" class to the table tag. At a tablet breakpoint, the "priority-low" table columns will hide and at the mobile breakpoint, the "priority-medium" columns will also not display.
You want to learn HTML and CSS, or maybe you just need a refresher on the current state of web technology—where should you start? This is a question we get asked a lot at Drupalize.Me. Our theming and module development videos often assume that you're familiar with basic HTML and CSS, so here is a list of our favorite resources.
In this week's podcast, Episode 48: Demystifying the Sprint, Kyle Hofmeyer talks with Cathy Theys (yesct), Michael Schmid (schnitzel), and Emma Karayiannis (emma.maria).
Drupalize.Me is looking for a Drupal trainer and developer to join our team.
Sorry! This promotion has now ended. But please subscribe to our newsletter, and we'll notify you of future promotions.
We're delighted to release another installment of PHP for Beginners videos from our amazing partners over at KnpUniversity. In these video tutorials, you'll learn all about HTTP responses and requests and step-by-step, how to process a form using php and JSON. Leanna takes you under the hood of a web page, showing you what information is being passed along and how you can make use of it in your PHP script.
Recently, the biggest piece of news in the Drupal 8 world is that we are finally down to just one beta-blocker. This is really great, but what does it mean exactly? Well, in the big picture it means that we are very close to releasing a beta version of Drupal 8 for everyone to start playing with, and this is a major step towards getting the final release out the door.
In this lesson we will build our first simple context. We will create a custom block that contains copyright information. We will use Context and the "site-wide" condition to place this custom block in the footer region of our site.
This week we're releasing a new series entirely devoted to using the Drupal 7 Token API. This series covers everything you need to know about creating, exposing, and using tokens in your Drupal modules. Since tokens can be a bit confusing, we kick things off with a presentation that covers what tokens are, some history, what problems tokens solve, and the token syntax. This is followed by the Drupal 7 Tokens Site Setup lesson that walks through the specific use-case that we'll be solving for in this series and a demonstration of the end result so that if you're following along you'll know where we're headed.
Note: In the video, around 9:30, we added at the :uid
argument to the query, but did not add the corresponding portion to the WHERE clause of the query. The final query should look like the one in the code sample below.
Now that we've got placeholder tokens that we can enter into a string of text we need to provide the actual values that should be used to replace those placeholders. In this lesson we'll implement hook_tokens() in order to provide the Drupal Token API with the values that correspond to the placeholders our module provides.
Implementations of hook_tokens()
are called once for every token type that's in scope for the current string that's being processed. So, one for all user tokens, once for all node tokens, and once for all global tokens. Each time the hook is passed an array which contains all the tokens of that specific type that where found in the string being processed as well as any additional contextual information such as the current $user
or $node
object.
hook_tokens()
is expected to return an array of values for each of the tokens in question that your module is responsible for. In our case, since we added the [databasics-page:*]
and [databasics-totals:*]
tokens we're responsible for calculating and returning their value whenever they are requested.
We'll also look at using the token_find_with_prefix() function which will allow us to detect and provide values for any chained tokens. Like for example [node:view-count:last-viewed]
.
Example:
/**
* Implements hook_tokens().
*/
function databasics_tokens($type, $tokens, array $data = array(), array $options = array()) {
$replacements = array();
if ($type == 'databasics-totals') {
foreach($tokens as $name => $original) {
switch($name) {
case 'count':
$count = db_query('SELECT SUM(view_count) FROM {databasics}')->fetchField();
$replacements[$original] = $count;
break;
}
}
}
if ($type == 'databasics-page' && !empty($data['databasics_record'])) {
$record = $data['databasics_record'];
foreach ($tokens as $name => $original) {
switch ($name) {
case 'view-count':
$replacements[$original] = $record->view_count;
break;
case 'last-viewed':
$replacements[$original] = $record->last_viewed;
break;
}
}
}
if ($type == 'node' && isset($tokens['view-count']) && !empty($data['node'])) {
$node = $data['node'];
global $user;
$count = db_query('SELECT SUM(view_count) FROM {databasics} WHERE nid = :nid AND uid = :uid', array(':nid' => $node->nid, ':uid' => $user->uid))->fetchField();
$replacements[$tokens['view-count']] = $count;
// [node:view-count:last-viewed]
if ($count_tokens = token_find_with_prefix($tokens, 'view-count')) {
$record = databasics_get_record($node->nid, $user->uid);
$replacements += token_generate('databasics-page', $count_tokens, array('databasics_record' => $record), $options);
}
}
return $replacements;
}