public function RestfulDataProviderVariable::variableSet in RESTful 7
Sets a variable value.
If no variable name is provided in the function call, such as for POST requests, then this method will get the name from the request body.
Parameters
string $name: The name of the variable to set a value for.
boolean $full_replace: Completely replace variable values with supplied values.
3 calls to RestfulDataProviderVariable::variableSet()
- RestfulDataProviderVariable::create in plugins/
restful/ RestfulDataProviderVariable.php - Alias for $this->variableSet().
- RestfulDataProviderVariable::replace in plugins/
restful/ RestfulDataProviderVariable.php - Alias for $this->variableSet().
- RestfulDataProviderVariable::update in plugins/
restful/ RestfulDataProviderVariable.php - Alias for $this->variableSet().
File
- plugins/
restful/ RestfulDataProviderVariable.php, line 194 - Contains \RestfulDataProviderDbQuery
Class
- RestfulDataProviderVariable
- @file Contains \RestfulDataProviderDbQuery
Code
public function variableSet($name = NULL, $full_replace = TRUE) {
$request = $this
->getRequest();
static::cleanRequest($request);
// Retrieve the name and value from the request, if present.
$public_fields = $this
->getPublicFields();
// Set initial empty value for replace and create contexts.
if ($full_replace) {
$value = '';
}
foreach ($public_fields as $public_property => $info) {
// Set the name from the request if it wasn't provided.
if ($info['property'] == 'name' && isset($request[$public_property]) && empty($name)) {
$name = $request[$public_property];
}
// Overwrite empty $value with value from the request, if given.
if ($info['property'] == 'value' && isset($request[$public_property])) {
$value = $request[$public_property];
}
}
if (isset($name)) {
if (isset($value)) {
variable_set($name, $value);
// Clear the rendered cache before calling the view method.
$this
->clearRenderedCache(array(
'tb' => 'variable',
'id' => $name,
));
}
// Update contexts could have no value set; if so, do nothing.
return $this
->view($name);
}
else {
// We are in a create context with no name supplied.
throw new RestfulBadRequestException('No name property supplied');
}
}