Skip to content

Commit 75f9d92

Browse files
authored
Merge pull request #6 from docwilmot/entity-flagging
Issue #5: HTTP error 500 when flagging content
2 parents ad8dfaa + 6b366a2 commit 75f9d92

File tree

3 files changed

+95
-5
lines changed

3 files changed

+95
-5
lines changed

flag.module

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function flag_autoload_info() {
3030
'flag_entity' => 'includes/flag/flag_entity.inc',
3131
'flag_flag' => 'includes/flag/flag_flag.inc',
3232
'flag_broken' => 'includes/flag/flag_flag.inc',
33+
'flagging' => 'includes/flag/flag.entity.inc',
3334
'flag_node' => 'includes/flag/flag_node.inc',
3435
'flag_comment' => 'includes/flag/flag_comment.inc',
3536

@@ -63,6 +64,7 @@ function flag_entity_info() {
6364
'label' => t('Flagging'),
6465
'controller class' => 'FlaggingController',
6566
'base table' => 'flagging',
67+
'entity class' => 'Flagging',
6668
'fieldable' => TRUE,
6769
'entity keys' => array(
6870
'id' => 'flagging_id',
@@ -130,7 +132,6 @@ function flagging_load($flagging_id, $reset = FALSE) {
130132
* An unsaved flagging object containing the property values.
131133
*/
132134
function flagging_create($values = array()) {
133-
$flagging = (object) array();
134135

135136
if (!isset($values['flag_name'])) {
136137
if (isset($values['fid'])) {
@@ -139,6 +140,7 @@ function flagging_create($values = array()) {
139140
$values['flag_name'] = $flag->name;
140141
}
141142
}
143+
$flagging = entity_create('flagging', $values);
142144

143145
// Apply the given values.
144146
foreach ($values as $key => $value) {

includes/flag.entity.inc

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,101 @@
55
* Provides supporting code for the entity/fields system.
66
*
77
* Note: We're making the <em>flaggings</em> fieldable, not the <em>flags</em>.
8-
* (In the same way that Drupal makes <em>nodes</em> fieldable, not <em>node
8+
* (In the same way that Backdrop makes <em>nodes</em> fieldable, not <em>node
99
* types</em>).
1010
*/
1111

12+
/**
13+
* Defines the flagging entity class.
14+
*/
15+
class Flagging extends Entity {
16+
17+
/**
18+
* The flagging ID.
19+
*
20+
* @var integer
21+
*/
22+
public $flagging_id;
23+
24+
/**
25+
* The flag ID.
26+
*
27+
* @var integer
28+
*/
29+
public $fid;
30+
31+
/**
32+
* The flag name.
33+
*
34+
* @var string
35+
*/
36+
public $flag_name;
37+
38+
/**
39+
* The entity type which is being flagged.
40+
*
41+
* @var string
42+
*/
43+
public $entity_type;
44+
45+
46+
/**
47+
* The entity ID.
48+
*
49+
* @var integer
50+
*/
51+
public $entity_id;
52+
53+
/**
54+
* The flagging user ID.
55+
*
56+
* @var string
57+
*/
58+
public $uid;
59+
60+
/**
61+
* The user session ID.
62+
*
63+
* @var integer
64+
*/
65+
public $sid;
66+
67+
68+
/**
69+
* Implements EntityInterface::id().
70+
*/
71+
public function id() {
72+
return $this->flagging_id;
73+
}
74+
75+
/**
76+
* Implements EntityInterface::entityType().
77+
*/
78+
public function entityType() {
79+
return 'flagging';
80+
}
81+
82+
/**
83+
* Implements EntityInterface::label().
84+
*/
85+
public function label() {
86+
return $this->flagging_id;
87+
}
88+
89+
/**
90+
* Implements EntityInterface::uri().
91+
*/
92+
public function uri() {
93+
return array(
94+
'path' => '',
95+
);
96+
}
97+
}
98+
1299
/**
13100
* Controller class for flaggings.
14101
*/
15-
class FlaggingController extends DefaultEntityController {
102+
class FlaggingController extends EntityDatabaseStorageController {
16103

17104
protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {
18105
$query = parent::buildQuery($ids, $conditions, $revision_id);

includes/flag/flag_flag.inc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ class flag_flag {
966966
* to eventually populate 'entity_id' and 'flagging_id'.
967967
*/
968968
function new_flagging($entity_id = NULL, $uid = NULL, $sid = NULL) {
969-
return (object) array(
969+
$flagging = entity_create('flagging', array(
970970
'flagging_id' => NULL,
971971
'flag_name' => $this->name,
972972
'fid' => $this->fid,
@@ -975,7 +975,8 @@ class flag_flag {
975975
'uid' => $uid,
976976
'sid' => $sid,
977977
// The timestamp is not set until this is saved.
978-
);
978+
));
979+
return $flagging;
979980
}
980981

981982
/**

0 commit comments

Comments
 (0)