Comments (6)
The problem with swapping this order is that you then have the opposite problem; user code that extends getCMSFields is then no longer able to update fields added by extensions.
The real question is, does the convention need to change?
I would argue not, as the above solution can be solved by user code that determines when fields should be overridden or not.
See the blog module for an example of how this is done:
function getCMSFields() {
SiteTree::disableCMSFieldsExtensions();
$fields = parent::getCMSFields();
SiteTree::enableCMSFieldsExtensions();
// do stuff
$this->extend('updateCMSFields', $fields);
return $fields;
}
I think a better question is, can we make it simpler and easier for users to do the above? (rather than changing the convention).
Is this better?
SiteTree.php
/**
* Delays extension of getCMSFields
* @param callable $callback
* @return FieldList
*/
protected function beforeExtendingCMSFields($callback) {
if(!self::$runCMSFieldsExtensions) {
user_error('Calls to SiteTree::beforeExtendingCMSFields cannot be nested', E_USER_ERROR);
}
self::disableCMSFieldsExtensions();
$fields = call_user_func(array($this, "parent::getCMSFields"));
$callback($fields);
self::enableCMSFieldsExtensions();
$this->extend('updateCMSFields', $fields);
return $fields;
}
MyPage.php
public function getCMSFields() {
$fields = $this->beforeExtendingCMSFields(function(FieldList &$fields){
$fields->addFieldToTab('Root.Main', new TextField('Test', 'Test'), 'Content');
});
// after extending updateCMSFields
$fields->removeByName('Root.GoogleSitemaps');
return $fields;
}
from silverstripe-framework.
Like your thinking! That defiantly makes the code a bit more explicit as to what it's trying to achieve rather than the disable() calls.
from silverstripe-framework.
Shame the code above doesn't work very well, but I'll rough something up and do some better testing.
The problem is that there's no object context in a closure, so calls to parent::getCMSFields is impossible, and workarounds are flakey.
from silverstripe-framework.
Is there a way to flag issues on Github, or can someone assign this issue to me?
from silverstripe-framework.
Issues can only be assigned to people in the organisation.
from silverstripe-framework.
Pull request is in the CMS module, including test cases. I've resolved the flakiness issue by adding a $parentClass specifier, allowing user code to tweak the behaviour where otherwise errors or infinite loops would occur.
from silverstripe-framework.
Related Issues (20)
- TinyMCE Styles-Dropdown shows incorrect empty-value HOT 2
- Add an SQL comment in dev mode showing where queries were executed
- Add generic typehints in PHPDoc HOT 2
- StandardRelatedDataService not working for complex relations HOT 2
- Make data representations in `ArrayList` more consistent
- Don't remove the `GridFieldFilterHeader` from `GridFieldConfig_RecordViewer`
- EPIC Explode framework into multiple modules
- Allow each `DataObject` subclass to define its own formfield when autoscaffolded from relation HOT 3
- Consolidate Dropdown components
- Incorrect hostname lookup when relying on `$_SERVER['HTTP_HOST']` HOT 3
- UnsavedRelationList::first() / last() return false instead of null when list is empty HOT 5
- [User Warning] Authenticator "default" doesn't support tabbed forms for Security Actions
- Toast message has problems with umlauts HOT 4
- Unused code in `FieldList::findTab()` HOT 2
- Any field using react-select has menu z-index issue when above a HTMLEditorField HOT 2
- Multiple Authenticators prevent Member password change
- PasswordField inside ConfirmedPasswordField isn't correctly marked as "required" HOT 2
- Unable to disable dev tasks via static configuration HOT 2
- Does not check the member email to send password reset link HOT 1
- switch to standard X-Forwarded-Proto instead of X-Forwarded-Protocol
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from silverstripe-framework.