Skip to content

Commit

Permalink
bug #866 Fixed the default label of the "Show" action in "list" view …
Browse files Browse the repository at this point in the history
…(javiereguiluz)

This PR was merged into the master branch.

Discussion
----------

Fixed the default label of the "Show" action in "list" view

This fixes #856.

Commits
-------

2d6bff6 Fixed the default label of the "Show" action in "list" view
  • Loading branch information
javiereguiluz committed Feb 6, 2016
2 parents 2aaa7ff + 2d6bff6 commit 04b467c
Showing 1 changed file with 43 additions and 24 deletions.
67 changes: 43 additions & 24 deletions Configuration/ActionConfigPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,13 @@ private function doNormalizeActionsConfig(array $actionsConfig, $errorOrigin = '
*/
private function doNormalizeDefaultActionsConfig(array $actionsConfig, $view)
{
$defaultActionsConfig = $this->getDefaultActions();
$defaultActions = $defaultActionsConfig[$view];
$defaultActionsConfig = $this->getDefaultActionsConfig($view);

foreach ($actionsConfig as $actionName => $actionConfig) {
if (array_key_exists($actionName, $defaultActions)) {
if (array_key_exists($actionName, $defaultActionsConfig)) {
// remove null config options but maintain empty options (this allows to set an empty label for the action)
$actionConfig = array_filter($actionConfig, function ($element) { return null !== $element; });
$actionsConfig[$actionName] = array_merge($defaultActions[$actionName], $actionConfig);
$actionsConfig[$actionName] = array_merge($defaultActionsConfig[$actionName], $actionConfig);
}
}

Expand All @@ -167,11 +166,9 @@ private function doNormalizeDefaultActionsConfig(array $actionsConfig, $view)

private function resolveActionInheritance(array $backendConfig)
{
$defaultActionsConfig = $this->getDefaultActions();

foreach ($backendConfig['entities'] as $entityName => $entityConfig) {
foreach ($this->views as $view) {
$defaultActions = $defaultActionsConfig[$view];
$defaultActions = $this->getDefaultActions($view);
$backendActions = $backendConfig[$view]['actions'];
$entityActions = $entityConfig[$view]['actions'];

Expand Down Expand Up @@ -249,15 +246,16 @@ private function processActionsConfig(array $backendConfig)
}

/**
* Returns the default actions defined by EasyAdmin for the given view.
* This allows to provide some nice defaults for backends that don't
* define their own actions.
* Returns the default configuration for all the built-in actions of the
* given view, including the actions which are not enabled by default for
* that view (e.g. the 'show' action for the 'list' view).
*
* @param string $view
*
* @return array
*/
private function getDefaultActions()
private function getDefaultActionsConfig($view)
{
// basic configuration for default actions
$actions = $this->doNormalizeActionsConfig(array(
'delete' => array('name' => 'delete', 'label' => 'action.delete', 'icon' => 'trash-o', 'css_class' => 'btn btn-default'),
'edit' => array('name' => 'edit', 'label' => 'action.edit', 'icon' => 'edit', 'css_class' => 'btn btn-primary'),
Expand All @@ -267,21 +265,42 @@ private function getDefaultActions()
'list' => array('name' => 'list', 'label' => 'action.list', 'css_class' => 'btn btn-secondary'),
));

// define which actions are enabled for each view
$actionsPerView = array(
'edit' => array('delete' => $actions['delete'], 'list' => $actions['list']),
'list' => array('edit' => $actions['edit'], 'delete' => $actions['delete'], 'search' => $actions['search'], 'new' => $actions['new']),
'new' => array('list' => $actions['list']),
'show' => array('edit' => $actions['edit'], 'delete' => $actions['delete'], 'list' => $actions['list']),
// minor tweaks for some action + view combinations
if ('list' === $view) {
$actions['delete']['icon'] = null;
$actions['delete']['css_class'] = 'text-danger';
$actions['edit']['icon'] = null;
$actions['edit']['css_class'] = 'text-primary';
}

return $actions;
}

/**
* Returns the built-in actions defined by EasyAdmin for the given view.
* This allows to provide some nice defaults for backends that don't
* define their own actions.
*
* @return array
*/
private function getDefaultActions($view)
{
$defaultActions = array();
$defaultActionsConfig = $this->getDefaultActionsConfig($view);

// actions are displayed in the same order as defined in this array
$actionsEnabledByView = array(
'edit' => array('delete', 'list'),
'list' => array('edit', 'delete', 'new', 'search'),
'new' => array('list'),
'show' => array('edit', 'delete', 'list'),
);

// minor tweaks for some action + view combinations
$actionsPerView['list']['delete']['icon'] = null;
$actionsPerView['list']['delete']['css_class'] = 'text-danger';
$actionsPerView['list']['edit']['icon'] = null;
$actionsPerView['list']['edit']['css_class'] = 'text-primary';
foreach ($actionsEnabledByView[$view] as $actionName) {
$defaultActions[$actionName] = $defaultActionsConfig[$actionName];
}

return $actionsPerView;
return $defaultActions;
}

/**
Expand Down

0 comments on commit 04b467c

Please sign in to comment.