Add a custom data as an extra field on node display

Public

Expose "pseudo-field" components on fieldable entities. This is a snippet set for my tutorial posted here: http://timonweb.com/adding-a-custom-extra-field-to-entity-node-display

Get raw version
php
  1. /**
  2.  * Implements hook_field_extra_fields().
  3.  */
  4. function MODULE_NAME_field_extra_fields() {
  5. $extra['node']['article']['welcome_message'] = array(
  6. 'label' => t('Welcome message'),
  7. 'description' => t('A welcome message'),
  8. 'weight' => 0,
  9. );
  10. return $extra;
  11. }
  12.  
  13. /**
  14.  * Implements hook_node_view().
  15.  */
  16. function MODULE_NAME_node_view($node, $view_mode, $langcode) {
  17. // Only show the field for node of article type
  18. if ($node->type == 'article') {
  19. $node->content['welcome_message'] = array(
  20. '#markup' => 'Hello and welcome to our Drupal site!',
  21. );
  22. }
  23. }

Comments

peeterjhn's picture

The main reason for the immediate approval of his free online availability and process without any problems. The need to waste their time standing in long queues. Payday loans no credit check The application can be formed via in the comfort of your home. With this you can select the faxless, so your loan faster processing. Loans for bed credit It's like a miracle that you can get money without a fax and documentation, and it might be possible with this short term. When a man and he has a bank account, it would be very easy for him to get approval for the same day loans No credit check loans. Must be 18 years and also a citizen of the United Kingdom. When she meets these conditions,
http://www.nocreditcheckloansz.co.uk

LarryS's picture

Nice post to read on.In relation,reverse mortgages are a bit of a niche financial product, as they are only available to senior citizens. The loans can offer some funding for retirement, but the CFPB is looking to the goods to see if any additional legislation might be warranted. Get help while waiting for a reverse mortgage with a personal finance.
See more at:
https://personalmoneynetwork.com/

mattew's picture

The "display" key is missing in your extra field declaration, it should be :

  1. $extra['node']['article']['display']['welcome_message'] = array(
  2. 'label' => t('Welcome message'),
  3. 'description' => t('A welcome message'),
  4. 'weight' => 0,
  5. );