You are here

function party_hat_set_data_set_rules in Party 7

Same name and namespace in other branches
  1. 8.2 modules/party_hat/party_hat.module \party_hat_set_data_set_rules()

Set hat data set rules into a hat.

This should be used rather than stuffing the data set rules directly into the hat, as it removes any data sets the hat doesn't grant from the array, so the hat has no superflous items.

Note the hat will still require saving.

@todo: add a parameter to specify which data sets are being updated, if needed??

Parameters

$hat: The hat entity.

$values: An array of data set rules, keyed by data set name. These are cleaned up prior to being set into the hat, to allow form values to be passed in here.

2 calls to party_hat_set_data_set_rules()
party_hat_form_submit in modules/party_hat/party_hat.admin.inc
Form submission for the hat edit form.
party_hat_update_7005 in modules/party_hat/party_hat.install
Filter out unused data sets in hat entity data.

File

modules/party_hat/party_hat.module, line 182
party_hat.module Provides an extensible access system for parties.

Code

function party_hat_set_data_set_rules(&$hat, $values) {
  $save_values = array();
  foreach ($values as $data_set_name => $data_set_values) {

    // Values are allowed to come in as 'key' => 'key', as saved by FormAPI
    // checkboxes. Clean these up.
    foreach ($data_set_values as $key => $value) {
      $data_set_values[$key] = (bool) $value;
    }

    // Only take data sets which are needed.
    if ($data_set_values['has']) {
      $save_values[$data_set_name] = $data_set_values;
    }
  }
  $hat->data['data_sets'] = $save_values;
}