Skip to content

Instantly share code, notes, and snippets.

@kinglozzer
Created October 18, 2015 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kinglozzer/b81ca4eb04ea42b56e78 to your computer and use it in GitHub Desktop.
Save kinglozzer/b81ca4eb04ea42b56e78 to your computer and use it in GitHub Desktop.
Config ordering

Example

TestExtensionA adds a field named “Test A”, TestExtensionB adds a field named “Test B”.

class TestExtensionA extends Extension {
	public function updateCMSFields(FieldList $fields) {
		$fields->push(TextField::create('TestA', 'Test A'));
	}
}

class TestExtensionB extends Extension {
	public function updateCMSFields(FieldList $fields) {
		$fields->push(TextField::create('TestB', 'Test B'));
	}
}

Inclusion order not set

With this configuration “Test B” would appear before “Test A”, despite being set after it in config. This example is easily fixed - you can either reverse the order, or merge the two config “blocks”. However if you are trying to control whether your extension is included before/after another module, you don’t have this control.

---
Name: 'block1'
---
Page:
  extensions:
    - TestExtensionA
---
Name: 'block2'
---
Page:
  extensions:
    - TestExtensionB

Inclusion order set

With this configuration “Test A” would appear before “Test B”. The After: '#block2' is slightly misleading - it means that block1 will be merged into the config system after block2. Think of it as “last in, first out” in this example - TestExtensionA was merged in last, so will be triggered first.

---
Name: 'block1'
After: '#block2'
---
Page:
  extensions:
    - TestExtensionA
---
Name: 'block2'
---
Page:
  extensions:
    - TestExtensionB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment