Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow admin extension to configure admin at initialize time #7144

Merged
merged 4 commits into from
May 2, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Admin/AbstractAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,13 @@ public function initialize()
$this->baseCodeRoute = $this->getCode();

$this->configure();

foreach ($this->getExtensions() as $extension) {
yann-eugone marked this conversation as resolved.
Show resolved Hide resolved
// NEXT_MAJOR: remove method_exists check
if (method_exists($extension, 'configure')) {
$extension->configure($this);
}
}
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/Admin/AbstractAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ public function getAccessMapping(AdminInterface $admin)
return [];
}

/**
* @phpstan-param AdminInterface<T> $admin
*/
public function configure(AdminInterface $admin): void
{
}

/**
* @phpstan-param AdminInterface<T> $admin
*/
Expand Down
8 changes: 8 additions & 0 deletions src/Admin/AdminExtensionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* @author Thomas Rabaix <[email protected]>
*
* @method array getAccessMapping(AdminInterface $admin)
* @method array configure(AdminInterface $admin)
yann-eugone marked this conversation as resolved.
Show resolved Hide resolved
yann-eugone marked this conversation as resolved.
Show resolved Hide resolved
* @method array configureBatchActions(AdminInterface $admin, array $actions)
* @method array configureExportFields(AdminInterface $admin, array $fields)
* @method array configureActionButtons(AdminInterface $admin, array $list, string $action, object $object)
Expand Down Expand Up @@ -165,6 +166,13 @@ public function alterObject(AdminInterface $admin, $object);
*/
public function getPersistentParameters(AdminInterface $admin);

/**
* Get a chance to configure admin before used.
*
* @phpstan-param AdminInterface<T> $admin
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could also add // NEXT_MAJOR: Uncomment this method

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will uncomment this during the merge

// public function configure(AdminInterface $admin): void;

/**
* Get a chance to add persistent parameters.
*
Expand Down