0

I am trying to programmatically add a registration type using the Entity Registration module and Drupal 7.

Currently I am using the following code:

$bundle = array(
    'type' => 'flake',
    'label' => $t('Flake'),
    'base' => 'registration',
    'custom' => TRUE,
);

$registration_type = registration_entity_set_default_settings($bundle);

registration_type_save($registration_type);

Among other thing, I have tried 'name' instead of 'label' and 'entity_registration' instead of 'registration'.

As you can probably gather, I am new to creating types of any sort. I started by working off a tutorial for creating a regular content type and did not run into any problems. Figuring out how exactly that differs from the entity registration type has been a little challenging.

1 Answer 1

1

Registration _type is just an entity type so is exactly the same as creating any other entity:

$registration_type = entity_create('registration_type', array(
    'name' => 'flake',
    'label' => 'Flake',
));
entity_save('registration_type', $registration_type);

Sometimes it helps to create an entity via the UI provided with a module and then load and inspect it to help understand what values can be provided.

For example after creating a registration type visit /devel/php (make sure devel module is enabled) and run this code:

dpm(entity_load_single('registration_type', 1));

You should see an output similar to this:

krumo output of registration type entity

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.