Git Product home page Git Product logo

silverstripe-php-web-storm-live-templates's Introduction

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$
];

silverstripe-php-web-storm-live-templates's People

Contributors

jjjjjjjjjjjjjjjjjjjj avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.