Tag: drupal 7

Drupal: Check and render image fields

At reclaimyourcity, we have picture and artist nodes and relate them via a node reference. Now some of the artists may have a little profile comprising a picture and a description. When viewing the artist profile and there is no profile picture yet, we want to show the latest submitted picture of the particular artist instead. For this, we first need to check the value of the profile picture field and if it is not set, we need to get and render the latest picture of the artist. The first question is where to perform this check. Fortunately, Drupal offers

Posted in code Tagged with: , , , , , , ,

Drupal: Group and sort by taxonomy term

For the reclaimyourcity relaunch, we added different categories (via taxonomy) for our picture specials. Now, a view was needed that displayed all special titles grouped by the particular category. And the categories should be sorted by the term’s weight since the category other should be displayed last. The following steps delivered the desired result: 1. First select the required fields of the picture specials, namely Content: Title and Content: special_type which refers to the terms of the corresponding vocabulary. 2. Exclude the special_type from display and in the grid layout settings, set the grouping field to special_type. Now, the picture specials are already

Posted in code Tagged with: , , , , ,

Drupal: Tweaking block visibility for content types and URLs

For the relaunch of reclaimyourcity.net, I recently developed a custom pager module that provides a block with links to the previous and next picture according to the particular gallery. The visibility settings for the block are restricted to the content type of the street art pictures. However, the pager also tries to show up on the node add/edit pages which is not very useful there. Based on the posts in this thread about block visibility at drupal.org, adding the following PHP validation prevents the block from showing on the node create/edit pages. <?php $show = TRUE; $url = request_uri(); $hide_on_pages

Posted in code Tagged with: , , , , , ,