I am building a module that creates a content type. When a node is created via I want to create a block that will access the code associated with that node.

I also want the block to be deleted when the node is deleted.

How do i, and what is the best way to, create the block when the node is created, and have it be deleted when the node is deleted?

Thanks,
Cy

Comments

nevets’s picture

You probably do not one block per node, though that depends on the actual goal. My guess is you want a single block that can work for any node of your custom type.

What do you want to show in the block.

When, under what conditions, do you want to show the information?

cjobes’s picture

A node would be created, and the block would be associated with that so that the block could be placed inside any node, but always get its specific code.

In this way, and content node could be assigned a block, and what is displayed in the block does not depend on the content node.

In other words, the block does not care what node it is in, but already knows what node content it itself is to display.

Make sense?

Cy

nevets’s picture

How does the block know what to display? How is it related to the node in question?

Off hand it sounds like you could use an entity reference field.

XandieL’s picture

i thought views is the one responsible for those things

create a block associated to a content type

I like the universe, but she messes with my words
I'm not talking planets or galaxies and the distance just makes it worse.
I know what you're thinking, this probably sounds rehearsed.

cjobes’s picture

Basically you are asking the questions that I need answers to.

Here is what I am doing?
I am re-writing the Poll module because it's properties and tables cannot work with what we want, and how we manage our website. It's lengthy to explain, so just know that I cannot use the Poll module as it is.

The poll module creates a block called Most Recent Poll. Problem is we might be doing more than one poll at a time, so I need a way to make sure the proper poll is displayed on the proper page(s).

Cy