-
Notifications
You must be signed in to change notification settings - Fork 669
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(actions): adds a generic delete action
Plugins can now use action/delete?guid=$guid to delete an entity. The action file provides for an easy way to define custom translation keys, as well as a forward URL. Refs #5922
- Loading branch information
1 parent
e47785f
commit 4c35fe2
Showing
5 changed files
with
107 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
/** | ||
* Default entity delete action | ||
*/ | ||
$guid = get_input('guid'); | ||
$entity = get_entity($guid); | ||
|
||
if (!$entity instanceof ElggEntity) { | ||
register_error(elgg_echo('entity:delete:item_not_found')); | ||
forward(REFERRER); | ||
} | ||
|
||
if (!$entity->canDelete()) { | ||
register_error(elgg_echo('entity:delete:permission_denied')); | ||
forward(REFERRER); | ||
} | ||
|
||
set_time_limit(0); | ||
|
||
// determine what name to show on success | ||
$display_name = $entity->getDisplayName(); | ||
if (!$display_name) { | ||
$display_name = elgg_echo('entity:delete:item'); | ||
} | ||
|
||
$type = $entity->getType(); | ||
$subtype = $entity->getSubtype(); | ||
$container = $entity->getContainerEntity(); | ||
|
||
if (!$entity->delete()) { | ||
register_error(elgg_echo('entity:delete:fail', array($display_name))); | ||
forward(REFERRER); | ||
} | ||
|
||
// determine forward URL | ||
$forward_url = get_input('forward_url'); | ||
if (!$forward_url) { | ||
$forward_url = REFERRER; | ||
$referrer_url = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; | ||
$site_url = elgg_get_site_url(); | ||
if ($referrer_url && 0 == strpos($referrer_url, $site_url)) { | ||
$referrer_path = substr($referrer_url, 0, strlen($site_url)); | ||
$segments = explode('/', $referrer_path); | ||
if (in_array($guid, $segments)) { | ||
// referrer URL contains a reference to the entity that will be deleted | ||
$forward_url = ($container) ? $container->getURL() : ''; | ||
} | ||
} else if ($container) { | ||
$forward_url = $container->getURL() ? : ''; | ||
} | ||
} | ||
|
||
$success_keys = array( | ||
"entity:delete:$type:$subtype:success", | ||
"entity:delete:$type:success", | ||
"entity:delete:success", | ||
); | ||
|
||
foreach ($success_keys as $success_key) { | ||
if (elgg_language_key_exists($success_key)) { | ||
system_message(elgg_echo($success_key, array($display_name))); | ||
break; | ||
} | ||
} | ||
forward($forward_url); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters