Commit 14f07719 authored by tim.plunkett's avatar tim.plunkett
Browse files

Use classed entities instead of stdClass.

parent a5e71d0b
......@@ -37,7 +37,7 @@ function options_form(&$form, &$form_state) {
function render_link($data, $values) {
if (!empty($this->options['link_to_user'])) {
$account = new stdClass();
$account = entity_create('user', array());
$account->uid = $this->get_value($values, 'uid');
$account->name = $this->get_value($values);
$account->homepage = $this->get_value($values, 'homepage');
......
......@@ -40,7 +40,7 @@ function option_definition() {
function render($values) {
if (!empty($this->options['link_to_user'])) {
$account = new stdClass();
$account = entity_create('user', array());
$account->name = $this->get_value($values);
$account->uid = $values->{$this->uid};
return theme('username', array(
......
......@@ -91,9 +91,10 @@ function pre_render(&$values) {
function render_link($data, $values) {
if (!empty($this->options['link_to_comment']) && $data !== NULL && $data !== '') {
$node = new stdClass();
$node->nid = $this->get_value($values, 'nid');
$node->type = $this->get_value($values, 'type');
$node = entity_create('node', array(
'nid' => $this->get_value($values, 'nid'),
'type' => $this->get_value($values, 'type'),
));
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = 'node/' . $node->nid;
$this->options['alter']['query'] = comment_new_page_count($this->get_value($values, 'comment_count'), $this->get_value($values), $node);
......
......@@ -97,7 +97,7 @@ function render($row) {
$item_text = '';
$uri = entity_uri('comment', $comment);
$uri = $comment->uri();
$comment->link = url($uri['path'], $uri['options'] + array('absolute' => TRUE));
$comment->rss_namespaces = array();
$comment->rss_elements = array(
......
......@@ -629,7 +629,7 @@ function post_execute(&$values) {
foreach ($entities_by_type as $entity_type => $entity_ids) {
$entity_info = entity_get_info($entity_type);
if (empty($this->definition['is revision'])) {
$entities = entity_load($entity_type, $entity_ids);
$entities = entity_load_multiple($entity_type, $entity_ids);
$keys = $entity_ids;
}
else {
......@@ -639,7 +639,7 @@ function post_execute(&$values) {
$keys = array();
foreach ($entity_ids as $key => $combined) {
list($entity_id, $revision_id) = $combined;
$entity = entity_load($entity_type, array($entity_id), array($entity_info['entity keys']['revision'] => $revision_id));
$entity = entity_load_multiple($entity_type, array($entity_id), array($entity_info['entity keys']['revision'] => $revision_id));
if ($entity) {
$entities[$revision_id] = array_shift($entity);
$keys[$key] = $revision_id;
......
......@@ -107,7 +107,7 @@ function render($row) {
$item_text = '';
$uri = entity_uri('node', $node);
$uri = $node->uri();
$node->link = url($uri['path'], $uri['options'] + array('absolute' => TRUE));
$node->rss_namespaces = array();
$node->rss_elements = array(
......
......@@ -62,12 +62,13 @@ function options_form(&$form, &$form_state) {
function render_link($data, $values) {
$tid = $this->get_value($values, 'tid');
if (!empty($this->options['link_to_taxonomy']) && !empty($tid) && $data !== NULL && $data !== '') {
$term = new stdClass();
$term->tid = $tid;
$term->vid = $this->get_value($values, 'vid');
$term->vocabulary_machine_name = $values->{$this->aliases['vocabulary_machine_name']};
$term = entity_create('taxonomy_term', array(
'tid' => $tid,
'vid' => $this->get_value($values, 'vid'),
'vocabulary_machine_name' => $values->{$this->aliases['vocabulary_machine_name']},
));
$this->options['alter']['make_link'] = TRUE;
$uri = entity_uri('taxonomy_term', $term);
$uri = $term->uri();
$this->options['alter']['path'] = $uri['path'];
}
......
......@@ -44,13 +44,14 @@ function query() {
}
function render($values) {
// Mock a term object for taxonomy_term_edit_access(). Use machine name and
// Mock a term object for taxonomy_term_access(). Use machine name and
// vid to ensure compatibility with vid based and machine name based
// access checks. See http://drupal.org/node/995156
$term = new stdClass();
$term->vid = $values->{$this->aliases['vid']};
$term->vocabulary_machine_name = $values->{$this->aliases['vocabulary_machine_name']};
if (taxonomy_term_edit_access($term)) {
$term = entity_create('taxonomy_term', array(
'vid' => $values->{$this->aliases['vid']},
'vocabulary_machine_name' => $values->{$this->aliases['vocabulary_machine_name']},
));
if (taxonomy_term_access('edit', $term)) {
$text = !empty($this->options['text']) ? $this->options['text'] : t('edit');
$tid = $this->get_value($values, 'tid');
return l($text, 'taxonomy/term/'. $tid . '/edit', array('query' => drupal_get_destination()));
......
......@@ -16,7 +16,7 @@ function render_link($data, $values) {
$uid = $values->{$this->aliases['uid']};
// Build a pseudo account object to be able to check the access.
$account = new stdClass();
$account = entity_create('user', array());
$account->uid = $uid;
if ($uid && user_cancel_access($account)) {
......
......@@ -13,7 +13,7 @@
class views_handler_field_user_link_edit extends views_handler_field_user_link {
function render_link($data, $values) {
// Build a pseudo account object to be able to check the access.
$account = new stdClass();
$account = entity_create('user', array());
$account->uid = $data;
if ($data && user_edit_access($account)) {
......
......@@ -60,7 +60,7 @@ function options_form(&$form, &$form_state) {
}
function render_link($data, $values) {
$account = new stdClass();
$account = entity_create('user', array());
$account->uid = $this->get_value($values, 'uid');
$account->name = $this->get_value($values);
if (!empty($this->options['link_to_user']) || !empty($this->options['overwrite_anonymous'])) {
......
......@@ -97,7 +97,7 @@ function render($values) {
}
else {
// Fake an account object.
$account = new stdClass();
$account = entity_create('user', array());
if ($this->options['link_photo_to_profile']) {
// Prevent template_preprocess_user_picture from adding a link
// by not setting the uid.
......
......@@ -1605,7 +1605,7 @@ function get_result_entities($results, $relationship = NULL) {
}
}
$entities = entity_load($entity_type, $ids);
$entities = entity_load_multiple($entity_type, $ids);
// Re-key the array by row-index.
$result = array();
foreach ($ids as $key => $id) {
......
......@@ -32,7 +32,7 @@ class viewsHandlerArgumentCommentUserUidTest extends ViewsSqlTest {
'cid' => '',
'pid' => '',
);
return comment_save((object) $comment);
return entity_create('comment', $comment)->save();
}
function setUp() {
......
......@@ -283,10 +283,11 @@ class ViewsUIWizardTaggedWithTestCase extends ViewsUIWizardHelper {
$this->node_type_without_tags = $this->drupalCreateContentType();
// Create the vocabulary for the tag field.
$this->tag_vocabulary = new stdClass();
$this->tag_vocabulary->name = 'Views testing tags';
$this->tag_vocabulary->machine_name = 'views_testing_tags';
taxonomy_vocabulary_save($this->tag_vocabulary);
$this->tag_vocabulary = entity_create('taxonomy_vocabulary', array(
'name' => 'Views testing tags',
'machine_name' => 'views_testing_tags',
));
$this->tag_vocabulary->save();
// Create the tag field itself.
$this->tag_field = array(
......@@ -710,7 +711,7 @@ class ViewsUIWizardJumpMenuTestCase extends ViewsUIWizardHelper {
*/
function createNodeAndGetPath() {
$node = $this->drupalCreateNode();
return entity_uri('node', $node);
return $node->uri();
}
/**
......@@ -718,7 +719,7 @@ class ViewsUIWizardJumpMenuTestCase extends ViewsUIWizardHelper {
*/
function createUserAndGetPath() {
$account = $this->drupalCreateUser();
return entity_uri('user', $account);
return $account->uri();
}
/**
......@@ -726,7 +727,7 @@ class ViewsUIWizardJumpMenuTestCase extends ViewsUIWizardHelper {
*/
function createCommentAndGetPath() {
$node = $this->drupalCreateNode();
$comment = (object) array(
$comment = entity_create('comment', array(
'cid' => NULL,
'nid' => $node->nid,
'pid' => 0,
......@@ -735,26 +736,28 @@ class ViewsUIWizardJumpMenuTestCase extends ViewsUIWizardHelper {
'subject' => $this->randomName(),
'language' => LANGUAGE_NOT_SPECIFIED,
'comment_body' => array(LANGUAGE_NOT_SPECIFIED => array($this->randomName())),
);
comment_save($comment);
return entity_uri('comment', $comment);
));
$comment->save();
return $comment->uri();
}
/**
* Helper function to create a taxonomy term and return its expected path.
*/
function createTaxonomyTermAndGetPath() {
$vocabulary = new stdClass();
$vocabulary->name = $this->randomName();
$vocabulary->machine_name = drupal_strtolower($this->randomName());
taxonomy_vocabulary_save($vocabulary);
$term = new stdClass();
$term->name = $this->randomName();
$term->vid = $vocabulary->vid;
taxonomy_term_save($term);
return entity_uri('taxonomy_term', $term);
$vocabulary = entity_create('taxonomy_vocabulary', array(
'name' => $this->randomName(),
'machine_name' => drupal_strtolower($this->randomName()),
));
$vocabulary->save();
$term = entity_create('taxonomy_term', array(
'name' => $this->randomName(),
'vid' => $vocabulary->vid,
'vocabulary_machine_name' => $vocabulary->machine_name,
));
$term->save();
return $term->uri();
}
/**
......@@ -783,7 +786,7 @@ class ViewsUIWizardJumpMenuTestCase extends ViewsUIWizardHelper {
$settings = array('revision' => TRUE);
$node = $this->drupalCreateNode($settings);
$node->vid = NULL;
node_save($node);
$node->save();
return 'node/' . $node->nid . '/revisions/' . $node->vid . '/view';
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment