You are here

function css_injector_rule_save in CSS Injector 7.2

Save a single CSS injector rule. This custom save callback is required in order to write (or update) the CSS file on the filesystem

1 call to css_injector_rule_save()
css_injector_update_7203 in ./css_injector.install
Import the 1.x rules to the new 2.x structure
1 string reference to 'css_injector_rule_save'
css_injector_schema in ./css_injector.install
Implements hook_schema().

File

./css_injector.module, line 75
css_injector.module

Code

function css_injector_rule_save($rule) {
  $schema = ctools_export_get_schema('css_injector_rule');
  $export = $schema['export'];

  // objects should have a serial primary key. If not, simply fail to write.
  if (empty($export['primary key'])) {
    return FALSE;
  }
  $key = $export['primary key'];
  if ($rule->export_type & EXPORT_IN_DATABASE) {

    // existing record.
    $update = array(
      $key,
    );
  }
  else {

    // new record.
    $update = array();
    $rule->export_type = EXPORT_IN_DATABASE;
  }

  // rule is passed by reference, and the crid is written into it upon save
  $success = drupal_write_record('css_injector_rule', $rule, $update);
  if ($success == FALSE || empty($rule->crid)) {
    return FALSE;
  }

  // write the CSS file to the filesystem
  $file_written = file_unmanaged_save_data($rule->css, _css_injector_rule_uri($rule->crid), FILE_EXISTS_REPLACE);
  return $file_written != FALSE && is_numeric($rule->crid);
}