Commit e614befa authored by targoo's avatar targoo

Issue #2101001 by loominade: Fixed color swatch formatter is not themeable.

parent 63d5a976
......@@ -437,6 +437,18 @@ function color_field_field_formatter_settings_summary($field, $instance, $view_m
return implode('<br />', $summary);
}
/**
* Implements hook_theme().
*/
function color_field_theme($existing, $type, $theme, $path) {
return array(
'color_swatch' => array(
'variables' => array('color' => '', 'width' => 50, 'height' => 50),
),
);
}
/**
* Implements hook_field_formatter_view().
*
......@@ -474,7 +486,13 @@ function color_field_field_formatter_view($entity_type, $entity, $field, $instan
$rgb = $item['rgb'];
$width = $settings['width'];
$height = $settings['height'];
$element[$delta]['#markup'] = '<div style="background: ' . $rgb . '; width: ' . $width . 'px; height: ' . $height . 'px;"></div>';
$element[$delta] = array(
'#theme' => 'color_swatch',
'#color' => $rgb,
'#width' => $width,
'#height' => $height,
);
}
break;
}
......@@ -695,3 +713,11 @@ function color_field_hex2rgb($hex = FALSE) {
$b = hexdec(substr($hex,-2));
return compact('r', 'g', 'b');
}
function theme_color_swatch($variables) {
$color = $variables['color'];
$width = $variables['width'];
$height = $variables['height'];
return '<div class="color-swatch" style="background-color: ' . $color . '; width: ' . $width . 'px; height: ' . $height . 'px;"></div>';
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment