2

I've read through many questions asking this same thing, but I feel like I'm doing what they are suggesting and it's still not working.

I've created a custom module and enabled it. This is my code:

function mymodule_node_view($node, $view_mode, $langcode) {
  if ($view_mode == 'teaser' && $node->type == 'article' && count($node->field_video) > 0) {
    kpr($node);

    $markup = sprintf("<video style='width: 502px; height: 282px;' poster='%s'>\n",
        image_style_url('video_thumbnail', $node->field_video[$node->language][0]['thumbnailfile']->uri)
      );

    foreach($node->field_video[$node->language][0]['playablefiles'] as $video_object) {
      $markup .= sprintf("<source src='%s' type='%s' />\n",
          file_create_url($video_object->uri),
          $video_object->filemime
        );
    }

    $markup .= "</video>";

    $node->content['field_video_embed_code'] = array(
      '#markup' => $markup,
      '#weight' => 10,
      '#type'   => 'markup',
    );

    kpr($node);
  }

}

When I look at the krumo output, I see my changes to the $node object, however, when it renders the new field I'm adding is not included.

What am I doing wrong?

EDIT: I just realized I'm using Display Suite (it's been awhile since I set this site up) which is overriding which fields are shown and in what order. My guess is that DS is getting my modified content, but not showing the additional field because it isn't listed in my teaser fields? I'm not sure.

7
  • 2
    Please provide code of node template file. Maybe you don't output $node->content directly. Commented Jan 10, 2013 at 9:31
  • I am using a Zen sub-theme and I haven't overridden Zen's node template, but I'll include it above anyway. Commented Jan 10, 2013 at 22:29
  • have you inspected the page source to make sure the <video> tag is definitely missing form the HTML, and not just invisible for some reason?
    – Chaulky
    Commented Jan 11, 2013 at 3:16
  • Yes, I have looked at the raw source in addition the DOM inspector. The video tag is definitely missing. Commented Jan 11, 2013 at 3:59
  • What happens if you do a dpm($content) in the template file? Is your field in there? (dpm needs devel module).
    – 2pha
    Commented Jan 11, 2013 at 4:54

1 Answer 1

1

You must declare the field for the DS be able to handle it. In your case:

/**
 * Implements hook_field_extra_fields().
 */
function mymodule_field_extra_fields() {

  $extra['node']['article']['display']['field_video_embed_code'] = array(
    'label' => t('Custom field embed video.'),
    'description' => t('Adds a custom field.'),
    'weight' => 0,
  );
  return $extra;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.