function hook_entity_info_alter

You are here

7 system.api.php hook_entity_info_alter(&$entity_info)

Alter the entity info.

Modules may implement this hook to alter the information that defines an entity. All properties that are available in hook_entity_info() can be altered here.

Parameters

$entity_info: The entity info array, keyed by entity name.

See also

hook_entity_info()

Related topics

5 functions implement hook_entity_info_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

book_entity_info_alter in modules/book/book.module
Implements hook_entity_info_alter().
field_test_entity_info_alter in modules/field/tests/field_test.entity.inc
Implements hook_entity_info_alter().
forum_entity_info_alter in modules/forum/forum.module
Implements hook_entity_info_alter().
locale_entity_info_alter in modules/locale/locale.module
Implements hook_entity_info_alter().
rdf_entity_info_alter in modules/rdf/rdf.module
Implements hook_entity_info_alter().

File

modules/system/system.api.php, line 285
Hooks provided by Drupal core and the System module.

Code

function hook_entity_info_alter(&$entity_info) {
  // Set the controller class for nodes to an alternate implementation of the
  // DrupalEntityController interface.
  $entity_info['node']['controller class'] = 'MyCustomNodeController';
}

Comments

Hello,

This hook doesn't work in my template.php (my custom theme)

I want to do this :
http://www.braahm.be/posts/tuning-taxonomy-pages-page-manager-panels-vie...

<?php
function mythemename_entity_info_alter(&$entity_info){
 
$entity_info['node']['view modes']['taxonomy_listing'] = array(
   
'label' => t('Taxonomy listing'),
   
'custom settings' => TRUE,
  );
}
?>

What is the solution ?

Firstly you need to include this in a custom module, not template.php, eg.
function custommodule_entity_info_alter(&$entity_info){

Initially I couldn't get this working either, once the module was enabled the view mode was there enabled in the checkbox list, but was missing the secondary tab/button to customise it.

Cleared all caches etc., no luck.

As I wanted to only use this mode in a ubercart product, I tried changing the entity 'node' to 'product' in the code. My view mode tab now appeared, but errors abounded.

Switched it back to 'node' and tab stayed there, and now works fine with no errors...

Can anyone explain this? Is it something to do with the way that ubercart declares/creates the product content type in the product module?

I found that disabling the module that implements hook_entity_info_alter(), then re-enabling it, allows the tab for the newly created view mode to appear on the Manage Display page.

Hope this helps someone!

You don't need to re-enable the module, clearing the cache is enough.

Actually, I was having a similar issue and disabling and re-enabling the module did the trick, whereas numerous cache clears did not.