Plugin that helps you write complex migrations., (*1)
Important:
The plugin's folder should be named "migrationshelper", (*2)
Deprecated
With the release of Craft 3 on 4-4-2018, this plugin has been deprecated. You can still use this with Craft 2 but you are encouraged to use (and develop) a Craft 3 version. At this moment, I have no plans to do so., (*3)
Tips
- You don't need to install this plugin. As long as you require the helper file you can use its functions.
Helpers
getFieldGroupByName
<?php
/**
* Get a field group by name
*
* @param string $name
* @return FieldGroupModel|null
*/
$group = MigrationsHelper::getFieldGroupByName($name);
addToFieldLayout
<?php
/**
* Append a field to a source's fieldlayout programmatically.
*
* @param BaseModel $source The element's source (e.g. a EntryTypeModel or CategoryGroupModel)
* @param FieldModel $field The field's model
* @param int $index The index of the field on the tab (optional - defaults to 0)
* @param string $tabName The fieldlayout's tab (optional)
*
* @return BaseModel
*/
MigrationsHelper::addToFieldLayout(BaseModel $source, FieldModel $field, $index = 0, $tabName = '');
// Save source (e.g. Entry Type)
craft()->sections->saveEntryType($source);
changeFieldSettings
<?php
/**
* Change the settings of a given field.
*
* @param string $context The field's context (e.g. global, matrixBlockType:1, etc.)
* @param string $handle The field's handle
* @param array $attributes An array of key/value settings
*/
MigrationsHelper::changeFieldSettings($context, $handle, array $attributes);
Development
Run this from your Craft installation to test your changes to this plugin before submitting a Pull Request, (*4)
phpunit --bootstrap craft/app/tests/bootstrap.php --configuration craft/plugins/migrationshelper/phpunit.xml.dist --coverage-clover coverage.clover craft/plugins/migrationshelper/tests
Changelog
0.5.2
- Don't return source object as its already by reference
- Set an empty array as default layout for the tabName in case it does not exist yet
0.5.1
- Added MIT license to composer.json
0.5.0
- Added getFieldGroupByName helper to easily get field groups
0.4.0
- Improved unit tests for development
0.3.1
- Fixed field context not setting correctly
0.3.0
- Added the ability to insert the field on a specified (tab) index
- ElementType is not an argument anymore
- Tabname is now optional
0.2.0
- Added unit tests for development
0.1.0