2

I've set my entity up with a custom controller but I want views integration. I tried to follow the entity_test.module example, but it's for one bundle. I want to create 4 bundles for my entity. When I check views it does not appear in the list.

Here is my code:

function module_entity_info() {
  $return['module_content'] = array(
    'label' => t('Module Content'),
    'module' => 'module',
    'entity class' => 'ModuleContentClass',
    'controller class' => 'EntityAPIController',
    'views controller class' => 'EntityDefaultViewsController',
    'base table' => 'module_content',
    'fieldable' => TRUE,
    'entity keys' => array(
      'id' => 'cid',
      'bundle' => 'type',
    ),
    // Make use of the class' label() and uri() implementation by default
    'label callback' => 'entity_class_label',
    'uri callback' => 'entity_class_uri',
    'static cache' => TRUE,
    'bundles' => array(),
    'bundle keys' => array(
      'bundle' => 'type',
    ),
    'view modes' => array(
      'full' => array(
        'label' => t('Full content'),
        'custom settings' => FALSE,
      ),
      'teaser' => array(
        'label' => t('Teaser'),
        'custom settings' => FALSE,
      ),
    ),
    'module_property' => array(
      'label' => t('Property'),

      'entity class' => 'Entity',
      'controller class' => 'EntityAPIControllerExportable',
      'fieldable' => TRUE,
      'bundle of' => 'module_content',
      'exportable' => TRUE,
    ),
    'module_agent' => array(
      'label' => t('Agent'),
      'entity class' => 'Entity',
      'controller class' => 'EntityAPIControllerExportable',
      'fieldable' => TRUE,
      'bundle of' => 'module_content',
      'exportable' => TRUE,
    ),
    'module_open_house' => array(
      'label' => t('Open House'),
      'entity class' => 'Entity',
      'controller class' => 'EntityAPIControllerExportable',
      'fieldable' => TRUE,
      'bundle of' => 'module_content',
      'exportable' => TRUE,
    ),
    'module_office' => array(
      'label' => t('Office'),
      'entity class' => 'Entity',
      'controller class' => 'EntityAPIControllerExportable',
      'fieldable' => TRUE,
      'bundle of' => 'module_content',
      'exportable' => TRUE,
    ),
  );

  return $return;
}

function module_entity_info_alter(&$entity_info) {
  foreach (module_content_get_types() as $type => $info) {
    $entity_info['module_content']['bundles'][$type] = array(
      'label' => $info->label,
    );
  }
}

function module_content_get_types($type = NULL) {
  $types = entity_load_multiple_by_name('module_content', isset($type) ? array($type) : FALSE);
  return isset($type) ? reset($types) : $types;
}

I think something is wrong with either module_content_get_types() or module_entity_info_alter because when I try to use dpm statements in those functions nothing is output. Please advise on any changes that should be made to improve my entity definition. If you need to see additional code I can provide that as well.

3

You dont create views integration for bundles but for entities. The reason is that each bundle by definition stores it's core data the same way.

Think of node types = bundles. When you create a view you select to use nodes (Content) not if you want to use articles, pages, blog posts etc.

  • I've specified my views controller class for my entity module_content. Why doesn't views list that entity as an option for filtering? I select content from the dropdown menu after 'Show' and the dropdown after 'of type' only lists article and page. Are my bundles not being added correctly? – Arosboro Sep 14 '11 at 21:00
  • @Arosboro Views has a lot of code specifically for how nodes work, you can do the same for your entity/bundels but the entity API module is not clever enough to make this for you. The problem is that it doesn't know what column holds the value for bundle and which values that are possible. – googletorp Sep 15 '11 at 19:43
  • I used hook_entity_property_info and my content type and fields appeared in views. I only had to define the bundles. – Arosboro Sep 16 '11 at 15:57

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.