public function EntityDefaultUIController::applyOperation in Entity API 7
Applies an operation to the given entity.
Note: the export operation is directly carried out by the operationForm() method.
Parameters
string $op: The operation (revert, delete or import).
$entity: The entity to manipulate.
Return value
string The status message of what has been applied.
1 call to EntityDefaultUIController::applyOperation()
- EntityDefaultUIController::operationFormSubmit in includes/
entity.ui.inc - Operation form submit callback.
File
- includes/
entity.ui.inc, line 437 - Provides a controller for building an entity overview form.
Class
- EntityDefaultUIController
- Default UI controller providing admin UI.
Code
public function applyOperation($op, $entity) {
$label = entity_label($this->entityType, $entity);
$vars = array(
'%entity' => $this->entityInfo['label'],
'%label' => $label,
);
$id = entity_id($this->entityType, $entity);
$edit_link = l(t('edit'), $this->path . '/manage/' . $id . '/edit');
switch ($op) {
case 'revert':
entity_delete($this->entityType, $id);
watchdog($this->entityType, 'Reverted %entity %label to the defaults.', $vars, WATCHDOG_NOTICE, $edit_link);
return t('Reverted %entity %label to the defaults.', $vars);
case 'delete':
entity_delete($this->entityType, $id);
watchdog($this->entityType, 'Deleted %entity %label.', $vars);
return t('Deleted %entity %label.', $vars);
case 'import':
// First check if there is any existing entity with the same ID.
$id = entity_id($this->entityType, $entity);
$entities = entity_load($this->entityType, array(
$id,
));
if ($existing_entity = reset($entities)) {
// Copy DB id and remove the new indicator to overwrite the DB record.
$idkey = $this->entityInfo['entity keys']['id'];
$entity->{$idkey} = $existing_entity->{$idkey};
unset($entity->is_new);
}
entity_save($this->entityType, $entity);
watchdog($this->entityType, 'Imported %entity %label.', $vars);
return t('Imported %entity %label.', $vars);
default:
return FALSE;
}
}