[ExtendedProfile] Allow to delete custom profile field

This commit is contained in:
Diogo Cordeiro 2019-08-10 13:40:47 +01:00 committed by Diogo Peralta Cordeiro
parent fd1a7a5e68
commit 9a9fa89a0c
2 changed files with 54 additions and 2 deletions

View File

@ -23,9 +23,15 @@ if (!defined('GNUSOCIAL')) {
class ProfileDetailSettingsAction extends ProfileSettingsAction
{
/**
* Title of the page
*
* @return string Title of the page
*/
public function title()
{
// TRANS: Title for extended profile settings.
// TRANS: %%site.name%% is the name of the site.
return _m('Extended profile settings');
}

View File

@ -29,11 +29,21 @@ defined('GNUSOCIAL') || die();
class ProfilefieldsAdminPanelAction extends AdminPanelAction
{
/**
* Title of the page
*
* @return string Title of the page
*/
public function title(): string
{
return _m('Profile fields');
}
/**
* Instructions for use
*
* @return string instructions for use
*/
public function getInstructions(): string
{
return _m('GNU Social custom profile fields');
@ -45,7 +55,7 @@ class ProfilefieldsAdminPanelAction extends AdminPanelAction
$form->show();
}
public function saveSettings(): void
protected function saveField(): void
{
$field = GNUsocialProfileExtensionField::getKV('id', $this->trimmed('id'));
if (!$field) {
@ -68,6 +78,39 @@ class ProfilefieldsAdminPanelAction extends AdminPanelAction
$field->insert();
}
}
protected function removeField(): void
{
// Grab field
$field = GNUsocialProfileExtensionField::getKV('id', $this->trimmed('id'));
if (!$field) {
$this->clientError(_m('Field not found.'));
}
// Delete responses to this field
$responses = new GNUsocialProfileExtensionResponse();
$responses->extension_id = $field->id;
$responses->find();
$responses = $responses->fetchAll();
foreach ($responses as $response) {
$response->delete();
}
// Delete field
$field->delete();
}
public function saveSettings()
{
if ($this->arg('save')) {
return $this->saveField();
} else if ($this->arg('remove')) {
return $this->removeField();
}
// TRANS: Message given submitting a form with an unknown action in e-mail settings.
throw new ClientException(_('Unexpected form submission.'));
}
}
class ProfilefieldsAdminForm extends AdminForm
@ -178,6 +221,9 @@ class ProfilefieldsAdminForm extends AdminForm
*/
public function formActions(): void
{
$this->out->submit('submit', _m('Save'), 'submit', null, _m('Save new field'));
$this->out->submit('save', _m('BUTTON','Save'), 'submit', null, _m('Save field'));
if ($this->out->trimmed('edit')) {
$this->out->submit('remove', _m('BUTTON', 'Remove'), 'submit', null, _m('Remove field'));
}
}
}