function purge_item_form_load in Purge 7.2
Function to load an item from current form values.
_state
Parameters
array $form:
Return value
object $bundle
2 calls to purge_item_form_load()
- purge_item_form_submit in includes/
purge_ui.inc - Form submit for the item form.
- purge_item_form_validate in includes/
purge_ui.inc - Form validation for the item form.
File
- includes/
purge_ui.inc, line 765 - Provides administrative interface for the Purge module.
Code
function purge_item_form_load($form, &$form_state) {
$bundle = new PurgePurgerBundleUI();
$item_action = $form_state['values']['item_action'];
// See what action is to be taken.
$item_name = $form_state['values']['machine_name'];
$item_type = $form_state['values']['item_type'];
if ($item_action == 'add' || $item_action == 'clone' || $item_action == 'example') {
switch ($item_type) {
case 'target':
$bundle->target[$item_name] = new PurgeTargetStatic();
$item = $bundle->target[$item_name];
break;
case 'domain':
$bundle->domain[$item_name] = new PurgeDomainStatic();
$item = $bundle->domain[$item_name];
break;
case 'header':
$bundle->header[$item_name] = new PurgeHeaderStatic();
$item = $bundle->header[$item_name];
break;
case 'purger':
$bundle->purger[$item_name] = new PurgePurgerBasicUrl();
$item = $bundle->purger[$item_name];
break;
}
}
elseif ($item_action == 'edit') {
$item = $bundle->{$item_type}[$item_name];
}
// First process the basic item properties
$item->name = check_plain($form_state['values']['name']);
$item->description = check_plain($form_state['values']['description']);
$item->enabled = $form_state['values']['enabled'];
// Now for each item specific property
switch ($item_type) {
case 'target':
// Start with an empty array.
$item->urls = array();
// Get the URLs from the form state.
$urls = preg_split('/$\\R?^/m', $form_state['values']['urls']);
// trims each url.
foreach ($urls as $url) {
$item->urls[] = trim($url);
}
break;
case 'domain':
$item->domains = preg_split('/$\\R?^/m', $form_state['values']['domains']);
break;
case 'header':
$headers = preg_split('/$\\R?^/m', $form_state['values']['headers']);
$item->headers = array();
foreach ($headers as $header) {
$header_key = trim(strstr($header, ":", true));
$header_value = trim(strstr($header, ":"), " :\t");
$item->headers[$header_key] = $header_value;
}
break;
case 'purger':
// Loop through all item types
foreach ($item->pointers as $pointer_type => $pointer) {
// Get the item valuea from the form
$items = $form_state['values'][$pointer_type . '_settings'];
$items_enabled = array();
// See if this was a single of multi field.
if ($form['purger'][$pointer_type][$pointer_type . '_settings']['#multiple'] == 0) {
$item_name = $items;
$item->{$pointer_type}[$item_name] = $bundle->{$pointer_type}[$item_name];
$items_enabled = array(
$items,
);
}
else {
// Multiple options form
foreach ($items as $item_name => $item_selected) {
// Check each item if it's selected
if ($item_selected != '0') {
// Point to set property to the bundle object
$item->{$pointer_type}[$item_name] = $bundle->{$pointer_type}[$item_name];
$items_enabled[] = $item_name;
}
}
}
// Set the pointers
$item->pointers[$pointer_type] = $items_enabled;
// Set the options
if (isset($bundle->type[$pointer_type]->options)) {
foreach ($bundle->type[$pointer_type]->options as $option_name => $option) {
// Check if context is type
if ($option['context'] == 'type') {
$item->options[$pointer_type][$option_name] = $form_state['values'][$pointer_type . '_' . $option_name];
}
elseif ($option['context'] == 'item') {
$item_name = $form_state['values'][$pointer_type . '_settings'];
$item->options[$pointer_type][$option_name] = $form_state['values'][$item_name . '_' . $option_name];
}
}
}
}
// Now process the purger options
foreach ($bundle->type['purger']->options as $option_name => $option) {
if ($option['context'] == 'type') {
$item->options['purger'][$option_name] = $form_state['values']['purger_' . $option_name];
}
}
break;
}
return $bundle;
}