Hi,
In the Entity API page, for the hook_entity_property_info it says :
field: (optional) A boolean indicating whether a property is stemming from a field.
http://www.drupalcontrib.org/api/drupal/contributions!entity!entity.api....
...but nothing more, and i was not able to find any doc or example about defining an entity property from a field.
How to declare an entity property from a field (as entities are fieldable) ?
For example, working with the group module, i can add a property the "dirty way"
With the dirty way : i create another column 'field_clean_id' in the group table, declare it with hook_schema and property with group_entity_property_info(). Actually i'm"hacking" the group module which is not great.
function group_entity_property_info() {
....
$group['field_clean_id'] = array(
'label' => t('Identifier'),
'description' => t('The identifier of the group.'),
'type' => 'text',
'setter callback' => 'entity_property_verbatim_set',
'schema_field' => 'field_clean_id',
);
With the clean way : i create a simple text field ('field_clean_id' in a custom module) attached to the "community" bundle from group. All is OK but how to define this field value as a property ?
Thanks !
P.S : here is how i created the fields for the group entity/community bundle, all is OK :
function ecv_group_install() {
// Create all the fields we are adding to our entity type.
// http://api.drupal.org/api/function/field_create_field/7
foreach (_mymodule_field_data() as $field) {
field_create_field($field);
}
// Create all the instances for our fields.
// http://api.drupal.org/api/function/field_create_instance/7
foreach (_mymodule_instance_data() as $instance) {
field_create_instance($instance);
}
}
// Create the array of information about the fields we want to create.
function _ecv_group_field_data() {
$fields = array();
fields['field_id_clean'] = array(
'translatable' => '0',
'entity_types' => array(),
'settings' => array(
'max_length' => '255',
),
'storage' => array(
'type' => 'field_sql_storage',
'settings' => array(),
'module' => 'field_sql_storage',
'active' => '1',
'details' => array(
'sql' => array(
'FIELD_LOAD_CURRENT' => array(
'field_data_field_id_clean' => array(
'value' => 'field_id_clean_value',
'format' => 'field_id_clean_format',
),
),
'FIELD_LOAD_REVISION' => array(
'field_revision_field_id_clean' => array(
'value' => 'field_id_clean_value',
'format' => 'field_id_clean_format',
),
),
),
),
),
'foreign keys' => array(
'format' => array(
'table' => 'filter_format',
'columns' => array(
'format' => 'format',
),
),
),
'indexes' => array(
'format' => array(
'format',
),
),
'field_name' => 'field_id_clean',
'type' => 'text',
'module' => 'text',
'active' => '1',
'locked' => '0',
'cardinality' => '1',
'deleted' => '0',
'columns' => array(
'value' => array(
'type' => 'varchar',
'length' => '255',
'not null' => FALSE,
),
'format' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
),
'bundles' => array(
'group' => array(
'community',
),
),
);
return $fields;
}
// Create the array of information about the instances we want to create.
function _ecv_group_instance_data() {
$instances = array();
$instances['field_id_clean'] = array(
'label' => 'ID clean',
'widget' => array(
'weight' => '1',
'type' => 'text_textfield',
'module' => 'text',
'active' => 1,
'settings' => array(
'size' => '60',
),
),
'settings' => array(
'text_processing' => '0',
'user_register_form' => FALSE,
),
'display' => array(
'default' => array(
'label' => 'above',
'type' => 'text_default',
'settings' => array(),
'module' => 'text',
'weight' => 0,
),
),
'required' => 0,
'description' => "L' identifiant de la collectivité qui sera synchronisé avec LDAP pour utilisation dans la GED.",
'default_value' => NULL,
'field_name' => 'field_id_clean',
'entity_type' => 'group',
'bundle' => 'community',
'deleted' => '0',
);
return $instances;
}
Comments
Comment #2
Roman_L CreditAttribution: Roman_L commentedComment #3
Roman_L CreditAttribution: Roman_L commentedComment #4
Roman_L CreditAttribution: Roman_L commented