Skip to content

Commit 972df4a

Browse files
committed
1.0.1. Add edit from ACP. Refactoring.
1 parent d52c3c6 commit 972df4a

File tree

13 files changed

+127
-46
lines changed

13 files changed

+127
-46
lines changed

XF/Admin/Controller/User.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace West\ColorUsername\XF\Admin\Controller;
4+
5+
class User extends XFCP_User
6+
{
7+
protected function userSaveProcess(\XF\Entity\User $user)
8+
{
9+
$form = parent::userSaveProcess($user);
10+
11+
/** @var \West\ColorUsername\XF\Entity\User $user*/
12+
$form->setup(function () use ($user)
13+
{
14+
$input = $this->filter([
15+
'w_cu_type' => 'str',
16+
'w_cu_color' => 'str',
17+
'w_cu_color_second' => 'str'
18+
]);
19+
20+
$user->setUsernameColor($input['w_cu_type'], $input['w_cu_color'], $input['w_cu_color_second']);
21+
});
22+
23+
return $form;
24+
}
25+
}

XF/Entity/User.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,28 @@ public function getColorUsernameStyles()
4040
return $styles;
4141
}
4242

43+
public function setUsernameColor($type, $color, $secondColor)
44+
{
45+
$this->w_cu_type = $type;
46+
$this->w_cu_color = $color;
47+
$this->w_cu_color_second = $secondColor;
48+
}
49+
50+
protected function _preSave()
51+
{
52+
parent::_preSave();
53+
54+
switch ($this->w_cu_type)
55+
{
56+
case 'single':
57+
if (!$this->w_cu_color) $this->error(\XF::phrase('w_cu_please_enter_correct_color'));
58+
break;
59+
case 'gradient':
60+
if (!$this->w_cu_color || !$this->w_cu_color_second) $this->error(\XF::phrase('w_cu_please_enter_correct_color'));
61+
break;
62+
}
63+
}
64+
4365
public static function getStructure(Structure $structure)
4466
{
4567
$structure = parent::getStructure($structure);

XF/Pub/Controller/Account.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,21 @@ protected function accountDetailsSaveProcess(\XF\Entity\User $visitor)
88
{
99
$form = parent::accountDetailsSaveProcess($visitor);
1010

11+
/** @var \West\ColorUsername\XF\Entity\User $visitor */
1112
if ($visitor->canChangeUsernameColor())
1213
{
13-
$form->setup(function() use($visitor)
14+
$form->setup(function() use ($visitor)
1415
{
15-
$visitor->w_cu_type = $this->filter('w_cu_type', 'str');
16-
$visitor->w_cu_color = $this->filter('w_cu_color', 'str');
16+
$input = $this->filter([
17+
'w_cu_type' => 'str',
18+
'w_cu_color' => 'str',
19+
'w_cu_color_second' => 'str'
20+
]);
1721

18-
$visitor->w_cu_color_second = $this->filter('w_cu_color_second', 'str');
19-
20-
if(($visitor->w_cu_type == 'gradient' AND (!$visitor->w_cu_color_second OR !$visitor->w_cu_color)) OR ($visitor->w_cu_type == 'single' AND !$visitor->w_cu_color))
21-
{
22-
throw $this->exception($this->error(\XF::phraseDeferred('w_cu_please_enter_correct_color')));
23-
}
24-
22+
$visitor->setUsernameColor($input['w_cu_type'], $input['w_cu_color'], $input['w_cu_color_second']);
2523
});
2624
}
25+
2726
return $form;
2827
}
2928
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"from_class": "XF\\Admin\\Controller\\User",
3+
"to_class": "West\\ColorUsername\\XF\\Admin\\Controller\\User",
4+
"execute_order": 10,
5+
"active": true
6+
}

_output/class_extensions/_metadata.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"XF-Admin-Controller-User_West-ColorUsername-XF-Admin-Controller-User.json": {
3+
"hash": "9c7e2dce4912aec3a1f54a147e8d36e3"
4+
},
25
"XF-BbCode-Renderer-Html_West-ColorUsername-XF-BbCode-Renderer-Html.json": {
36
"hash": "492b3f4491d7c450c7da7b756febda66"
47
},

_output/extension_hint.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
// ################## THIS IS A GENERATED FILE ##################
44
// DO NOT EDIT DIRECTLY. EDIT THE CLASS EXTENSIONS IN THE CONTROL PANEL.
55

6+
namespace West\ColorUsername\XF\Admin\Controller
7+
{
8+
class XFCP_User extends \XF\Admin\Controller\User {}
9+
}
10+
611
namespace West\ColorUsername\XF\BbCode\Renderer
712
{
813
class XFCP_Html extends \XF\BbCode\Renderer\Html {}

_output/template_modifications/_metadata.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"admin/w_cu_user_edit_insert_options.json": {
3+
"hash": "a7b6090b72b7c15ee12ec4d31da054a4"
4+
},
25
"public/w_cu_account_details.json": {
36
"hash": "96035c6286b26fad62943f2e7513be72"
47
},
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"template": "user_edit",
3+
"description": "",
4+
"execution_order": 10,
5+
"enabled": true,
6+
"action": "str_replace",
7+
"find": "\t\t\t\t\t\tlabel=\"{{ phrase('about') }}\"\n\t\t\t\t\t\thint=\"{{ phrase('you_may_use_bb_code') }}\" />",
8+
"replace": "$0\n\n<xf:macro template=\"public:w_cu_color_username_macros\" name=\"options\" arg-user=\"{$user}\" />"
9+
}

_output/templates/_metadata.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
{
22
"public/w_color_username.less": {
3-
"version_id": 1000091,
4-
"version_string": "1.0.0 Patch Level 1",
5-
"hash": "4b3f8df3cdbaebaf2557894eaa3abb5e"
3+
"version_id": 1000170,
4+
"version_string": "1.0.1",
5+
"hash": "9ea349c2f8dccbb134c5e2240eca3c93"
6+
},
7+
"public/w_cu_color_username_macros.html": {
8+
"version_id": 1000170,
9+
"version_string": "1.0.1",
10+
"hash": "c4ac6d03f3c22a6f64d2b5551cebe6f2"
611
},
712
"public/w_cu_username_color.html": {
8-
"version_id": 1000010,
9-
"version_string": "1.0.0 Alpha",
10-
"hash": "1e6c45a93da8ddb093935c67aa6dc210"
13+
"version_id": 1000170,
14+
"version_string": "1.0.1",
15+
"hash": "f9d7bacdef8df6a6d2437eab748966a7"
1116
}
1217
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.username--colored span {
22
background: unset;
33
color: unset;
4+
-webkit-text-fill-color: unset;
45
}

0 commit comments

Comments
 (0)