protected function CerFieldHandler::logError in Corresponding Entity References 7.3
Logs an error, optionally against a specific entity. If the cer_debug variable is set, the error will also be set as a message.
Parameters
string $message: The untranslated message to log.
EntityDrupalWrapper $entity: The entity that has caused the error, if any.
1 call to CerFieldHandler::logError()
- CerFieldHandler::validate in includes/
CerFieldHandler.inc - Validates a potential reference. After doing a cardinality check, the reference is validated through the Field Attach API, allowing the module which owns the field to do its normal validation logic. If validation fails, the error(s) are logged.
File
- includes/
CerFieldHandler.inc, line 179 - Contains CerFieldHandler.
Class
- CerFieldHandler
- @class Handles low-level operations for a single field on a single entity. Exposes methods to add, delete and check for references. This will also iterate over the references, returning each one as an EntityDrupalWrapper object.
Code
protected function logError($message, EntityDrupalWrapper $entity = NULL) {
$variables = array(
'!field_name' => $this->field->name,
'!field_type' => $this->field->fieldTypeLabel,
'!field_label' => $this->field->label,
);
$variables['!this_type'] = $this->entity
->type();
$variables['!this_label'] = $this->entity
->label();
// If the entity has a URI, provide a link to it. Otherwise, its "link"
// will just be an unlinked label. Entity API doesn't reliably expose a url
// property on entities, and there doesn't appear to be a way to check for
// it without risking an EntityMetadataWrapperException. So I need to use
// this clunky BS instead...ugh.
$this_uri = entity_uri($this->entity
->type(), $this->entity
->value());
if (isset($this_uri)) {
$variables['!this_url'] = url($this_uri['path'], $this_uri['options']);
$variables['!this_link'] = l($this->entity
->label(), $this_uri['path'], $this_uri['options']);
}
else {
$variables['!this_link'] = $this->entity
->label();
}
if ($entity) {
$variables['!that_type'] = $entity
->type();
$variables['!that_label'] = $entity
->label();
// If the entity has a URI, link to it.
$that_uri = entity_uri($entity
->type(), $entity
->value());
if (isset($that_uri)) {
$variables['!that_url'] = url($that_uri['path'], $that_uri['options']);
$variables['!that_link'] = l($entity
->label(), $that_uri['path'], $that_uri['options']);
}
else {
$variables['!that_link'] = $entity
->label();
}
}
watchdog('cer', $message, $variables, WATCHDOG_ERROR);
if (variable_get('cer_debug', FALSE)) {
drupal_set_message(t($message, $variables), 'error');
}
}