I have two entities: People and People Notes.
The People entity is in another database with the People Notes is in the local Drupal database.
Schema for People:
PeopleId
FirstName
LastName
DOB
Schema for People Notes:
NoteId
uid
PeopleId (entityReference)
Signed (Boolean)
From a post I found here, I've created a custom action called Signed to execute a PHP script with the code below -
global $user;
$entity_notes_array = array();
$entity_notes_array['uid'] = $user->uid;
$entity_notes_array['field_people_reference']['value'][0] = 1; // Using 1 to test the reference
$entity_notes_array['field_signed']['value'][0] = 1;
$entity_notes = entity_create('people_notes', $entity_notes_array);
$entity_notes->save();
I have a view created that uses the People table as its base and then I bring in the People_Notes table through an entity reference. The view also has a VBO that executes the Signed script.
Two questions:
1 - How do I save the entity People Notes? The script process with no error messages and it successfully returns with "Action Signed Petition saved", but when I got to see what was created the admin page does not list the new entity.
2 - How do I reference the PeopleId from the view?
Additional Information on People Notes
/**
* Implements hook_entity_info().
*/
function people_notes_entity_info() {
$info = array();
$info['people_notes'] = array(
'label' => t('People Notes'),
'base table' => 'people_notes',
'entity keys' => array(
'id' => 'id',
'label' => 'label',
),
'label callback' => 'entity_class_label',
'uri callback' => 'entity_class_uri',
'entity class' => 'PeopleNotesEntity',
'controller class' => 'PeopleNotesEntityController',
'views controller class' => 'PeopleNotesViewsController',
'admin ui' => array(
'path' => 'admin/peoplenotes',
'controller class' => 'PeopleNotesUIController',
'menu wildcard' => '%notes',
'file' => 'people_notes.admin.inc',
),
'module' => 'people_notes',
'access callback' => 'people_notes_access_callback',
'fieldable' => TRUE,
'bundles' => array(
'people_notes' => array(
'label' => t('People Notes'),
'admin' => array(
'path' => 'admin/peoplenotes',
'access arguments' => array('admininster notes'),
),
),
),
'view modes' => array(
'full' => array(
'label' => t('Full View'),
'custom settings' => FALSE,
),
'part' => array(
'label' => t('Partial View'),
'custom settings' => FALSE,
),
),
);
return $info;
}
function people_notes_menu() {
$items = array();
$items['peoplenotesdemo'] = array(
'title' => 'People Notes Demo Page',
'page callback' => 'people_notes_demo_page',
'access callback' => TRUE,
'menu' => 'navigation',
);
$items['notes/%notes'] = array(
'title' => 'People Notes Entity Page',
'title arguments' => array(1),
'page callback' => 'people_notes_view_entity',
'access arguments' => 'view notes',
'page arguments' => array(1),
'type' => MENU_CALLBACK,
);
return $items;
}
function people_notes_load($id) {
$people_notes = entity_load('people_notes', array($id));
return array_pop($people_notes);
}
function people_notes_save($people_notes) {
return $people_notes->save();
}
function people_notes_demo_page() {
$people_notes = entity_load('people_notes', array(1));
kpr($people_notes);
return 'Hi Notes from Mark';
}
function people_notes_page_title($people_notes){
return $people_notes->id;
}
/*function people_notes_view_entity($people_notes) {
$people_notes_entity = entity_view('people_notes', array($people_notes->id => $people_notes));
kpr($people_notes_entity);
return 'Hello Mark';
}
*/
function people_notes_view_entity($people_notes, $view_mode = 'full') {
//drupal_set_title('(' . $people_notes->id . ')');
$people_notes_entity = entity_view('people_notes', array($people_notes->id => $people_notes));
return $people_notes_entity;
}
function people_notes_permission() {
return array(
'administer notes' => array(
'title' => t('Administer Notes'),
),
'view notes' => array(
'title' => t('View Notes on a person'),
),
);
}
function people_notes_access_callback($op, $people_notes = NULL, $account = NULL) {
if (($op == 'view' && user_access('view notes', $account)) || user_access('administer notes', $account)) {
return TRUE;
} else if ($user_access('administer notes', $account)) {
return TRUE;
}
return FALSE;
}
/*
* Controller classes are located in the includes direcotory
*
*/
// ...