1

I get this error as I was doing my work. How do I fix this fatal error?

Fatal error: Call to undefined function entity_view_mode_prepare() in .sites/all/modules/field_collection/field_collection.entity.inc on line 600

  • 2
    Make sure you're using a recent release of Drupal (that function was added in 7.33) and make sure field collection is up to date. If that doesn't fix it, we'll need some more details – Clive Dec 7 '16 at 22:46
  • What happened did you do before this happened? – Chris Happy Dec 7 '16 at 23:37
1

This error has been removed in latest drupal 7 versions. Please upgrade your drupal core version to the latest.

OR
Temporary solution: Copy and paste the below function in includes/common.inc file

function entity_view_mode_prepare($entity_type, $entities, $view_mode, $langcode = NULL) {
if (!isset($langcode)) {
$langcode = $GLOBALS['language_content']->language;
}

// To ensure hooks are never run after field_attach_prepare_view() only
// process items without the entity_view_prepared flag.
$entities_by_view_mode = array();
foreach ($entities as $id => $entity) {
$entity_view_mode = $view_mode;
if (empty($entity->entity_view_prepared)) {

  // Allow modules to change the view mode.
  $context = array(
    'entity_type' => $entity_type,
    'entity' => $entity,
    'langcode' => $langcode,
  );
drupal_alter('entity_view_mode', $entity_view_mode, $context);
}

$entities_by_view_mode[$entity_view_mode][$id] = $entity;
}

return $entities_by_view_mode;
}
  • 1
    Hi @Neeraj, thank you for the tip. It is highly discouraged to alter core files however, maybe you can provide instructions on how to deal with this error in another way? – Wim Mostrey Mar 6 '17 at 8:23
  • Please upgrade Drupal version to the latest then if you want get rid off this error. All cores files will be upgraded. This was just quick fix. – Neeraj Mar 6 '17 at 8:41
  • You can do this like below: 1. Create a directory on the site root(Next to includes) named as custom_include(in my case) 2. Create a file "custom_includes.inc" in that folder. 3. Now copy/define your function in this file 4. Load this file with the help of your custom existing module in hook_init function. require_once DRUPAL_ROOT . '/custom_includes/custom_common.inc'; 5. This file will be loaded in all over the project. – Neeraj Mar 6 '17 at 11:05

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.