Booleans are nicer to read than strings or integers.

However, this crashes Flag:

function foo_flag_default_flags() {
  $flags = array();
  $flags['test_flag'] = array (
    'entity_type' => 'node',
    'title' => 'Test flag',
    'global' => FALSE,
    // ...

with this error:

> General error: 1366 Incorrect integer value: '' for column 'global' at row 1: INSERT INTO {flag} (entity_type, name, title, global, options) VALUES

It would seem that the FALSE gets cast to an empty string rather than a 0.

CommentFileSizeAuthor
#2 2059959.flag_.global-boolean.patch729 bytesjoachim
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim’s picture

I had a look at other exportables with boolean properties to see how they handle it, as casting the value to an (int) on save seemed messy.

But no, this is how node types do it:

function node_type_save($info) {
  $existing_type = !empty($info->old_type) ? $info->old_type : $info->type;
  $is_existing = (bool) db_query_range('SELECT 1 FROM {node_type} WHERE type = :type', 0, 1, array(':type' => $existing_type))->fetchField();
  $type = node_type_set_defaults($info);

  $fields = array(
    'type' => (string) $type->type,
    'name' => (string) $type->name,
    'base' => (string) $type->base,
    'has_title' => (int) $type->has_title, // <----- cast to an int here!
    // SNIP
  );

So I guess that's how we'll do it too.

joachim’s picture

Status: Active » Needs review
FileSize
729 bytes
joachim’s picture

Status: Needs review » Fixed

Tests pass. Committing.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.