-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify profile editing / registration
- Loading branch information
Showing
20 changed files
with
161 additions
and
533 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 |
---|---|---|
@@ -1,15 +1,56 @@ | ||
Customize Profile | ||
================= | ||
|
||
.. note:: | ||
If the user is allowed to change some date, you can modify the profile form. It is possible to add, remove or modify form fields provided by NucleosProfileBundle. | ||
|
||
Work in progress! | ||
|
||
Add more fields | ||
--------------- | ||
How to customize a Form | ||
----------------------- | ||
|
||
- Extend ``Nucleos\ProfileBundle\Form\Model\Profile`` | ||
- Add custom form model to configuration | ||
- Use symfony FormExtensions | ||
If you want to modify the Profile form in your project there are a few steps that you should take. For example if you would like to add checkbox for accepting terms and conditions you will have to follow these steps: | ||
|
||
1. Extend ``Nucleos\UserBundle\Model\User\User`` | ||
|
||
.. code-block:: php-annotations | ||
namespace App\Model; | ||
use Nucleos\UserBundle\Model\User as BaseUser; | ||
class User extends BaseUser | ||
{ | ||
protected ?bool $termsAccepted = false; | ||
public function gettermsAccepted(): ?bool | ||
{ | ||
return $this->termsAccepted; | ||
} | ||
public function setTermsAccepted(?bool $termsAccepted): void | ||
{ | ||
$this->termsAccepted = $termsAccepted; | ||
} | ||
} | ||
2. Use Symfony Form Extensions to add fields. You can use builder to remove or modify fields as well. | ||
|
||
.. code-block:: php-annotations | ||
namespace App\Form\Type; | ||
use Symfony\Component\Form\AbstractTypeExtension; | ||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
class ProfileFormType extends AbstractTypeExtension | ||
{ | ||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
$builder->add('termsAccepted', CheckboxType::class); | ||
} | ||
public static function getExtendedTypes(): iterable | ||
{ | ||
return ['Nucleos\ProfileBundle\Form\Type\ProfileFormType']; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,7 +1,2 @@ | ||
parameters: | ||
ignoreErrors: | ||
- | ||
message: "#^Unsafe usage of new static\\(\\)\\.$#" | ||
count: 1 | ||
path: src/Form/Model/Profile.php | ||
|
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
Oops, something went wrong.