Drupal Feeds

Miles Carter: Drupal views templating tutorial: Outputting the respective image fields of multiple associated taxonomy term references

Planet Drupal - Sun, 2014-07-13 23:50

Courtesy of - Miles J Carter Photos on the Web Blog
Source URL : Drupal views templating tutorial: Outputting the respective image fields of multiple associated taxonomy term references

Using a custom field template to output taxonomy term references as their respective image fields, rather than as text or a link output

The ingredient icons are term reference fields formatted to output as their respective image fields, rather than as a link or text

The example situation is where a view displays a list of nodes or fieldable entities, for our example items on a menu, and each of these has one or more taxonomy term references, in this example the main ingredients. While it’s simple to output the term references as plain text or a link, showing an image or other field attached to the term reference instead of this presents problems.

Using views relationships

The obvious solution is to create a relationship to the taxonomy in the view set up, and add the image field via the relationship. However, this currently presents issues with duplicate rows being output. If an item in the view has more than one term reference, it is displayed once for each term reference. Because of how views works, setting “distinct” and “pure distinct” in the query settings does nothing as they are technically distinct results (each has a different term reference).

The views_distinct module should offer a solution to this kind of problem, but currently it does not work in a way that can aggregate the required fields while filtering duplicates in this situation.

Creating the custom field template

In our example view, no relationship is used and the relevant term reference field is included in the field list

If you have never made a views template before, click the link “Information” in the Other section of the view:

themeinfo

 

This displays a list of possible templates to use in customising your view for each field in the view. The template names shown are ordered from least specific to most specific – the filename of the template determines which situtations it is used. The bolded template is the one currently being used. To make a new custom template, create a file in the theme’s templates directory with the name. Click the link next to it to get the default code which should go into the template. In this case we wish to control output in all situations the field appears, so the first custom template option (highlighted) is that used.

themeinfo2

 

From the helpful comment at the top of the file, it can be seen that the contents of the view item can be found in the $row object. By debugging this object the location of the ingredients term references and their respective image fields can be found.

In this case the term reference field data is at:

$row->field_field_ingredients

and the image field at:

$row->field_field_ingredients[INDEX]['raw']['taxonomy_term']['field_image']

Where INDEX is the array index for multiple items.

The field_view_field() function is useful here to display the image field without needing to worry about URLs and allows control of formatting, e.g. image style presets. We also need to use an isset() condition to prevent warnings being thrown where rows don’t have any term references.

Putting this all together gives the example code:

if(isset($row->field_field_ingredients)) {
        $term = $row->field_field_ingredients;

        foreach($term as $ingredient){
                print render(field_view_field('taxonomy_term', $ingredient['raw']['taxonomy_term'], 'field_image',));
        }
}

This outputs the image, but at it’s original size and with an ugly label that says “Image:”. To fix this, we need to use the optional fourth parameter of the field_view_field() function to control display and formatting of the field. The line inside the foreach() loop becomes:

print render(field_view_field('taxonomy_term', $ingredient['raw']['taxonomy_term'], 'field_image',
array('label'=>'hidden', 'settings' => array('image_style' => 'thumbnail'))));

This hides the label and sets the image style preset for the output to ‘thumbnail’.

Final code:

if(isset($row->field_field_ingredients)) {
        $term = $row->field_field_ingredients;

        foreach($term as $ingredient){
                print render(field_view_field('taxonomy_term', $ingredient['raw']['taxonomy_term'], 'field_image',
                array('label'=>'hidden', 'settings' => array('image_style' => 'thumbnail'))));
        }
}

Source - Miles J Carter Photos on the Web Blog
Read the Original Article : Drupal views templating tutorial: Outputting the respective image fields of multiple associated taxonomy term references

Miles Carter: Drupal views templating tutorial: Outputting the respective image fields of multiple associated taxonomy term references

Feeds from Drupal.org - Sun, 2014-07-13 23:50

Courtesy of - Miles J Carter Photos on the Web Blog
Source URL : Drupal views templating tutorial: Outputting the respective image fields of multiple associated taxonomy term references

Using a custom field template to output taxonomy term references as their respective image fields, rather than as text or a link output

The ingredient icons are term reference fields formatted to output as their respective image fields, rather than as a link or text

The example situation is where a view displays a list of nodes or fieldable entities, for our example items on a menu, and each of these has one or more taxonomy term references, in this example the main ingredients. While it’s simple to output the term references as plain text or a link, showing an image or other field attached to the term reference instead of this presents problems.

Using views relationships

The obvious solution is to create a relationship to the taxonomy in the view set up, and add the image field via the relationship. However, this currently presents issues with duplicate rows being output. If an item in the view has more than one term reference, it is displayed once for each term reference. Because of how views works, setting “distinct” and “pure distinct” in the query settings does nothing as they are technically distinct results (each has a different term reference).

The views_distinct module should offer a solution to this kind of problem, but currently it does not work in a way that can aggregate the required fields while filtering duplicates in this situation.

Creating the custom field template

In our example view, no relationship is used and the relevant term reference field is included in the field list

If you have never made a views template before, click the link “Information” in the Other section of the view:

themeinfo

 

This displays a list of possible templates to use in customising your view for each field in the view. The template names shown are ordered from least specific to most specific – the filename of the template determines which situtations it is used. The bolded template is the one currently being used. To make a new custom template, create a file in the theme’s templates directory with the name. Click the link next to it to get the default code which should go into the template. In this case we wish to control output in all situations the field appears, so the first custom template option (highlighted) is that used.

themeinfo2

 

From the helpful comment at the top of the file, it can be seen that the contents of the view item can be found in the $row object. By debugging this object the location of the ingredients term references and their respective image fields can be found.

In this case the term reference field data is at:

$row->field_field_ingredients

and the image field at:

$row->field_field_ingredients[INDEX]['raw']['taxonomy_term']['field_image']

Where INDEX is the array index for multiple items.

The field_view_field() function is useful here to display the image field without needing to worry about URLs and allows control of formatting, e.g. image style presets. We also need to use an isset() condition to prevent warnings being thrown where rows don’t have any term references.

Putting this all together gives the example code:

if(isset($row->field_field_ingredients)) {
        $term = $row->field_field_ingredients;

        foreach($term as $ingredient){
                print render(field_view_field('taxonomy_term', $ingredient['raw']['taxonomy_term'], 'field_image',));
        }
}

This outputs the image, but at it’s original size and with an ugly label that says “Image:”. To fix this, we need to use the optional fourth parameter of the field_view_field() function to control display and formatting of the field. The line inside the foreach() loop becomes:

print render(field_view_field('taxonomy_term', $ingredient['raw']['taxonomy_term'], 'field_image',
array('label'=>'hidden', 'settings' => array('image_style' => 'thumbnail'))));

This hides the label and sets the image style preset for the output to ‘thumbnail’.

Final code:

if(isset($row->field_field_ingredients)) {
        $term = $row->field_field_ingredients;

        foreach($term as $ingredient){
                print render(field_view_field('taxonomy_term', $ingredient['raw']['taxonomy_term'], 'field_image',
                array('label'=>'hidden', 'settings' => array('image_style' => 'thumbnail'))));
        }
}

Source - Miles J Carter Photos on the Web Blog
Read the Original Article : Drupal views templating tutorial: Outputting the respective image fields of multiple associated taxonomy term references

Categories: Straight From Drupal

PreviousNext: Writing a custom Drupal Search API processor

Planet Drupal - Sun, 2014-07-13 23:07

When working with the Search API Drupal module, sometimes we need to programmatically add information that is not available for indexing as a field. Lucky we can write our own custom pre-processor to provide this information to the index.

PreviousNext: Writing a custom Drupal Search API processor

Feeds from Drupal.org - Sun, 2014-07-13 23:07

When working with the Search API Drupal module, sometimes we need to programmatically add information that is not available for indexing as a field. Lucky we can write our own custom pre-processor to provide this information to the index.

Categories: Straight From Drupal

Flickr: Free Drupal 7 theme #drupal_12628

Feeds from Drupal.org - Sun, 2014-07-13 21:23

Free-Templates.lt posted a photo:

Free Drupal 7 theme #drupal_12628

via Free-Templates.lt - Free Drupal, Wordpress, Joomla themes bit.ly/W1hoGU FREE-TEMPLATES.LT

Categories: Straight From Drupal

Gizra.com: Headless Drupal - Inline edit

Planet Drupal - Sun, 2014-07-13 21:00

In our last example we showed how to create node using an angular form served from Drupal itself. This time we are taking one big step further and create the node from a completely decoupled web app.
And if that's not enough for the readers excited by the idea of a decoupled Drupal, we've also added inline editing to the example!

Enjoy the live demo

If you know Form API's pains, you should be excited now

Continue reading…

Gizra.com: Headless Drupal - Inline edit

Feeds from Drupal.org - Sun, 2014-07-13 21:00

In our last example we showed how to create node using an angular form served from Drupal itself. This time we are taking one big step further and create the node from a completely decoupled web app.
And if that's not enough for the readers excited by the idea of a decoupled Drupal, we've also added inline editing to the example!

Enjoy the live demo

If you know Form API's pains, you should be excited now

Continue reading…

Categories: Straight From Drupal

Auto Login URL

Latest Drupal Modules - Sun, 2014-07-13 19:58
Overview

Creates auto login URLs on demand and through tokens.

This is mostly a developer's module. The better use for me is to convert all links of a specific text to auto login links.

It also provides two tokens that you may use on mass emailing like simplenews.

Use case

You may use

Categories: Straight From Drupal

Flickr: Free Drupal 7 theme #drupal_12334

Feeds from Drupal.org - Sun, 2014-07-13 18:27

Free-Templates.lt posted a photo:

Free Drupal 7 theme #drupal_12334

via Free-Templates.lt - Free Drupal, Wordpress, Joomla themes bit.ly/1yda6h1 FREE-TEMPLATES.LT

Categories: Straight From Drupal

Freelock : I've got a theory: The Scientific Method applied to web site performance

Planet Drupal - Sun, 2014-07-13 16:10

What can you do about this page being so slow? That's a question we've been asked by half a dozen customers in the past 6 months, and as it turns out, we can do quite a lot.

One of my long-standing complaints about Drupal is that it's a resource hog. That's an issue we can generally help by throwing lots of hardware and caching systems at the problem -- but that's not the kind of performance issue these clients were having.

PerformanceScalingMonitoringDrupalDrupal PlanetTechnical

Freelock : I've got a theory: The Scientific Method applied to web site performance

Feeds from Drupal.org - Sun, 2014-07-13 16:10

What can you do about this page being so slow? That's a question we've been asked by half a dozen customers in the past 6 months, and as it turns out, we can do quite a lot.

One of my long-standing complaints about Drupal is that it's a resource hog. That's an issue we can generally help by throwing lots of hardware and caching systems at the problem -- but that's not the kind of performance issue these clients were having.

PerformanceScalingMonitoringDrupalDrupal PlanetTechnical
Categories: Straight From Drupal

Nutralactis | Probióticos para la vida

Drupal showcase com - Sun, 2014-07-13 16:01
Site Description: 

This website is an online shop to sell probiotics to Spain (and Portugal in the near future). This ecommerce website is based in the Drupal Commerce Platform. The website's theme was deveoped from scratch, based on the 960 CSS grid system. The website includes a lot of customizations and integrations with third-party systems, like: integration with the Mailchimp platform, integration with Paypal and Redsys payments, integration with the MRW shipping platform. The website supports coupons and it includes a a blog. Currently, the website is a spanish-only website, but more languages will be included soon.

Site Designer: 

Karakana Factoría TIC

Site Developer: 

Karakana Factoría TIC

Site URL: https://www.nutralactis.comVersion of Drupal: Drupal 7Site Type: 5Industry: Health CareCountry: SpainCategories: BiotechnologyFood & BeverageHealth & FitnessHealthMedicalPharmaceuticalsScreenshot Thumbnail: Probióticos para la vida | NutralactisTags: drupalDrupal 7 developmentDrupal 7 ecommerceecommerceecommerce web designe-Commercee-commerce shopTier: Three Select ratingGive it 1/5Give it 2/5Give it 3/5Give it 4/5Give it 5/5Cancel rating Average: 5 (1 vote)
Categories: Showcase

Flickr: Free Drupal 7 theme #drupal_13586

Feeds from Drupal.org - Sun, 2014-07-13 12:09

Free-Templates.lt posted a photo:

Free Drupal 7 theme #drupal_13586

via Free-Templates.lt - Free Drupal, Wordpress, Joomla themes bit.ly/1kkKXJd FREE-TEMPLATES.LT

Categories: Straight From Drupal

Slick Tweets

Latest Drupal Modules - Sun, 2014-07-13 11:41

Slick and Twitter Pull integration to have tweet slider/ticker blocks.

Categories: Straight From Drupal

Navbar Awesome

Latest Drupal Modules - Sun, 2014-07-13 00:33

Makes NavBar awesome by implementing Font Awesome + Google's Material Design concepts.

Making Navbar Awesome

This module helps take Navbar to a different experience. It allows site builders to provide site users and clients with a cleaner implementation of Navbar.

Categories: Straight From Drupal

Flickr: Free Drupal 7 theme #drupal_10048

Feeds from Drupal.org - Sun, 2014-07-13 00:06

Free-Templates.lt posted a photo:

Free Drupal 7 theme #drupal_10048

via Free-Templates.lt - Free Drupal, Wordpress, Joomla themes bit.ly/1muoNc1 FREE-TEMPLATES.LT

Categories: Straight From Drupal

ΣΥΝΤΑΓΕΣ

Drupal showcase com - Sat, 2014-07-12 19:57
Site Description: 

Συνταγές μαγειρικής. Αγαπάμε το καλό φαγητό, τη μαγειρική της μαμάς, τα γλυκά της γιαγιάς και μοιραζόμαστε τις πιο σούπερ συνταγές μας!

Site Designer: 

http://www.webzein.gr

Site Developer: 

http://www.webzein.gr

Site URL: http://www.supersyntages.grVersion of Drupal: Drupal 7Site Type: 3Industry: RecreationCountry: GreeceCategories: FoodScreenshot Thumbnail: Tags: drupalviewsforumjcarousel Select ratingGive it 1/5Give it 2/5Give it 3/5Give it 4/5Give it 5/5Cancel rating No votes yet
Categories: Showcase

Flickr: IMG_4722

Feeds from Drupal.org - Sat, 2014-07-12 17:30

DrupalSPB.org posted a photo:

IMG_4722

Categories: Straight From Drupal

Flickr: IMG_4721

Feeds from Drupal.org - Sat, 2014-07-12 17:30

DrupalSPB.org posted a photo:

IMG_4721

Categories: Straight From Drupal

Flickr: IMG_4724

Feeds from Drupal.org - Sat, 2014-07-12 17:30

DrupalSPB.org posted a photo:

IMG_4724

Categories: Straight From Drupal

Pages

Subscribe to My Drupal aggregator