Skip to content

Instantly share code, notes, and snippets.

@underhilllabs
Last active December 27, 2015 19:39
Show Gist options
  • Save underhilllabs/7378647 to your computer and use it in GitHub Desktop.
Save underhilllabs/7378647 to your computer and use it in GitHub Desktop.
Code example for custom Entity
<?php
/**
* Implements hook_entity_info().
*/
function dance_code_entity_info() {
$ents['proficiency'] = array(
'label' => t('Proficiency Status'),
'plural label' => t('Proficiency Statuses'),
'fieldable' => TRUE,
'base table' => 'dance_proficiency',
'entity keys' => array(
'id' => 'dpid',
//'label' => 'title',
),
//'bundle keys' => array(),
//'bundles' => array(),
'entity class' => 'Entity',
'controller class' => 'EntityAPIController',
'admin ui' => array(
'path' => 'admin/dance/proficiency',
),
'module' => 'dance_code',
'access callback' => 'dance_code_proficiency_access',
'uri callback' => 'dance_code_proficiency_uri',
);
return $ents;
}
/**
* Implements hook_entity_property_info().
*/
function dance_code_entity_property_info() {
$info = array();
// Add meta-data about the basic node properties.
$properties = &$info['proficiency']['properties'];
$properties['dpid'] = array(
'label' => t("DANCE Proficiency ID"),
'type' => 'integer',
'description' => t("The unique ID of the node."),
'schema field' => 'dpid',
);
$properties['user'] = array(
'label' => t("Learner"),
'type' => 'user',
'description' => t("The Learner associated with the proficiency status."),
// These are "default", but you need to add them anyway (ie NOT default)
'setter callback' => 'entity_property_verbatim_set',
'getter callback' => 'entity_property_verbatim_get',
'setter permission' => 'Administer Proficiency',
'required' => TRUE,
'schema field' => 'uid',
);
$properties['assessment1'] = array(
'label' => t("Assessment number 1"),
'type' => 'proficiency_assessment',
'type' => 'node',
'bundle' => 'proficiency_assessment',
'description' => t("Node reference to first proficiency assessment"),
'setter callback' => 'entity_property_verbatim_set',
'getter callback' => 'entity_property_verbatim_get',
'setter permission' => 'Administer Proficiency',
'schema field' => 'assessment1',
);
$properties['assessment2'] = array(
'label' => t("Assessment number 2"),
'type' => 'node',
'bundle' => 'proficiency_assessment',
'description' => t("Node reference to second proficiency assessment"),
'setter callback' => 'entity_property_verbatim_set',
'getter callback' => 'entity_property_verbatim_get',
'setter permission' => 'Administer Proficiency',
'schema field' => 'assessment2',
);
$properties['sent_reminder'] = array(
'label' => t("Was learner Sent Reminder?"),
'type' => 'boolean',
'description' => t("boolean: whether learner has been sent reminder."),
'setter callback' => 'entity_property_verbatim_set',
'getter callback' => 'entity_property_verbatim_get',
'setter permission' => 'Administer Proficiency',
'schema field' => 'sent_reminder',
);
return $info;
}
<?php
/**
* Implements hook_schema().
*/
function dance_code_schema() {
$schema['dance_proficiency'] = array(
'description'=>'The table for storing DANCE coding sheets.',
'fields' => array(
'dpid' => array(
'description' => 'The primary key',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'uid' => array(
'description' => 'The id of the User',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'sent_reminder' => array(
'description' => 'boolean: whether user has been sent reminder 9 months for prof, 3 months for np',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'assessment1' => array(
'description' => 'ID of the first assessment',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
),
'assessment2' => array(
'description' => 'ID of the second assessment',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
),
'is_proficient' => array(
'description' => 'boolean: whether user is proficient',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
),
'created' => array(
'description' => 'The creation date timestamp',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'active_date' => array(
'description' => 'The date this proficiency was set to active',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
),
'active' => array(
'description' => 'Whether this is the most recent Proficiency decision',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
),
),
'primary key' => array('dpid'),
);
return $schema;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment