Adding attributes/categories to a block

Hi all,
I am playing with C5.7. I love it!! I come from the Symfony-ish world, and greatly appreciate C5’s streamlined architecture and interface. So, although I am by no means a C5 developer (yet), I can follow along.

I have created a custom video block, based on the youtube block type, but which support thumbnails, preconfigured sizes, multiple descriptions, hover, etc… So far so good.

What I would like to do in integrate either/both categories/topics into the block and also add some other attributes.

For the sake of simplicity, let’s just say I want to add a Rating attribute or a Featured attribute to this block… so when the block is instantiated, there is a rating/featured option, which I assume (hope) is also accessible via edit mode OF THAT BLOCK INSTANCE.

However, I have had no luck in getting an idea how to do this. Is there a tutorial, doc,example that would help me?

In my attempts to figure this out, I came up with a few more questions, which I will toss in here in case some kind soul want to throw me a bone.

For example, I thought one way would be to create a new Collection Set called vStreams, enable various attributes, then add the instances of that block, programmatically, to that set.

I ran into 2 obstacles: 1) after create a new set none of the attributes were enableable. Where do I enable these attributes for the new set? and 2) How do I add new instances of the block to a set?

I guess the 3rd questions is… am I even going about this the right way?

The end result is simply to have the attribute, for example Featured, editable from within the block instance

The more ‘complicated’ questions, (for me), is, how do I add a user-managed interface to the block instance that allows the user to select what category and/or topic this instance belongs to?


View Replies: View Best Answer
JohntheFish replied on at Permalink Best Answer Reply
Others have tried to add attributes to blocks in the past. Its complicated because block IDs change with each edit.

The usual c5 approach is to map the items you want to manage to something that already supports attributes.

For example, you have a thumbnail file associated with each video, so use file attributes of the thumbnail files and edit the attributes through the file manager.

More generally, pages are often used as data objects, so you could associate videos with pages (of a specific page type), add attributes to the pages, then use page lists to filter the pages. The pages themselves don't need to be shown, they can be hidden from nav and search.

In 5.6 hereNT's Best Suite could be used to create managers for page types. I don't know if there is any 5.7 alternative that is as easy to set up.
ntisithoj replied on at Permalink Reply
these are great suggestions! thanks!....

However, I am not clar what you mean by 'mapping'. For example, I understand mapping as in ORM, and, for example in Symfony, I would create the mapping in the ORM

something like...

@ORM\OneToMany(targetEntity="MenuItem", mappedBy="category")

for the 'ONE' side, and the following for the 'MANY' side

@ORM\ManyToOne(targetEntity="Category", inversedBy="menuitems")
@ORM\JoinColumn(name="category_id", referencedColumnName="id")

Whis is exactly what I would like to do with something like table AttributeTypes and table Blocks (adding a 1->N table in the middle, I guess). I assumed the difficuly rested solely in my lack of knowledge about C5 (as I can not even find where the ORM os actually defined, let alone understand how I would need to tweak it... but maybe that is not even a good idea). The block ID's may change but if the ORM is there it would not be a problem to simply preserve the references from the last block.

So when you say "map the items you want to manage to something that already supports attributes" I kinda have no clue what that means or how to do it in C5.

So I have my schema youtube block, which inclues a thumbnail url, and you are saying I should use the thumbnail attribute instead, which, I assume, is in the File object... so in some magic way I map the youtube block to the file block (and create a 'collection' for this hybrid?)

Or, Is this an example of the mapping you are referring to?

$this->set('thumbnailAttribute', CollectionAttributeKey::getByHandle('thumbnail'));


Sorry if I sound dense. I am still getting my head around how C5 is all put together, and there are major differences to what I am used to, so, still climbing the learning curve.

I have read as many docs as I could find so far on this, but none too helpful. If you can reccomend any, greatly appreciated

Thank you for your feedback
JohntheFish replied on at Permalink Reply
Mapping in a fundamental logical sense, not as a specific database or orm concept, although such concepts may be used to implement it.
ntisithoj replied on at Permalink Reply
ahh... is this what you are referring to, for example?