Active
Project:
Field Formatter CSS Class
Version:
7.x-1.x-dev
Component:
Miscellaneous
Priority:
Normal
Category:
Plan
Assigned:
Unassigned
Reporter:
Created:
7 Jun 2016 at 10:49 UTC
Updated:
12 Jul 2019 at 23:03 UTC
Jump to comment: Most recent
Comments
Comment #2
zany commentedA Drupal 8 version is not planned. Patches and co-maintainers welcome!
Comment #3
geek-merlinThanks for clarifying this. I'd be interested in that.
Comment #4
galli commentedI'm interested in a Drupal 8 Version, too. Not sure how I can help - I'm not a programmer. But if you need something else (testing, documentation,...) I would be glad to help.
Comment #5
SoYeah commentedI solved it with this option:
in YOURTHEME.theme:
function YOURTHEME_preprocess_node(&$vars) {
$vars['CLASSNAME'] = $vars['content']['FIELD_WITH_VALUE'][0]['#markup'];
}
node.html.twig:
<div class="node__container node--{{ CLASSNAME }}">So you could build a select list for your Editor to choose a special styling or just render a hidden field for your class.
Or you just set classes in the .twig
Comment #6
geek-merlinI think this can also be done with DS region tokens: #2288345: Add token support for region classes
Unfortunately we do not yet have them on entity level: #2867781: Add CSS classes for entity
I'd suggest implementing that feature to provide the use case of this module and many more.
Comment #7
murrayw commentedI think that a simple solution can be done by implementing hook_entity_view_alter in Drupal 8. Using a general hook like this keeps things flexible as it just works for any entity.
The D7 module seems to have some added complexity around target, depth and transliteration. I'm wondering if these are really needed. From my experience adding a class direct to the entity is usually enough. If you do need to manage lists of things then you can handle that in the CSS.
If the maintainers were amenable to a simple solution as described, we could have a look into providing a D8 version.
Comment #8
zany commentedTarget and depth are quite essential actually. I.e. think of applying format to a field, you'd want the CSS "somewhere higher up the DOM tree". Imagine the field is inside a group inside a field collection (and then inside a node, page, body). Where do you want the CSS? Imagine the field is inside nested groups or nested field collections. And this nesting arises surprisingly often in projects of moderate complexity.
Comment #9
murrayw commentedSorry about that. I didn't grok that it was going higher up, not lower down. I was thinking along the lines of a component where the class was associated with the entity (component) and no higher.
Comment #10
murzAs alternative, we can use Entity Class Formatter module for Drupal 8.
Comment #11
puya commentedIs there any development planned on this end? This would be a very useful modules to have on D8.
Thanks