0

I want to create a checkbox widget in my custom entity to select multiple options.

I don't want to use the field api, instead I want to use my custom table with multiple columns, one of them shall have the values which were chosen.

For select I use the following:

$info['pricedefault']['properties']['preis_zeiteinheit'] = array(
'label' => t('Time unit'),
'description' => t('Preis Zeiteinheit'),
'type' => 'integer',
'schema field' => 'preis_zeiteinheit',
'options list' => 'zeiteinheit_options_list',
'translatable' => TRUE, 
);

and

function zeiteinheit_options_list(){
return array(0=>t('0'),1 => t('YEAR'),2 =>t('MONTH'),3=>t('WEEK'),4=>t('DAY'));
}

But how to write a checkbox function with the correct table column?

Thx in advance,

maen

0

To store multiple value property values, without the field API, you may find it easier to create a generic extended properties table for one-to-many relationship with the base table.

e.g a table

Table: my_entity_properties

Columns: entity_id | revision_id | name | value

You can then store the extended properties in that table in the save function for your entity - each field value will be a row with the property name and value pair. You then load them in the attachLoad function, grouping by the revision_id and property name to load the values for that entity revision.

  • First of all thank you for your reply. Bu how do I save one form element in this new table within the form for the existing big table?" – maen Sep 29 '14 at 23:58
  • Drupal not so clever to understand what value from form belongs to your entity in this case. For that reason there is field api. If you want insert this value you can for example add some property to your form element. And then in form alter insert value from element to your entity. But better and more correctly is make entity fieildable. – FriOne Sep 30 '14 at 0:34
  • @maen you can add the property to the entity in the form submit handler. – David Thomas Sep 30 '14 at 3:08

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.