Stoppt die Vorratsdatenspeicherung! Jetzt klicken &handeln! Willst du auch an der Aktion teilnehmen? Hier findest du alle relevanten Infos und Materialien:

Archived entries for cck

Drupal: Rendering Fields

ComputerMinds zeigt zwei Wege Fields zu rendern, ohne dass man sich um die Sprache und Sanitisation Sorgen machen muss.

$output = field_view_field('node', $node, 'field_name');
That will return the sanitised, rendered field in its entirety, in the current language and in render-array form, so you’ll get all the associated markup.

Wer mehr Kontrolle will nutzt field_get_item und field_view_value

$node = node_load($nid);
$image = field_get_items('node', $node, 'field_image');
$output = field_view_value('node', $node, 'field_image', $image[0], array(
 'type' => 'image',
 'settings' => array(
 'image_style' => 'thumbnail',
 'image_link' => 'content',
 ),
));

Drupal 7: Custom Formatters

Dan Linn erklärt was nötig ist um Custom Formatters in Drupal 7 zu erstellen.

Custom formatters are a great way to control the output of your fields. In this tutorial I’m going to use an example that takes a user’s Facebook URL as the input and outputs a button of the Admin’s choosing, along with an option to open the link in a new window.

Drupal 7: Field API

Ein Posting bei Public Action demonstriert was mit der neuen Field API in Drupal mit relativ wenig Mühe möglich ist.

This article is intended for programmers. We build a proof-of-concept module who’s sole purpose is to demonstrate features of the Drupal 7 Field API. (…) Our new module is called “my date”. We add several new features: the ability to style the date display; better control over the default date values; use of the JQuery date picker widget to select dates. (…) I broke each of the date instances in to 4 HTML div elements: container, month, day, year.
In addition, each of the date parts (month, day, year) can be toggled on or off (displayed or not displayed).
I also allow an HTML style attribute to be applied to each HTML element. Again, that is the container div, month, date, year.
The date can be aligned (float) either right or left.
You also have the option of choosing a back ground image.

Theming CCK fields

Netter Screencast auf Friendly Drupal über CCK Fields Theming.

Using CCK field templates
CCK comes with a default field template, called content-field.tpl.php. Copy it from the module directory (cck/theme) to your theme.
In addition to the default template, you also have several template suggestions based on it.
As typical with Drupal, the more specific options (e.g. the last one in the list) would have a precedence over the more generic one.
When you open content-field.tpl.php, you’ll see available variables such as $field_name or even the $node object. (…)
Using Drupal preprocess functions.
In what situation preprocess functions are preferable to working directly with the templates? Well, for one thing, you’re likely to end up with a ton of different templates with a serious downside in terms of maintenance. Or, just like in our example, you might need to use some piece of code that is shared across several fields but has to display different contents depending on the field or other context.
Let’s begin by opening template.php file for your theme (create it if there isn’t one yet). Then you can add preprocess function for the field template:
function your_theme_preprocess_content_field(&$vars) { // code here }

Drupal 7: Creating Custom Fields

Ein ausführliches Posting von Phase2 erklärt wie man eigene Felder in Drupal 7 definiert.

With Field API being part of core as of Drupal 7.0, creating custom fields just became a lot easier than they were in Drupal 6.x. Suppose you need to create a compound field, which consists of several different form elements (a select and several text fields). You can now have a basic compound field in three basic steps:

  • Define the field (info and schema)
  • Define the field form (widget)
  • Define the output (formatter)

Note: Much of what will be discussed here can be found in the Field Example module, but with some much-needed explanations.



Copyright © 2004–2009. All rights reserved. – Impressum

RSS Feed. This blog is proudly powered by Wordpress and uses Modern Clix, a theme by Rodrigo Galindez.