public function entity_views_handler_relationship_by_bundle::options_form in Entity API 7
Add an entity type option.
Overrides views_handler_relationship::options_form
File
- views/
handlers/ entity_views_handler_relationship_by_bundle.inc, line 33 - Contains the entity_views_handler_relationship_by_bundle class.
Class
- entity_views_handler_relationship_by_bundle
- Relationship handler for entity relationships that may limit the join to one or more bundles.
Code
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
// Get the entity type and info from the table data for the base on the
// right hand side of the relationship join.
$table_data = views_fetch_data($this->definition['base']);
$entity_type = $table_data['table']['entity type'];
$entity_info = entity_get_info($entity_type);
// Get the info of the bundle entity.
foreach (entity_get_info() as $type => $info) {
if (isset($info['bundle of']) && $info['bundle of'] == $entity_type) {
$entity_bundle_info = $info;
break;
}
}
$plural_label = isset($entity_bundle_info['plural label']) ? $entity_bundle_info['plural label'] : $entity_bundle_info['label'] . 's';
$bundle_options = array();
foreach ($entity_info['bundles'] as $name => $info) {
$bundle_options[$name] = $info['label'];
}
$form['bundle_types'] = array(
'#title' => $plural_label,
'#type' => 'checkboxes',
'#description' => t('Restrict this relationship to one or more @bundles.', array(
'@bundles' => strtolower($entity_bundle_info['plural label']),
)),
'#options' => $bundle_options,
'#default_value' => $this->options['bundle_types'],
);
}