How to add a custom field which dynamically renders different output according to certain conditions? I am writing a module which adds a new field. Similar to the serial module, the field cannot be changed or filled anyhow when creating a new node.
I just want the field to create a different output according to certain conditions, for instance if the user has a certain role or not.

For instance, when a user visits a node of a content type which has this field enabled, check for php conditions and then output different html.
Is the user a guest or registered? If guest, output a link which says "register to do this".  

It would be really cool if this would then automatically work with views? Like a view which outputs this field for every node of that content type.

Ive tried using computed field but this module computed the result once and then displays this all the time... only solution would to alter the cache db, which seems a little unsmooth to me.

I already added a field using the examples module, so this is what I got so far:

function proposal_field_field_info() {
  return array(
    // We name our field as the associative name of the array.
    'proposal_field' =&gt; array(
      'label' =&gt; t('Proposal Field'),
      'description' =&gt; t('Adds proposal feature'),
      'default_widget' =&gt; 'proposal',
      'default_formatter' =&gt; 'proposal_field_simple_text',
    ),
  );
}
Computed Field seems to meet your needs.


  These computed fields are populated with values that you define via PHP code. You may draw on anything available to Drupal, including other fields, the current user, database tables, you name it. (Feeling the power yet? :) ) You can also choose whether to store your computed field values in the database with other content fields, or have them "calculated" on the fly during node views.


Emphasis mine. Either require it in your module and use it, or use it's code, it is open source after all.