Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #5: HTTP error 500 when flagging content #6

Merged
merged 1 commit into from
Oct 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion flag.module
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function flag_autoload_info() {
'flag_entity' => 'includes/flag/flag_entity.inc',
'flag_flag' => 'includes/flag/flag_flag.inc',
'flag_broken' => 'includes/flag/flag_flag.inc',
'flagging' => 'includes/flag/flag.entity.inc',
'flag_node' => 'includes/flag/flag_node.inc',
'flag_comment' => 'includes/flag/flag_comment.inc',

Expand Down Expand Up @@ -63,6 +64,7 @@ function flag_entity_info() {
'label' => t('Flagging'),
'controller class' => 'FlaggingController',
'base table' => 'flagging',
'entity class' => 'Flagging',
'fieldable' => TRUE,
'entity keys' => array(
'id' => 'flagging_id',
Expand Down Expand Up @@ -130,7 +132,6 @@ function flagging_load($flagging_id, $reset = FALSE) {
* An unsaved flagging object containing the property values.
*/
function flagging_create($values = array()) {
$flagging = (object) array();

if (!isset($values['flag_name'])) {
if (isset($values['fid'])) {
Expand All @@ -139,6 +140,7 @@ function flagging_create($values = array()) {
$values['flag_name'] = $flag->name;
}
}
$flagging = entity_create('flagging', $values);

// Apply the given values.
foreach ($values as $key => $value) {
Expand Down
91 changes: 89 additions & 2 deletions includes/flag.entity.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,101 @@
* Provides supporting code for the entity/fields system.
*
* Note: We're making the <em>flaggings</em> fieldable, not the <em>flags</em>.
* (In the same way that Drupal makes <em>nodes</em> fieldable, not <em>node
* (In the same way that Backdrop makes <em>nodes</em> fieldable, not <em>node
* types</em>).
*/

/**
* Defines the flagging entity class.
*/
class Flagging extends Entity {

/**
* The flagging ID.
*
* @var integer
*/
public $flagging_id;

/**
* The flag ID.
*
* @var integer
*/
public $fid;

/**
* The flag name.
*
* @var string
*/
public $flag_name;

/**
* The entity type which is being flagged.
*
* @var string
*/
public $entity_type;


/**
* The entity ID.
*
* @var integer
*/
public $entity_id;

/**
* The flagging user ID.
*
* @var string
*/
public $uid;

/**
* The user session ID.
*
* @var integer
*/
public $sid;


/**
* Implements EntityInterface::id().
*/
public function id() {
return $this->flagging_id;
}

/**
* Implements EntityInterface::entityType().
*/
public function entityType() {
return 'flagging';
}

/**
* Implements EntityInterface::label().
*/
public function label() {
return $this->flagging_id;
}

/**
* Implements EntityInterface::uri().
*/
public function uri() {
return array(
'path' => '',
);
}
}

/**
* Controller class for flaggings.
*/
class FlaggingController extends DefaultEntityController {
class FlaggingController extends EntityDatabaseStorageController {

protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {
$query = parent::buildQuery($ids, $conditions, $revision_id);
Expand Down
5 changes: 3 additions & 2 deletions includes/flag/flag_flag.inc
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ class flag_flag {
* to eventually populate 'entity_id' and 'flagging_id'.
*/
function new_flagging($entity_id = NULL, $uid = NULL, $sid = NULL) {
return (object) array(
$flagging = entity_create('flagging', array(
'flagging_id' => NULL,
'flag_name' => $this->name,
'fid' => $this->fid,
Expand All @@ -975,7 +975,8 @@ class flag_flag {
'uid' => $uid,
'sid' => $sid,
// The timestamp is not set until this is saved.
);
));
return $flagging;
}

/**
Expand Down