Skip to content

northcreation-agency/silverstripe-php-web-storm-live-templates

 
 

Repository files navigation

SilverStripe live templates

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.

Installation

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:

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.

Usage

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 = [
    ''
];

List of available templates and their contents

Fields

Direct link to the live template file: https://raw.githubusercontent.com/janneklouman/silverstripe-phpstorm-live-templates/master/SilverStripe%20PHP%20Fields.xml

cbf (check box field)

CheckboxField::create('$NAME$', $LABEL$)$END$

ddf (drop down field)

DropdownField::create(
    '$NAME$',
    $LABEL$,
    $DATALIST$
)$END$

df (date field)

DateField::create('$NAME$', $LABEL$)$END$

fg (field group)

FieldGroup::create(
    $LABEL$,
    [
        $FIELDS$
    ]
)$END$

gf (grid field)

GridField::create(
    '$NAME$',
    $LABEL$,
    $this->$DATALIST$(),
    GridFieldConfig_$TYPE$::create()
)$END$

lf (literal field)

LiteralField::create('$NAME$', $LABEL$)$END$

nf (numeric field)

NumericField::create('$NAME$', $LABEL$)$END$

tf (text field)

TextField::create('$NAME$', $LABEL$)$END$

Functions

Direct link to the live template file: https://raw.githubusercontent.com/janneklouman/silverstripe-phpstorm-live-templates/master/SilverStripe%20PHP%20Functions.xml

gcms (get cms fields)

/**
 * @return FieldList
 */
public function getCMSFields() {

    $fields = parent::getCMSFields();
    
    $END$

    return $fields;

}

log

SS_Log::log( print_r ( $END$, true ), SS_Log::WARN );

t (translate)

_t('$STRING$', '$DEFAULT$')$END$

ucms (update cms fields)

/**
 * @param FieldList $fields
 */
public function updateCMSFields(FieldList $fields) 
{
    $END$
}

"Skeletons"

Direct link to the live template file: https://raw.githubusercontent.com/janneklouman/silverstripe-phpstorm-live-templates/master/SilverStripe%20PHP%20Skeletons.xml

dofs (data object file start)

/**
 * $DESCRIPTION$
 *
 * @author $AUTHOR$
 * @package $PACKAGE$
 * @subpackage $SUBPACKAGE$
 */
class $CLASS$ extends DataObject
{
    $END$
}

defs (data extension file start)

/**
 * $DESCRIPTION$
 *
 * @author $AUTHOR$
 * @package $PACKAGE$
 * @subpackage $SUBPACKAGE$
 */
class $CLASS$Extension extends DataExtension
{
    $END$
}

efs (extension file start)

/**
 * $DESCRIPTION$
 *
 * @author $AUTHOR$
 * @package $PACKAGE$
 * @subpackage $SUBPACKAGE$
 */
class $CLASS$ extends Extension
{
    $END$
}

pfs (page file start)

/**
 * $DESCRIPTION$
 *
 * @author $AUTHOR$
 * @package $PACKAGE$
 * @subpackage $SUBPACKAGE$
 */
class $CLASS$ extends Page
{
    $END$
}

class $CLASS$_Controller extends Page_Controller 
{
}

Static variables

Direct link to the live template file: https://raw.githubusercontent.com/janneklouman/silverstripe-phpstorm-live-templates/master/SilverStripe%20PHP%20Static%20Variables.xml

aa (allowed actions)

/**
 * @var array
 */
private static $allowed_actions = [
    '$END$'
];

bmm (belongs many-many)

/**
 * @var array
 */
private static $belongs_many_many = [
    '$VAR$'  => '$END$'
];

d (defaults)

/**
 * @var array
 */
private static $defaults = [
    $END$
];

db (database)

/**
 * @var array
 */
private static $db = [
    '$VAR$' => '$END$'
];

df (default sort)

/**
 * @var string
 */
private static $default_sort '$END$';

hm (has many)

/**
 * @var array
 */
private static $has_many = [
    '$VAR$'  => '$END$'
];

ho (has one)

/**
 * @var array
 */
private static $has_one = [
    '$VAR$'  => '$END$'
];

mm (many many)

/**
 * @var array
 */
private static $many_many = [
    '$VAR$'  => '$END$'
];

mmef (many many extra fields)

/**
 * @var array
 */
private static $many_many_extraFields = [
    '$RELATION$' => [
        '$NAME$' => '$TYPE$'
    ]
];

sef (searchable fields)

/**
 * @var array
 */
private static $searchable_fields = [
    $END$
];

suf (summary fields)

/**
 * @var array
 */
private static $summary_fields = [
    $END$
];

About

⚡ Speed up development with SilverStripe live templates for PhpStorm and WebStorm

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published