PHP code example of fastbolt / sonata-admin-protected-fields

1. Go to this page and download the library: Download fastbolt/sonata-admin-protected-fields library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fastbolt / sonata-admin-protected-fields example snippets




return [
    Fastbolt\SonataAdminProtectedFields\SonataAdminProtectedFieldsBundle::class => ['all' => true],
];



#[ORM\Column(type: 'string', length: 255)]
#[SonataAdminProtectedFields\WriteProtected]
private string $name = '';

public function isProtected(): bool
{
    return $this->isProtected;
}



#[ORM\Entity(repositoryClass: MaterialRepository::class)]
#[SonataAdminProtectedFields\DeleteProtected]
class Material



use Fastbolt\SonataAdminProtectedFields\Protection\Checker\Checker;

class MyChecker implements Checker
{
    public function getName(): string
    {
        return 'my_checker';
    }

    public function shouldBeProtected(object $item): bool 
    {
        return true;    
    }
}



use Fastbolt\SonataAdminProtectedFields\Mapping\Attributes as SonataAdminProtectedFields;

#[ORM\Entity(repositoryClass: App\Repository\MyEntityRepository::class)]
#[SonataAdminProtectedFields\DeleteProtected(checker: 'my_checker')]
class MyEntity
{
    #[ORM\Column(type: 'string', length: 18)]
    #[SonataAdminProtectedFields\WriteProtected(checker: 'my_checker')]
    private string $myField = '';
}