Naming conventions for content classes attributes

Author Message

Sebastiaan van der Vliet

Thursday 29 October 2009 2:15:00 am

At Contactivity, we found that the default content class attribute names (image, file, etc) are sometimes confusing to work with: especially in templates where the output of several content classes are combined. It is not always clear what type of datatype we are dealing with (eh, was this a textblock or an xml block?), so we need to go back to the content class definitions to check that.

We found that using more descriptive content class attribute names saves us time and makes our code more readable. Our naming convention for eZ publish content class attributes is as follows:

[class_prefix]_[attribute_name]_[datatype_initials] 

For example, the attribute identifier for an article is:

art_intro_xmlb

The attribute identifier for a downloadable file in a blog post is:

blp_file_file

Available datatype initials include:
o auth - Authors;
o chkb - Checkbox;
o datt - Date/Time;
o mail - Email;
o file - File;
o imag - Image;
o keys - Keywords;
o mtrx - Matrix;
o link - URL;
o user - User account;
o xmlb - XML block.
o etc...

But:
- Some of the attribute names we do not change (for example, the 'image' attribute in the image class) because these are 'ez publish' configuration defaults;
- Of course, the use of more advanced debug info also helps;
- Sometimes we need the attribute name of the attributes of two different classes to be the same, in order to simplify a fetch.

We have developed a set of standard content class definitions and matching templates that we use as our 'base' design.

We are interested to know if anybody else uses naming conventions for content classes. Is there another way to do this?

Certified eZ publish developer with over 9 years of eZ publish experience. Available for challenging eZ publish projects as a technical consultant, project manager, trouble shooter or strategic advisor.

Piotrek Karaƛ

Thursday 29 October 2009 8:21:07 am

Hello Sebastiaan,

Interesting subject.

We try to follow the as semantic as possible approach, so our variables are long and full of meaning ;) And so are the identifiers of any kind (no abbreviations), but we try not to double of what is already expressed with native structures, so they carry no information about class or datatype, like yours. I wouldn't like that either for any evolving project that I have to maintain, because that may quickly lead to inconsistencies that could be a headache.

We have some conventions for prefixes/suffices like holders/containers/catalogs for folder-like class names, the rest we try to keep as descriptive as possible.

Any simplification or unification of fetches and other repeatable pieces of code we do by abstracting them with includes of smaller template bits that can actually act as functions. Again, I wouldn't like to remember that my application relies on attributes having to have the same names. Of course, what you wrote is not exactly example of that situation, but may slightly take the code that way. Also, what if you rely on your attribute being named "file", and then you find out that there are two more file-like attributes required? This is why I would prefer to name the first file more precisely, like "cv_file", and then add two other accordingly.

However, those all rules often have to be bent to handle the reality ;)

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

Sebastiaan van der Vliet

Thursday 29 October 2009 9:08:05 am

Hi Piotrek,

Could you give a few examples? I am interested to know how you use conventions for prefixes/suffices like holders/containers/catalogs.

Regarding your question:

>> Also, what if you rely on your attribute being named "file", and then you find out that there are two more file-like attributes required?<<

In such cases we use the object relation browse datatype. This allows us to translate the eZ publish content model into a more 'relational datamodel'. As far as naming conventions are concerned, for multiple files for the class 'article', we would then use the following attribute name:

art_file_obrb

Another example: if we would use predefined labels (using a 'label' class) for articles, we use

art_label_obrb

Certified eZ publish developer with over 9 years of eZ publish experience. Available for challenging eZ publish projects as a technical consultant, project manager, trouble shooter or strategic advisor.

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 21:12:01
Script start
Timing: Jan 18 2025 21:12:01
Module start 'layout'
Timing: Jan 18 2025 21:12:01
Module start 'content'
Timing: Jan 18 2025 21:12:02
Module end 'content'
Timing: Jan 18 2025 21:12:02
Script end

Main resources:

Total runtime0.9668 sec
Peak memory usage4,096.0000 KB
Database Queries57

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0109 588.0391152.6406
Module start 'layout' 0.01090.0040 740.679739.4766
Module start 'content' 0.01490.9503 780.1563560.1016
Module end 'content' 0.96520.0016 1,340.257816.1250
Script end 0.9668  1,356.3828 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00360.3682160.0002
Check MTime0.00140.1480160.0001
Mysql Total
Database connection0.00140.149610.0014
Mysqli_queries0.898392.9178570.0158
Looping result0.00070.0715550.0000
Template Total0.921395.320.4606
Template load0.00220.226220.0011
Template processing0.919195.063520.4595
Template load and register function0.00010.010610.0001
states
state_id_array0.00230.233410.0023
state_identifier_array0.00210.215220.0010
Override
Cache load0.00180.1901480.0000
Sytem overhead
Fetch class attribute can translate value0.00090.089420.0004
Fetch class attribute name0.00110.109450.0002
XML
Image XML parsing0.00100.100520.0005
class_abstraction
Instantiating content class attribute0.00000.001360.0000
General
dbfile0.00100.0987240.0000
String conversion0.00000.001340.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
8content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
5content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 23
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs