Skip to content

Commit

Permalink
allow AdminExtension to alter a newly created instance
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed Jul 26, 2013
1 parent 8f85e96 commit e4d073e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
7 changes: 6 additions & 1 deletion Admin/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,12 @@ public function getTemplate($name)
*/
public function getNewInstance()
{
return $this->getModelManager()->getModelInstance($this->getActiveSubClass() ?: $this->getClass());
$object = $this->getModelManager()->getModelInstance($this->getActiveSubClass() ?: $this->getClass());
foreach($this->getExtensions() as $extension) {
$extension->alterNewInstance($this, $object);
}

return $object;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions Admin/AdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,10 @@ public function validate(AdminInterface $admin, ErrorElement $errorElement, $obj
*/
public function configureQuery(AdminInterface $admin, ProxyQueryInterface $query, $context = 'list')
{}

/**
* {@inheritdoc}
*/
public function alterNewInstance(AdminInterface $admin, $object)
{}
}
8 changes: 8 additions & 0 deletions Admin/AdminExtensionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,12 @@ public function validate(AdminInterface $admin, ErrorElement $errorElement, $obj
* @return void
*/
public function configureQuery(AdminInterface $admin, ProxyQueryInterface $query, $context = 'list');

/**
* Get a chance to modify a newly created instance.
*
* @param AdminInterface $admin
* @param mixed $object
*/
public function alterNewInstance(AdminInterface $admin, $object);
}
4 changes: 2 additions & 2 deletions Admin/AdminInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public function addExtension(AdminExtensionInterface $extension);
/**
* Returns an array of extension related to the current Admin
*
* @return void
* @return AdminExtensionInterface[]
*/
public function getExtensions();

Expand Down Expand Up @@ -595,7 +595,7 @@ public function setFormGroups(array $formGroups);
* @return void
*/
public function addFormFieldDescription($name, FieldDescriptionInterface $fieldDescription);

/**
* Returns true if this admin uses ACL
*
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
CHANGELOG
=========

### 2013-07-26

* [BC BREAK] added alterNewInstance to AdminExtensionInterface
If you do not extend the AdminExtension, you need to add an empty method to
your extension classes:

public function alterNewInstance(AdminInterface $admin, $object)
{}

### 2013-07-05

* Remove qTip
Expand Down

0 comments on commit e4d073e

Please sign in to comment.