Closed lloonnyyaa closed 6 years ago
Feel free to do this by yourself and create a PR @lloonnyyaa
Why do you need a form type to be accesible from the container. Closing it for now. If you feel like this should be fixed, please provide more information about the problem.
In the Admin bundle documentation, an example is shown for the type of ‘boolean’ (https://sonata-project.org/bundles/admin/3-x/doc/reference/action_list.html#customizing-the-fields-displayed-on-the-list-page)
Here is my code (according to the documentation of the bundle):
Here's the error:
Now I'm using Symfony Flex 3.4
When I used Symfony 3.3, I had no problems.
Declaring this service public in my own config solves the problem:
A similar problem with 'sonata.core.form.type.equal' service
Show your full admin class
<?php
namespace App\Admin;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Show\ShowMapper;
use Symfony\Component\EventDispatcher\GenericEvent;
use Symfony\Component\Form\Extension\Core\Type\{
EmailType,
ChoiceType,
TextareaType
};
use Sonata\AdminBundle\Admin\AdminInterface;
use Knp\Menu\ItemInterface as MenuItemInterface;
use App\Entity\{
Review,
User,
Company
};
class ReviewsAdmin extends AbstractAdmin {
protected $datagridValues = [
'_sort_order' => 'DESC',
'_sort_by' => 'date',
];
/**
* Form
*
* @param FormMapper $formMapper
*/
protected function configureFormFields(FormMapper $formMapper) {
$formMapper
->with('Content', array('class' => 'col-md-9'))
->add('published')
->add('about')
->add('title')
->add('rate', ChoiceType::class, [
'choices' => [
1 => 1,
2 => 2,
3 => 3,
4 => 4,
5 => 5
],
'expanded' => true,
'multiple' => false
])
->add('text', TextareaType::class)
->add('company', 'sonata_type_model', ['class' => Company::class, 'required' => false])
->end()
->with('Author', array('class' => 'col-md-3'))
->add('author', 'sonata_type_model', [
'class' => User::class,
'help' => 'select author from users or enter author name & email',
'required' => false
])
->add('authorName')
->add('authorEmail', EmailType::class, ['required' => false])
->end()
;
}
/**
* List
*
* @param ListMapper $listMapper
*/
protected function configureListFields(ListMapper $listMapper) {
$listMapper
->addIdentifier('title')
->add('company')
->add('published', 'boolean', ['editable' => true])
->add('date')
;
}
/**
* Filter
*
* @param DatagridMapper $datagridMapper
*/
protected function configureDatagridFilters(DatagridMapper $datagridMapper) {
$datagridMapper
->add('title')
->add('published')
->add('company', null, [], 'entity', [
'class' => 'App\Entity\Company',
'choice_label' => 'title',
])
;
}
/**
* Preview (show)
*
* @param ShowMapper $showMapper
*/
public function configureShowFields(ShowMapper $showMapper) {
$showMapper
->add('title')
->add('text')
->add('authorName')
->add('authorEmail')
->add('company')
;
}
protected function configureSideMenu(MenuItemInterface $menu, $action, AdminInterface $childAdmin = null) {
if (!$childAdmin && !in_array($action, ['edit', 'show'])) {
return;
}
$admin = $this->isChild() ? $this->getParent() : $this;
$id = $admin->getRequest()->get('id');
if ($this->isGranted('EDIT')) {
$menu->addChild('Edit Review', ['uri' => $admin->generateUrl('edit', ['id' => $id])]);
}
$menu->addChild('View', ['uri' => $admin->generateUrl('show', ['id' => $id])]);
if ($this->isGranted('LIST')) {
$menu->addChild('Manage Comments', [
'uri' => $admin->generateUrl('admin.comment.list', ['id' => $id])
]);
$menu->addChild('Manage Images', [
'uri' => $admin->generateUrl('admin.image.list', ['id' => $id])
]);
}
}
public function preUpdate($newReview) {
$em = $this->getModelManager()->getEntityManager($this->getClass());
$existReview = $em->getUnitOfWork()->getOriginalEntityData($newReview);
if (is_null($existReview['company']) && !is_null($newReview->getCompany())) {
$dispatcher = $this->getConfigurationPool()->getContainer()->get('event_dispatcher');
$event = new GenericEvent($newReview);
$dispatcher->dispatch('review.created', $event);
}
}
public function toString($object) {
return $object instanceof Review ? $object->getTitle() : 'Review';
}
}
This class in my repository https://github.com/lloonnyyaa/reviews/blob/master/src/Admin/ReviewsAdmin.php
🎁 @lloonnyyaa
Symfony 3.4 Error:
The "sonata.core.form.type.boolean" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.
please make the services public for compatibility with Symfony >= 3.4