2

I created a new entity type with hook_entity_info using this code:

/**
 * Implements hook_entity_info().
 */
function custom_payment_entity_info() {
    return array(
        'custom_payment_period' => array(
            'label' => t('Period'),
            'plural label' => t('Periods'),
            'entity class' => 'Entity',
            'controller class' => 'EntityAPIController',
            'base table' => 'custom_payment_periods',
            'revision table' => 'custom_payment_period_revisions',
            'entity keys' => array(
                'id' => 'pid',
                'revision' => 'pvid',
            ),
            'fieldable' => TRUE,
            'static cache' => FALSE,
            'label callback' => 'entity_class_label',
            'uri callback' => 'entity_class_uri',
            'access callback' => 'custom_payment_access',
            'module' => 'custom_payment',
            'views controller class' => 'EntityDefaultViewsController',
            'admin ui' => array(
                'path' => 'admin/config/custom/custom-payment',
                'file' => '/forms/custom_payment.period.form.inc',
                'controller class' => 'EntityDefaultUIController',
                'menu wildcard' => '%period',
            ),
            'bundles' => array(
                'period' => array(
                    'label' => t('Period'),
                    'admin' => array(
                        'path' => 'admin/config/custom/custom-payment',
                        'access arguments' => array('administrator custom payment periods'),
                    )
                )
            )
        )
    );
}

But when i try to create new entity through the admin add page i get this error:

Fatal error: Cannot access empty property in F:\xampp\htdocs\sfn\sites\all\modules\entity\includes\entity.inc on line 277

This is the form function:

function custom_payment_period_form($form, &$form_state, $period = NULL) {
    $form['period'] = array(
        '#type' => 'textfield',
        '#title' => t('Period'),
        '#size' => 5,
        '#required' => TRUE,
        '#element_validate' => array('element_validate_integer_positive'),
        '#default_value' => isset($period->period) ? $period->period : ''
    );
    $form['type'] = array(
        '#type' => 'select',
        '#title' => t('Period Type'),
        '#options' => array(
            1 => t('Day'),
            2 => t('Month'),
            3 => t('Year')
        ),
        '#required' => TRUE,
        '#default_value' => isset($period->type) ? $period->type : ''
    );
    $form['price'] = array(
        '#type' => 'textfield',
        '#title' => t('Price'),
        '#size' => 5,
        '#field_suffix' => t('SYP'),
        '#required' => TRUE,
        '#element_validate' => array('element_validate_integer_positive'),
        '#default_value' => isset($period->price) ? $period->price : ''
    );
    $form['weight'] = array(
        '#type' => 'weight',
        '#title' => t('Position'),
        '#default_value' => isset($period->weight) ? $period->weight : ''
    );
    field_attach_form('period', $period, $form, $form_state);
    $form['actions'] = array(
        '#type' => 'actions',
        'submit' => array(
            '#type' => 'submit',
            '#value' => t('Save')
        )
    );
    return $form;
}

Can you help me fix this?


It's my first time working with entity type creation i followed the entity API documentation and the video entity example found here github.com/Lullabot/entity-api-demos/tree/master/docroot/sit‌​es/… i don't know exactly what is messing here.

  • Do you have an entity create function, and/or a menu loader function for like 'menu wildcard' => '%period',. I dont really see where you're creating an empty Entity in your code for the form to use. – tenken Sep 17 '14 at 19:28
  • @tenken it's my first time working with entity type creation i followed the entity api documenation and the video entity example found here github.com/Lullabot/entity-api-demos/tree/master/docroot/sites/… i don't know exaactly what is messing here – Muhamad Bhaa Asfour Sep 17 '14 at 19:36
  • Your entity keys don't seem to include bundle, label, or language. – beth Sep 17 '14 at 20:22
  • @tenken the problem was in two things: i had to add a label entity key to fix this error and then i had to remove the 'menu wildcard' => '%period' from the admin ui array because i got an error on edit page because of it and everything worked then as expected but is there a way to create an entity type without a "label" entity key? – Muhamad Bhaa Asfour Sep 20 '14 at 7:10
0

Your entity keys don't seem to include bundle, label, or language. - @beth

0

The problem was in two things:

  • I had to add a label entity key to fix this error
  • I had to remove the 'menu wildcard' => '%period' from the admin UI array,

because I got an error on edit page because of it and everything worked then as expected. It seems there was a problem creating an entity type without a "label" entity key.

Source: OP comment.

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.