要求:
コンテンツフィールドはテキストの場合、赤文字で表示する。
実装:
Hookを利用して、コアのフィールドモジュールをオーバーロードする
1、sites/all/modules/下にモジュールフォルダを作成する
custom/koma
2、komaフォルダに下記の二つファイルを作成する
koma.info
name=koma description=Koma Custom module core=7.x package=Custom file[]=koma.module
koma.module
<?php
function koma_field_formatter_info()
{
return array(
'text_komared' => array(
'label' => t('KomaRed'),
'field types' => array('text'),
),
);
}
function koma_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display)
{
$element = array();
switch ($display['type'])
{
case 'text_komared':
foreach ($items as $delta => $item)
{
$element[$delta] = array('#markup' => "<span style='color:red;'>" . $item['value'] . "</span>");
}
break;
}
return $element;
}
3、モジュールを有効にする

4、テキストフィールドの表示設定
5、表示結果確認

0 件のコメント:
コメントを投稿