Archive for the Drupal Category

Cuando generamos un View, y queremos darle un formato en particular tenemos que agregar una llamada desde nuestro templates a la función views_embed_view, pasando por parámetros el nombre de la vista, el display_id.

<?php echo views_embed_view(’nombre_vista’ , $display_id = ‘default’); ?>

Cuando
hacemos esta llamada nos genera un html con el contenido de la vista.
Si queremos darle un formato html especial tenemos que generar un
archivo con el nombre view_view–nombre_vista.tpl.php
A esta función llega un objeto con el nombre $view->result, que contiene todo el contenido de nuestra vista.

Por ejemplo si quisieramos mostrar el contenido de la vista en una listado con el title y el teaser, el código seria el siguiente.

<ul class=”destacados_libros”>
<?php if (!empty($title)): ?>
<li class=”top_titulo”><?php print $title; ?></li>
<?php endif; ?>
<?php foreach ($view->result as $row): ?>
<li><?php echo $row->node_revisions_teaser; ?></li>
<li><?php echo $row->node_title;?></li>
<?php endforeach; ?>
</ul>

While working on the administration section of a medium to large site, you may need to allow different roles to create and edit different content. Typically you want Role X to be able to create and view some content types only. The creation part is easy: go to the Access control section and give Role X the Create and Edit permission for the content types you want this role to be able to create and edit. The next thing you’ll want to do is give the role a way to list all nodes for the content type it is allowed to view/edit and be able to administer these nodes. The logical thing would be to give the role access to the admin/content/node by giving this role the administer nodes permission. The problem is that the filter for this screen will show you nodes of all types regardless of what the role should be able to edit! This hack will guide you to another trick: creating a views page for Role X to be able to administer the nodes he should have access to. Read on for the rest of this hack.

A page to edit and create content types

 

(more…)

A missing feature in Drupal is the ability to preview changes made to the home page. If you have a custom page as your home and you promote several pieces of content to it there is no way for you to preview how it will look. If the content breaks the layout or doesn’t look as good as you expect it to do then you’ll have to make several changes to fine-tune your home. Wouldn’t it be great if you could get a preview of your home and when you are satisfied with the all the changes hit a publish button to see all your changes commit at once? Well you can! Read on to see how.

(more…)

A problem which often arises when writing Drupal themes, modules, etc. is making sure there are no ‘hard-coded’ paths in our code. To help new users on their quest to writing quality Drupal code I list here the most used API functions to get paths in a portable way:

  • global $base_url - A global variable which stores your sites URL, typically http://www.<your_site>.com. This variable is set in your settings.php configuration file. This is not very portable and maybe in the future Drupal has a function for this.
  • base_path() - Returns the base URL path of the Drupal installation. At the very least, this will always default to /. This is used, for example when you want to add a resource relative to your base_url. For example like so: drupal_set_html_head(’<style type=”text/css” media=”all”>@import “‘. base_path() . drupal_get_path(’module’, ’system’) .’/system.css”;</style>’);
  • conf_path() - Based on your sites URL tries to find the most appropiate settings.php (site configuration file). To read how it works see Drupals API documentation
  • drupal_get_path($type, $name) - Returns the path to a system item (module, theme, etc.). The $type argument can be ‘theme’, ‘theme_engine’ or ‘module’ and $name the name of the item for which you want the path. To get an absolute path you need to prefix the $DOCUMENT_ROOT (the document root of your drupal installation).
  • path_to_theme() - This points to your theme’s path on the local filesystem. Usually $DOCUMENT_ROOT/themes/<your_theme> or $DOCUMENT_ROOT/sites/<your_site>/themes/<your_theme>
  • path_to_engine() - Returns the path to the currently selected engine.

To learn a bit more search for this terms in the API search box or ‘use the source, Luke!’.

At Easytech we are using Drupal for projects which require a CMS (Content Management System). It’s very powerful, full of modules to extend the functionality and written in PHP which is a Language for which we have a lot of programming experience. For a project we are working on we used the Related Content module. This module allows you to link a particular piece of content (a node in Drupal parlance) to other content such as images, videos, audios, etc. One problem with the current implementation of the module is that it wasn’t designed to work when you have lots of content on the site. The patch we currently submitted to Drupal fixes this by separating the Related Content into a tab and adding a filter to be able to quickly locate content items. Here’s a screenshot:

This is how the new features looks like

If you are interested in getting the patch its here. In case you want to download a patched version of the module I have included a tar file with the latest version as an attachment in this posting. Try it out and send feedback to: miquel <at> easytech <dot> com <dot> ar.

Here’s a tar file with the patched version to try out: relatedcontent-5.x-1.1-patch.tar.gz. To install it just download it and untar it in the modules/contrib directory of your Drupal installation.