0

I can't figure this out despite hours (maybe 12hrs) of Googling and experimentation. I'm trying to integrate my custom entity with views. I am using Entity API. I don't normally dump a lot of code in these posts, but I'm not sure where to start with this one. I'm hoping someone can point me in the right direction.

@googletorp - I tried to follow your tutorial but must be missing something because I just can't get it to work.

Below are the following: 1) Entity Declarations 2) Schema 3) Screenshot of what's showing up in Views

Entity Declarations

    function bse_entity_info()
    {
        $items['bse_type'] = array(
            'label' => t('Basic Storage Entity'),
            'controller class' => 'EntityAPIController',
            'entity class' => 'Entity',
            'base table' => 'bse_type',
            'fieldable' => TRUE,
            'entity keys' => array(
                'id' => 'id',
                'label' => 'label',
                'name' => 'type',
            ),
            'exportable' => FALSE,
            'bundle of' => 'bse',
            'module' => 'bse',
            'access callback' => TRUE,
        );

        $items['bse'] = array(
            'label' => t('Basic Storage Entity'),
            'controller class' => 'EntityAPIController',
            'views controller class' => 'EntityDefaultViewsController',
            'entity class' => 'Entity',
            'base table' => 'bse',
            'fieldable' => TRUE,
            'access callback' => TRUE,
            'entity keys' => array(
                'id' => 'bid',
                'bundle' => 'type',
            ),
        'label callback' => 'entity_class_label',
            'bundles' => array(),
            'bundle keys' => array(
                'bundle' => 'type',
            ),
            'view modes' => array(
                'full' => array(
                    'label' => t('Full'),
                    'custom settings' => FALSE,
                ),
            ),
            'module' => 'bse',
        );
        return $items;
    }

    function bse_entity_info_alter(&$entity_info)
    {
     $bundles = entity_load('bse_type');
        foreach ($bundles as $type_name => $type) {
          $entity_info['bse']['bundles'][$type_name] = array(
           'label' => $type->label,
        );
        }
       }

Schema

function bse_schema()
{
    $schema['bse'] = array(
        'description' => 'BSE Table',
        'fields' => array(
            'bid' => array(
                'type' => 'serial',
                'not null' => TRUE,
                'description' => 'Primary Key: Unique entry ID.',
            ),
            'type' => array(
                'description' => 'BSE content type.',
                'type' => 'varchar',
                'length' => 32,
                'not null' => TRUE,
                'default' => '',
            ),
            'uid' => array(
                'type' => 'int',
                'unsigned' => TRUE,
                'not null' => TRUE,
                'default' => 0,
                'description' => "The {users}.uid of the associated user.",
            ),
            'created' => array(
                'type' => 'int',
                'unsigned' => TRUE,
                'not null' => TRUE,
                'default' => 0,
                'description' => "Timestamp for when this entry was created.",
            ),
            'status' => array(
                'type' => 'int',
                'unsigned' => TRUE,
                'not null' => TRUE,
                'default' => 0,
                'description' => "Status of content.",
            ),
        ),
        'foreign keys' => array(
            'uid' => array(
                'table' => 'users',
                'columns' => array('uid' => 'uid'),
            ),
            'type' => array(
                'table' => 'bse_type',
                'columns' => array('type' => 'type'),
            ),
        ),
        'primary key' => array('bid'),
    );

    $schema['bse_type'] = array(
        'description' => 'BSE Type Table',
        'fields' => array(
            'id' => array(
                'type' => 'serial',
                'not null' => TRUE,
                'description' => 'Primary Key: Unique ID.',
            ),
            'type' => array(
                'description' => 'BSE type machine name.',
                'type' => 'varchar',
                'length' => 32,
                'not null' => TRUE,
            ),
            'label' => array(
                'description' => 'The human-readable name of this bse type.',
                'type' => 'varchar',
                'length' => 255,
                'not null' => TRUE,
                'default' => '',
            ),
            'module' => array(
                'description' => 'Name of the module that defined this type.',
                'type' => 'varchar',
                'length' => 255,
                'not null' => TRUE,
                'default' => '',
            ),
            'disable' => array(
                'type' => 'int',
                'unsigned' => TRUE,
                'not null' => TRUE,
                'default' => 0,
                'description' => "1 = disabled. 0 = enabled.",
            ),
        ),
        'primary key' => array('id'),
        'unique keys' => array('type' => array('type')),
    );

    return $schema;
}

Views

enter image description here

0
2

The entities in Commerce might be useful to you. They use Entity module's wrappers, but have full views support. The GPL programmer's motto: When in doubt, steal code.

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.