A custom module is using the following code.

function sun_blogs_views_pre_render(&$view) {
        $wrapper = entity_metadata_wrapper('node', $node);
        $title = $wrapper->field_job_title->value();
        if (strlen($title)) {
          $view->description .= ' - '  . $title;

It causes the following error.

Undefined function 'entity_metadata_wrapper'.

How can I fix this error?

  • entity_metadata_wrapper() does not exist in Drupal 8 or Drupal 9. It does not appear that your custom module has been ported to D8/9 yet. – anonymous Apr 7 at 6:25
  • $wrapper = entity_metadata_wrapper('node', $node); what is the alternative for this , can you help ,me out. – Santosh Baruah Apr 7 at 6:42
  • As @anonymous said, function entity_metadata_wrapper does not exit. You just replace with $node->field_job_title->value to get value of title. – MrD Apr 7 at 6:42

entity_metadata_wrapper() is a function implemented by the Drupal 7 version of the Entity API module. Since it returns a class wrapping the stdClass instance used from Drupal core for entities objects, and since Drupal 8 doesn't use stdClass objects for entities, that function isn't anymore necessary.

In Drupal 8, and Drupal 9, you access that field with $node->field_job_title->value or $node->get('field_job_title')->getValue().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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