[ExtendedProfile] Allow to delete custom profile field
This commit is contained in:
parent
fd1a7a5e68
commit
9a9fa89a0c
|
@ -23,9 +23,15 @@ if (!defined('GNUSOCIAL')) {
|
||||||
|
|
||||||
class ProfileDetailSettingsAction extends ProfileSettingsAction
|
class ProfileDetailSettingsAction extends ProfileSettingsAction
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Title of the page
|
||||||
|
*
|
||||||
|
* @return string Title of the page
|
||||||
|
*/
|
||||||
public function title()
|
public function title()
|
||||||
{
|
{
|
||||||
// TRANS: Title for extended profile settings.
|
// TRANS: Title for extended profile settings.
|
||||||
|
// TRANS: %%site.name%% is the name of the site.
|
||||||
return _m('Extended profile settings');
|
return _m('Extended profile settings');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,11 +29,21 @@ defined('GNUSOCIAL') || die();
|
||||||
|
|
||||||
class ProfilefieldsAdminPanelAction extends AdminPanelAction
|
class ProfilefieldsAdminPanelAction extends AdminPanelAction
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Title of the page
|
||||||
|
*
|
||||||
|
* @return string Title of the page
|
||||||
|
*/
|
||||||
public function title(): string
|
public function title(): string
|
||||||
{
|
{
|
||||||
return _m('Profile fields');
|
return _m('Profile fields');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instructions for use
|
||||||
|
*
|
||||||
|
* @return string instructions for use
|
||||||
|
*/
|
||||||
public function getInstructions(): string
|
public function getInstructions(): string
|
||||||
{
|
{
|
||||||
return _m('GNU Social custom profile fields');
|
return _m('GNU Social custom profile fields');
|
||||||
|
@ -45,7 +55,7 @@ class ProfilefieldsAdminPanelAction extends AdminPanelAction
|
||||||
$form->show();
|
$form->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveSettings(): void
|
protected function saveField(): void
|
||||||
{
|
{
|
||||||
$field = GNUsocialProfileExtensionField::getKV('id', $this->trimmed('id'));
|
$field = GNUsocialProfileExtensionField::getKV('id', $this->trimmed('id'));
|
||||||
if (!$field) {
|
if (!$field) {
|
||||||
|
@ -68,6 +78,39 @@ class ProfilefieldsAdminPanelAction extends AdminPanelAction
|
||||||
$field->insert();
|
$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
|
class ProfilefieldsAdminForm extends AdminForm
|
||||||
|
@ -178,6 +221,9 @@ class ProfilefieldsAdminForm extends AdminForm
|
||||||
*/
|
*/
|
||||||
public function formActions(): void
|
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'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user