Giter VIP home page Giter VIP logo

admin-bundle's Introduction

zicht/admin-bundle

Provides integration utilities for SonataAdminBundle.

Enable dump-role-hierarchy

To make this command supply you with an actual list of roles, add the following to your sonata_admin.yml:

parameters:
    sonata.admin.security.handler.role.class: Zicht\Bundle\AdminBundle\Security\Handler\RoleSecurityHandler

sonata_admin:
    security:
        handler: sonata.admin.security.handler.role

Override Menu-events to supply other hosts

Add the following configuration to config/zicht_admin.yml to override the AdminEvents::MENU_EVENT and alter the url to a match in the list.

zicht_admin:
    menu:
        hosts:
            - site.nl.dev
            - site.nl.dev3.zicht.intern
            - a.site.nl

Duplicate entities

To duplicate an entity, add the following code:

  1. In the admin of the entity you want to duplicate, add the route:

    protected function configureRoutes(RouteCollectionInterface $collection): void
    {
        $collection->add('duplicate');
    }
    
  2. In templates/bundles/SonataAdminBundle/CRUD/edit.html.twig add the duplicate button:

    {% if admin.hasroute('duplicate') %}
        <a class="btn btn-info" href="{{ admin.generateObjectUrl('duplicate', object) }}">{{ 'admin.duplicate.text_button'|trans }}</a>
    {% endif %}
    

For an example, see https://github.com/zicht/zestor.nl/pull/155/files

Override entities

To also override the entities content (after duplication, see section above), add the following code:

  1. Add the route in the admin so the configureRoute method becomes:
    protected function configureRoutes(RouteCollectionInterface $collection): void
    {
        $collection->add('duplicate');
        $collection->add('override');
    }
    
  2. In the entity create the field copiedFrom (and its getter and setter).
    #[ORM\ManyToOne(targetEntity: Page::class)]
    #[ORM\JoinColumn(referencedColumnName: 'id', onDelete: 'SET NULL')]
    private ?Page $copiedFrom;
    
  3. In the admin of the entity, add the override-button:
    if ($this->getSubject()->getCopiedFrom()) {
        $formMapper
            ->tab('admin.tab.schedule_publication')
                ->add(
                    'copiedFrom',
                    ButtonType::class,
                    [
                        'required' => false,
                        'help' => $this->trans('admin.help.override', ['%copied_from%' => $this->getSubject()->getCopiedFrom()]),
                        'buttons' => [
                            'override' => [
                                'label' => 'admin.override.text_button',
                                'style' => 'info',
                                'route' => 'override',
                            ],
                        ],
                    ]
                )
                ->end()
            ->end();
    }
    

For an example, see https://github.com/zicht/zestor.nl/pull/155/files

Quicklist

The quicklist is an autocomplete feature. In the CMS you can place this as an extra block at the dashboard to search for entities. It is also possible to use the AutocompleteType class in admin entities.

Configuration

In your project, create templates/admin/block_admin.html.twig and add this:

{% extends sonata_block.templates.block_base %}

{% block block %}
    {{ render(controller('Zicht\\Bundle\\AdminBundle\\Controller\\QuicklistController::quicklistAction')) }}
{% endblock %}

In config/packages/zicht/admin.yaml you have the option to add multiple repositories to be searched through.

Example:

zicht_admin:
    quicklist:
        App\Entity\Page\BiographyPage:
            repository: 'App\Entity\Page\BiographyPage'
            # choose multiple fields to search in...
            fields: ['firstName', 'lastName', 'profession']
            title: Bio
        App\Entity\Page\ArticlePage:
            repository: 'App\Entity\Page\ArticlePage'
            # ...or just one field
            fields: ['title']
            title: Article
        App\Entity\Slide:
            repository: 'App\Entity\Slide'
            fields: ['title', 'internalTitle', 'image']
            title: Slide
            # by default returns 15 results if not configured explicitly
            max_results: 100

Implementation example

namespace App\Admin;

use App\Entity\Page\BiographyPage;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Form\FormMapper;
use Zicht\Bundle\AdminBundle\Form\AutocompleteType;

class FooAdmin extends AbstractAdmin
{
    protected function configureFormFields(FormMapper $form): void
    {
        $form
            ->add('somePropertyNameHere', AutocompleteType::class, [
                'repo' => BiographyPage::class,
            ]);
    }
}

Maintainers

admin-bundle's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

admin-bundle's Issues

Fix unit-test in SF3.4

PHPUnit 4.8.36 by Sebastian Bergmann and contributors.
Warning:        The Xdebug extension is not loaded
                No code coverage will be generated.

..E.................

Time: 168 ms, Memory: 8.00MB

There was 1 error:

1) ZichtTest\Bundle\AdminBundle\DependencyInjection\Compiler\EventPropagationPassTest::testCompilerPass
Declaration of Mock_ContainerBuilder_f19d254c::merge(Mock_ContainerBuilder_f19d254c $container) should be compatible with Symfony\Component\DependencyInjection\ContainerBuilder::merge(Symfony\Component\DependencyInjection\ContainerBuilder $container)

/var/www/sf3testing.nl/vendor/zicht/admin-bundle/tests/ZichtTest/Bundle/AdminBundle/DependencyInjection/Compiler/EventPropagationPassTest.php:19

FAILURES!
Tests: 20, Assertions: 38, Errors: 1.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.