Skip to content

Commit

Permalink
Mark page as edited on batch block deleting (#689)
Browse files Browse the repository at this point in the history
  • Loading branch information
vesax authored and greg0ire committed Sep 6, 2017
1 parent bf06f3d commit 385a3bf
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Admin/BaseBlockAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\BlockBundle\Block\BlockServiceManagerInterface;
use Sonata\BlockBundle\Model\BlockInterface;
Expand Down Expand Up @@ -195,6 +196,24 @@ public function getPersistentParameters()
);
}

/**
* {@inheritdoc}
*/
public function preBatchAction($actionName, ProxyQueryInterface $query, array &$idx, $allElements)
{
$parent = $this->getParent();

if ($parent && $actionName === 'delete') {
$subject = $parent->getSubject();

if ($subject instanceof PageInterface) {
$subject->setEdited(true);
}
}

parent::preBatchAction($actionName, $query, $idx, $allElements);
}

/**
* {@inheritdoc}
*/
Expand Down
35 changes: 35 additions & 0 deletions Tests/Admin/BaseBlockAdminTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\PageBundle\Tests\Admin;

use Sonata\PageBundle\Tests\Helpers\PHPUnit_Framework_TestCase;

class BaseBlockAdminTest extends PHPUnit_Framework_TestCase
{
public function testSettingAsEditedOnPreBatchDeleteAction()
{
$page = $this->createMock('Sonata\PageBundle\Model\PageInterface');
$page->expects($this->once())->method('setEdited')->with(true);

$parent = $this->createMock('Sonata\AdminBundle\Admin\AdminInterface');
$parent->expects($this->once())->method('getSubject')->will($this->returnValue($page));

$blockAdmin = $this->getMockBuilder('Sonata\PageBundle\Admin\BaseBlockAdmin')
->disableOriginalConstructor()
->getMockForAbstractClass();
$blockAdmin->setParent($parent);

$query = $this->createMock('Sonata\AdminBundle\Datagrid\ProxyQueryInterface');
$idx = array();
$blockAdmin->preBatchAction('delete', $query, $idx, true);
}
}

0 comments on commit 385a3bf

Please sign in to comment.