Skip to content

Commit

Permalink
Fix TemplateRegistry usages
Browse files Browse the repository at this point in the history
  • Loading branch information
wbloszyk committed Sep 14, 2020
1 parent c4d0026 commit cf2b06c
Showing 1 changed file with 30 additions and 35 deletions.
65 changes: 30 additions & 35 deletions src/Admin/AbstractAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,8 @@ final public function setTemplateRegistry(MutableTemplateRegistryInterface $temp
}

/**
* @deprecated since sonata-project/admin-bundle 3.x, will be dropped in 4.0. Use TemplateRegistry services instead
*
* @param array<string, string> $templates
*/
public function setTemplates(array $templates)
Expand All @@ -1370,6 +1372,8 @@ public function setTemplates(array $templates)
}

/**
* @deprecated since sonata-project/admin-bundle 3.34, will be dropped in 4.0. Use TemplateRegistry services instead
*
* @param string $name
* @param string $template
*/
Expand Down Expand Up @@ -3061,9 +3065,7 @@ public function configureActionButtons($action, $object = null)
&& $this->hasAccess('create')
) {
$list['create'] = [
// NEXT_MAJOR: Remove this line and use commented line below it instead
'template' => $this->getTemplate('button_create'),
// 'template' => $this->getTemplateRegistry()->getTemplate('button_create'),
'template' => $this->getTemplateRegistry()->getTemplate('button_create'),
];
}

Expand All @@ -3072,9 +3074,7 @@ public function configureActionButtons($action, $object = null)
&& $this->canAccessObject('edit', $object)
) {
$list['edit'] = [
// NEXT_MAJOR: Remove this line and use commented line below it instead
'template' => $this->getTemplate('button_edit'),
//'template' => $this->getTemplateRegistry()->getTemplate('button_edit'),
'template' => $this->getTemplateRegistry()->getTemplate('button_edit'),
];
}

Expand All @@ -3083,9 +3083,7 @@ public function configureActionButtons($action, $object = null)
&& $this->canAccessObject('history', $object)
) {
$list['history'] = [
// NEXT_MAJOR: Remove this line and use commented line below it instead
'template' => $this->getTemplate('button_history'),
// 'template' => $this->getTemplateRegistry()->getTemplate('button_history'),
'template' => $this->getTemplateRegistry()->getTemplate('button_history'),
];
}

Expand All @@ -3095,9 +3093,7 @@ public function configureActionButtons($action, $object = null)
&& $this->canAccessObject('acl', $object)
) {
$list['acl'] = [
// NEXT_MAJOR: Remove this line and use commented line below it instead
'template' => $this->getTemplate('button_acl'),
// 'template' => $this->getTemplateRegistry()->getTemplate('button_acl'),
'template' => $this->getTemplateRegistry()->getTemplate('button_acl'),
];
}

Expand All @@ -3107,9 +3103,7 @@ public function configureActionButtons($action, $object = null)
&& \count($this->getShow()) > 0
) {
$list['show'] = [
// NEXT_MAJOR: Remove this line and use commented line below it instead
'template' => $this->getTemplate('button_show'),
// 'template' => $this->getTemplateRegistry()->getTemplate('button_show'),
'template' => $this->getTemplateRegistry()->getTemplate('button_show'),
];
}

Expand All @@ -3118,9 +3112,7 @@ public function configureActionButtons($action, $object = null)
&& $this->hasAccess('list')
) {
$list['list'] = [
// NEXT_MAJOR: Remove this line and use commented line below it instead
'template' => $this->getTemplate('button_list'),
// 'template' => $this->getTemplateRegistry()->getTemplate('button_list'),
'template' => $this->getTemplateRegistry()->getTemplate('button_list'),
];
}

Expand Down Expand Up @@ -3162,9 +3154,7 @@ public function getDashboardActions()
$actions['create'] = [
'label' => 'link_add',
'translation_domain' => 'SonataAdminBundle',
// NEXT_MAJOR: Remove this line and use commented line below it instead
'template' => $this->getTemplate('action_create'),
// 'template' => $this->getTemplateRegistry()->getTemplate('action_create'),
'template' => $this->getTemplateRegistry()->getTemplate('action_create'),
'url' => $this->generateUrl('create'),
'icon' => 'plus-circle',
];
Expand Down Expand Up @@ -3262,24 +3252,33 @@ public function canAccessObject($action, $object)
}

/**
* @return string[]
* @return MutableTemplateRegistryInterface
*/
protected function configureExportFields(): array
final public function getTemplateRegistry()
{
return $this->getModelManager()->getExportFields($this->getClass());
if ($this->hasTemplateRegistry()) {
return $this->templateRegistry;
}

throw new \LogicException(sprintf('Unable to find the templateRegistry for admin `%s`', static::class));
}

protected function configureQuery(ProxyQueryInterface $query): ProxyQueryInterface
final public function hasTemplateRegistry(): bool
{
return $query;
return $this->templateRegistry instanceof MutableTemplateRegistryInterface;
}

/**
* @return MutableTemplateRegistryInterface
* @return string[]
*/
final protected function getTemplateRegistry()
protected function configureExportFields(): array
{
return $this->getModelManager()->getExportFields($this->getClass());
}

protected function configureQuery(ProxyQueryInterface $query): ProxyQueryInterface
{
return $this->templateRegistry;
return $query;
}

/**
Expand Down Expand Up @@ -3425,9 +3424,7 @@ protected function buildList()
);

$fieldDescription->setAdmin($this);
// NEXT_MAJOR: Remove this line and use commented line below it instead
$fieldDescription->setTemplate($this->getTemplate('batch'));
// $fieldDescription->setTemplate($this->getTemplateRegistry()->getTemplate('batch'));
$fieldDescription->setTemplate($this->getTemplateRegistry()->getTemplate('batch'));

$mapper->add($fieldDescription, ListMapper::TYPE_BATCH);
}
Expand All @@ -3451,9 +3448,7 @@ protected function buildList()
);

$fieldDescription->setAdmin($this);
// NEXT_MAJOR: Remove this line and use commented line below it instead
$fieldDescription->setTemplate($this->getTemplate('select'));
// $fieldDescription->setTemplate($this->getTemplateRegistry()->getTemplate('select'));
$fieldDescription->setTemplate($this->getTemplateRegistry()->getTemplate('select'));

$mapper->add($fieldDescription, ListMapper::TYPE_SELECT);
}
Expand Down

0 comments on commit cf2b06c

Please sign in to comment.