My collection of live templates for WebStorm and PhpStorm, following PSR-2, using PHPDoc, and utilizing PHP 5.4 array shorthand syntax. These templates do not attempt cover every field, variable, nor function, but are a collection of snippets that I frequently use in my daily work. Feel free to open issues to suggest additional templates.
Download and place the template files inside your IDE's templates/
folder. Where the folder is located depends on the version and type of IDE you are using. Consult this IntelliJ article on where you'll find yours if below table does not work. Restart your IDE after placing the files in the templates folder.
OS | Path |
---|---|
Windows | <your home directory>\.<product name><version number>\config\templates |
Linux | ~\.<product name><version number>\config\templates |
OS X | ~/Library/Preferences/<product name><version number>/templates |
Direct links to specific template files:
SilverStripe PHP Fields.xml
SilverStripe PHP Functions.xml
SilverStripe PHP Skeletons.xml
SilverStripe PHP Static Variables.xml
Or you can cd
to templates/
directory and run:
git clone https://github.com/jjjjjjjjjjjjjjjjjjjj/silverstripe-php-web-storm-live-templates.git .
Then optionally remove the unused files by doing something like rm -rf .git
and rm README.md
if you don't want them in there.
When editing a PHP file you can simply type in the short code for the live template and then hit the "Choose lookup Item Replace" keymap binding (tab
by default). For example, typing in aa
then hitting tab
, would expand aa
into the following and leaving your cursor in between the single quotes:
/**
* @var array
*/
private static $allowed_actions = [
''
];
Direct link to the live template file: https://raw.githubusercontent.com/janneklouman/silverstripe-phpstorm-live-templates/master/SilverStripe%20PHP%20Fields.xml
CheckboxField::create('$NAME$', $LABEL$)$END$
DropdownField::create(
'$NAME$',
$LABEL$,
$DATALIST$
)$END$
DateField::create('$NAME$', $LABEL$)$END$
FieldGroup::create(
$LABEL$,
[
$FIELDS$
]
)$END$
GridField::create(
'$NAME$',
$LABEL$,
$this->$DATALIST$(),
GridFieldConfig_$TYPE$::create()
)$END$
LiteralField::create('$NAME$', $LABEL$)$END$
NumericField::create('$NAME$', $LABEL$)$END$
TextField::create('$NAME$', $LABEL$)$END$
Direct link to the live template file: https://raw.githubusercontent.com/janneklouman/silverstripe-phpstorm-live-templates/master/SilverStripe%20PHP%20Functions.xml
/**
* @return FieldList
*/
public function getCMSFields() {
$fields = parent::getCMSFields();
$END$
return $fields;
}
SS_Log::log( print_r ( $END$, true ), SS_Log::WARN );
_t('$STRING$', '$DEFAULT$')$END$
/**
* @param FieldList $fields
*/
public function updateCMSFields(FieldList $fields)
{
$END$
}
Direct link to the live template file: https://raw.githubusercontent.com/janneklouman/silverstripe-phpstorm-live-templates/master/SilverStripe%20PHP%20Skeletons.xml
/**
* $DESCRIPTION$
*
* @author $AUTHOR$
* @package $PACKAGE$
* @subpackage $SUBPACKAGE$
*/
class $CLASS$ extends DataObject
{
$END$
}
/**
* $DESCRIPTION$
*
* @author $AUTHOR$
* @package $PACKAGE$
* @subpackage $SUBPACKAGE$
*/
class $CLASS$Extension extends DataExtension
{
$END$
}
/**
* $DESCRIPTION$
*
* @author $AUTHOR$
* @package $PACKAGE$
* @subpackage $SUBPACKAGE$
*/
class $CLASS$ extends Extension
{
$END$
}
/**
* $DESCRIPTION$
*
* @author $AUTHOR$
* @package $PACKAGE$
* @subpackage $SUBPACKAGE$
*/
class $CLASS$ extends Page
{
$END$
}
class $CLASS$_Controller extends Page_Controller
{
}
Direct link to the live template file: https://raw.githubusercontent.com/janneklouman/silverstripe-phpstorm-live-templates/master/SilverStripe%20PHP%20Static%20Variables.xml
/**
* @var array
*/
private static $allowed_actions = [
'$END$'
];
/**
* @var array
*/
private static $belongs_many_many = [
'$VAR$' => '$END$'
];
/**
* @var array
*/
private static $defaults = [
$END$
];
/**
* @var array
*/
private static $db = [
'$VAR$' => '$END$'
];
/**
* @var string
*/
private static $default_sort '$END$';
/**
* @var array
*/
private static $has_many = [
'$VAR$' => '$END$'
];
/**
* @var array
*/
private static $has_one = [
'$VAR$' => '$END$'
];
/**
* @var array
*/
private static $many_many = [
'$VAR$' => '$END$'
];
/**
* @var array
*/
private static $many_many_extraFields = [
'$RELATION$' => [
'$NAME$' => '$TYPE$'
]
];
/**
* @var array
*/
private static $searchable_fields = [
$END$
];
/**
* @var array
*/
private static $summary_fields = [
$END$
];