Skip to content

Commit

Permalink
[AllBundles] Cleanup adminlist configurator getBundleName/getEntityNa…
Browse files Browse the repository at this point in the history
…me deprecations
  • Loading branch information
acrobat committed Mar 23, 2024
1 parent 76ba43f commit 4d0376e
Show file tree
Hide file tree
Showing 39 changed files with 20 additions and 655 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,6 @@ public function canView($item)
return false;
}

public function getBundleName()
{
trigger_deprecation('kunstmaan/admin-bundle', '6.4', 'The "%s" method is deprecated and will be removed in 7.0. Use the "getEntityClass" method instead.', __METHOD__);

return 'KunstmaanAdminBundle';
}

public function getEntityName()
{
trigger_deprecation('kunstmaan/admin-bundle', '6.4', 'The "%s" method is deprecated and will be removed in 7.0. Use the "getEntityClass" method instead.', __METHOD__);

return 'Exception';
}

public function getEntityClass(): string
{
return Exception::class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
/**
* Abstract admin list configurator, this implements the most common functionality from the
* AdminListConfiguratorInterface and ExportListConfiguratorInterface
*
* @method string getEntityClass()
*/
abstract class AbstractAdminListConfigurator implements AdminListConfiguratorInterface, ExportListConfiguratorInterface
{
Expand Down Expand Up @@ -111,30 +109,9 @@ abstract class AbstractAdminListConfigurator implements AdminListConfiguratorInt
protected $orderDirection = '';

/**
* @deprecated since 6.4 and will be removed in 7.0. Implement the `getEntityClass` method instead.
*
* Return current bundle name.
*
* @return string
* @return class-string
*/
public function getBundleName()
{
// No-op
throw new \RuntimeException(sprintf('The "%s" method is no-op since 6.4 and will be removed in 7.0. Implement the `getEntityClass` method instead.', __METHOD__));
}

/**
* @deprecated since 6.4 and will be removed in 7.0. Implement the `getEntityClass` method instead.
*
* Return current entity name.
*
* @return string
*/
public function getEntityName()
{
// No-op
throw new \RuntimeException(sprintf('The "%s" method is no-op since 6.4 and will be removed in 7.0. Implement the `getEntityClass` method instead.', __METHOD__));
}
abstract public function getEntityClass(): string;

/**
* Return default repository name.
Expand All @@ -143,12 +120,6 @@ public function getEntityName()
*/
public function getRepositoryName()
{
if (!method_exists($this, 'getEntityClass')) {
trigger_deprecation('kunstmaan/adminlist-bundle', '6.4', 'Relying on "getBundleName" and "getEntityName" in your adminlist configurator is deprecated and will be removed in 7.0. Implement the "getEntityClass" method in your adminlist configurator instead.');

return sprintf('%s:%s', $this->getBundleName(), $this->getEntityName());
}

return $this->getEntityClass();
}

Expand Down Expand Up @@ -216,7 +187,7 @@ public function getAddUrlFor(array $params = [])
{
$params = array_merge($params, $this->getExtraParameters());

$friendlyName = explode('\\', method_exists($this, 'getEntityClass') ? $this->getEntityClass() : $this->getEntityName());
$friendlyName = explode('\\', $this->getEntityClass());
$friendlyName = array_pop($friendlyName);
$re = '/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/';
$a = preg_split($re, $friendlyName);
Expand Down Expand Up @@ -843,19 +814,6 @@ public function getOrderDirection()
*/
public function getPathByConvention($suffix = null)
{
// NEXT_MAJOR Remove if
if (!method_exists($this, 'getEntityClass')) {
trigger_deprecation('kunstmaan/adminlist-bundle', '6.4', 'Relying on "getBundleName" and "getEntityName" in your adminlist configurator is deprecated and will be removed in 7.0. Implement the "getEntityClass" method in your adminlist configurator instead.');

$entityName = strtolower($this->getEntityName());
$entityName = str_replace('\\', '_', $entityName);
if (empty($suffix)) {
return sprintf('%s_admin_%s', strtolower($this->getBundleName()), $entityName);
}

return sprintf('%s_admin_%s_%s', strtolower($this->getBundleName()), $entityName, $suffix);
}

$rootNamespace = strtolower(EntityDetails::getRootNamespace($this->getEntityClass()));
$rootNamespace = str_replace('\\bundle\\', '', $rootNamespace);
$entityPart = EntityDetails::getEntityPart($this->getEntityClass());
Expand All @@ -869,18 +827,6 @@ public function getPathByConvention($suffix = null)
return sprintf('%s_admin_%s_%s', $rootNamespace, $entityName, $suffix);
}

/**
* @deprecated since 6.4 and will be removed in 7.0. There is no replacement for this method.
*
* @return string
*/
public function getControllerPath()
{
trigger_deprecation('kunstmaan/adminlist-bundle', '6.4', 'Method deprecated and will be removed in 7.0. There is no replacement for this method.');

return sprintf('%s:%s', $this->getBundleName(), $this->getEntityName());
}

/**
* Return extra parameters for use in list actions.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,6 @@ private function getOtherLocalesResults(QueryBuilder $qb)
}
}

/**
* Return default repository name.
*
* @return string
*/
public function getRepositoryName()
{
// NEXT_MAJOR remove if and old sprintf return
if (!method_exists($this, 'getEntityClass')) {
return parent::getRepositoryName();
}

return sprintf('%s:%s\%s', $this->getBundleName(), 'Pages', $this->getEntityName());
}

/**
* @return EntityInterface
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ protected function doDeleteAction(AdminListConfiguratorInterface $configurator,
/** @var SlugifierInterface $slugifier */
$slugifier = $this->container->get('kunstmaan_utilities.slugifier');

if (!$this->isCsrfTokenValid('delete-' . $slugifier->slugify(method_exists($configurator, 'getEntityClass') ? $configurator->getEntityClass() : $configurator->getEntityName()), $request->request->get('token'))) {
if (!$this->isCsrfTokenValid('delete-' . $slugifier->slugify($configurator->getEntityClass()), $request->request->get('token'))) {
$indexUrl = $configurator->getIndexUrl();

return new RedirectResponse($this->generateUrl($indexUrl['path'], $indexUrl['params'] ?? []));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ The first parameter of the addField() method is the fieldname, second one is the
}
```

And at last we add our Entity name
And at last we add our Entity class

```PHP
public function getEntityName()
public function getEntityClass(): string
{
return 'Document';
return App\Entity\Document::class;
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</h3>
</div>
<form action="{{ path(adminlist.getDeleteUrlFor(item)["path"], adminlist.getDeleteUrlFor(item)[("params")] ) }}" method="POST">
<input type="hidden" name="token" value="{{ csrf_token('delete-'~(attribute(adminlist.configurator, 'getEntityClass') ? adminlist.configurator.entityClass : adminlist.configurator.entityName)|slugify) }}"/>
<input type="hidden" name="token" value="{{ csrf_token('delete-'~adminlist.configurator.entityClass|slugify) }}"/>

<!-- Body -->
<div class="modal-body">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{% if adminmenu.current %}
{{ adminmenu.current.label | trans }} {% block page_header_addition %}{% endblock %}
{% else %}
{{ attribute(adminlist.configurator, 'getEntityClass') ? adminlist.configurator.getEntityClass() : adminlist.configurator.getEntityName() }}
{{ adminlist.configurator.getEntityClass() }}
{% endif %}
</h1>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@
use Kunstmaan\AdminListBundle\AdminList\ItemAction\ItemActionInterface;
use Kunstmaan\AdminListBundle\AdminList\ListAction\ListActionInterface;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;

class AbstractAdminListConfiguratorTest extends TestCase
{
use ExpectDeprecationTrait;

/** @var AbstractAdminListConfigurator */
private $adminListConfigurator;

Expand Down Expand Up @@ -67,16 +64,6 @@ public function getEntityClass(): string
{
return \App\Entity\News::class;
}

public function getBundleName()
{
return 'App';
}

public function getEntityName()
{
return 'News';
}
};
}

Expand Down Expand Up @@ -521,16 +508,6 @@ public function testGetPathByConvention()
$this->assertEquals('app_admin_news_test', $this->adminListConfigurator->getPathByconvention('test'));
}

/**
* @group legacy
*/
public function testGetControllerPath()
{
$this->expectDeprecation('Since kunstmaan/adminlist-bundle 6.4: Method deprecated and will be removed in 7.0. There is no replacement for this method.');

$this->assertEquals('App:News', $this->adminListConfigurator->getControllerPath());
}

public function testGetExtraParameters()
{
$this->assertIsArray($this->adminListConfigurator->getExtraParameters());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,6 @@ public function getEntityClass(): string
{
return \App\Entity\User::class;
}

public function getBundleName()
{
return 'App';
}

public function getEntityName()
{
return 'User';
}
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,6 @@ public function getEntityClass(): string
{
return \App\Entity\Blog::class;
}

public function getBundleName()
{
return 'App';
}

public function getEntityName()
{
return 'Blog';
}
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,6 @@ public function __construct(EntityManagerInterface $em, AclHelper $aclHelper, $l
$this->locale = $locale;
}

/**
* @deprecated since 6.4. Use the `getEntityClass` method instead.
*
* Return current bundle name.
*
* @return string
*/
public function getBundleName()
{
trigger_deprecation('kunstmaan/article-bundle', '6.4', 'Method "%s" deprecated and will be removed in 7.0. Use the "getEntityClass" method instead.', __METHOD__);

return 'KunstmaanArticleBundle';
}

/**
* @deprecated since 6.4. Use the `getEntityClass` method instead.
*
* Return current entity name.
*
* @return string
*/
public function getEntityName()
{
trigger_deprecation('kunstmaan/article-bundle', '6.4', 'Method "%s" deprecated and will be removed in 7.0. Use the "getEntityClass" method instead.', __METHOD__);

return 'AbstractArticleAuthor';
}

public function getEntityClass(): string
{
return AbstractAuthor::class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,6 @@ public function __construct(EntityManagerInterface $em, AclHelper $aclHelper)
parent::__construct($em, $aclHelper);
}

/**
* @deprecated since 6.4. Use the `getEntityClass` method instead.
*
* Return current bundle name.
*
* @return string
*/
public function getBundleName()
{
trigger_deprecation('kunstmaan/article-bundle', '6.4', 'Method "%s" deprecated and will be removed in 7.0. Use the "getEntityClass" method instead.', __METHOD__);

return 'KunstmaanArticleBundle';
}

/**
* @deprecated since 6.4. Use the `getEntityClass` method instead.
*
* Return current entity name.
*
* @return string
*/
public function getEntityName()
{
trigger_deprecation('kunstmaan/article-bundle', '6.4', 'Method "%s" deprecated and will be removed in 7.0. Use the "getEntityClass" method instead.', __METHOD__);

return 'AbstractArticleCategory';
}

public function getEntityClass(): string
{
return AbstractCategory::class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,6 @@ public function __construct(EntityManagerInterface $em, AclHelper $aclHelper, $l
);
}

/**
* @deprecated since 6.4. Use the `getEntityClass` method instead.
*
* Return current bundle name.
*
* @return string
*/
public function getBundleName()
{
trigger_deprecation('kunstmaan/article-bundle', '6.4', 'Method "%s" deprecated and will be removed in 7.0. Use the "getEntityClass" method instead.', __METHOD__);

return 'KunstmaanArticleBundle';
}

/**
* @deprecated since 6.4. Use the `getEntityClass` method instead.
*
* Return current entity name.
*
* @return string
*/
public function getEntityName()
{
trigger_deprecation('kunstmaan/article-bundle', '6.4', 'Method "%s" deprecated and will be removed in 7.0. Use the "getEntityClass" method instead.', __METHOD__);

return 'AbstractArticlePage';
}

public function getEntityClass(): string
{
return AbstractArticlePage::class;
Expand Down
Loading

0 comments on commit 4d0376e

Please sign in to comment.