signing a powershell script

code signing need to executed in administrator context

0> write a powershell script hello.ps1
1> Set-ExecutionPolicy AllSigned
2> New-SelfSignedCertificate -DnsName powershell-self-sign -Type CodeSigning

3> Set-AuthenticodeSignature C:\t\hello.ps1 @(gci Cert:\LocalMachine\My -DnsName powershell-self-sign -codesigning)[0]

4> run cert from start menu.
5> from Personal/Certificate, find powershell-self-sign cert
6> right click the cert , and copy , then paste the cert to intermediate certificate authoritties/Certificates
7> paste the cert to Trusted Root / certificate.

Leave a comment

PHPStorm 2016, vagrant, Symfony and xdebug

How to set up remote debug for symfony app.

1> go to run -> Edit Configurations

2> Click on ‘+’ symbol, top – left corner

3> adding a PHP web application, now a window popup, and give a name to this application.

4> select a server, if no server set up, following below steps.

4.1> give server a name.

4.2> your host name and port (not xdebug port)

4.3> choose xdebug

4.5> set up mapping.

for example:

if your symfony app is intalled on folder is e:\www\test\dev, and Vagrantfile is under e:\www\test, then on vagrant server,

you will have /vagrant/dev, and Symfony app’s doc root is /vagrant/dev/web/

now, use above information to set up mapping.

e:\www\test mapping to /vagrant

e:\www\test\dev mapping to /vagrant/dev

e:\www\test\dev\web mapping to /vagrant/dev/web

5> start URL set to “/”

6> select a browser.

On vagrant server side, install xdebug.

put following xdebuger content to php config file.



restart web server or php5-fpm instance.


now, go back to hosting machine. I am use windows 10.

run putty.exe, on Connection->SSH->Tunnels set up ssh tunnel.


now login into vagrant. make sure port 9000 is not been occupied.

go to phpstrom. turn on debug listener, on top – right corner.


go to File->Settings->Languages & Frameworks -> PHP -> debug, make sure xdebug port is 9000



set a break point on Symfony app,and from run -> Debug “you app” to start debugging symfony app.


Leave a comment

programatically add a new Page to Silverstripe

adding a page with page type ContactPage

if (class_exists("ContactPage") && !DataObject::get_one("ContactPage")) {
    $page = new ContactPage();
    $page->Title = _t("Contact.Title", "Contact");
    $page->Content = "";
    $page->URLSegment = "contact";
    $page->Status = "Published";
    $page->Sort = 1;
    $page->ShowInMenus = 1;
    $page->ShowInSearch = 1;
    $page->publish("Stage", "Live");
    DB::alteration_message("contact page created", 'created');

If is just a page type:
$page = new SiteTree();


$page = new Page();
To get parent page:

$parent = SiteTree::get_by_link($link);
$link is string which is a URL.

To attaching a page to a parent page:



Leave a comment

Drupal 8 , Custom Button, Editor form and Ajax

I have to add a button to a Drupal 8 content type editor form, when the button was clicked,

It passes all form values to a backend service via Ajax, and backend service will call google geo api and return latitude and longitude.

First, at default , Drupal 8 only has submit button, when you click the button, it submit whole editor form,

This is not what I want, I just want a normal button which does an Ajax call.

So, I have to create a custom button type:

Under module\src\Element, I have created a php file, called JustButton.

use Drupal\Core\Render\Element\Button;
use Drupal\Core\Render\Element;

* @FormElement(“just_button”)

class JustButton extends Button
public static function preRenderButton($element) {

$element[‘#attributes’][‘type’] = ‘button’;
Element::setAttributes($element, array(‘id’, ‘name’, ‘value’));

$element[‘#attributes’][‘class’][] = ‘button’;
if (!empty($element[‘#button_type’])) {
$element[‘#attributes’][‘class’][] = ‘button–‘ . $element[‘#button_type’];
$element[‘#attributes’][‘class’][] = ‘js-form-submit’;
$element[‘#attributes’][‘class’][] = ‘form-submit’;

if (!empty($element[‘#attributes’][‘disabled’])) {
$element[‘#attributes’][‘class’][] = ‘is-disabled’;

return $element;

Now , in my module file (netbyte_locator.module), use form hook to add JustButton to form:

pay close attention to Bold sentence: there are 2 hooks not one.

function netbyte_locator_form_node_locator_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id)
    $a  = \Drupal\Core\Url::fromRoute('locator.geoip');
    $form['Looking up latitude/longitude'] = array(
        '#type' => 'just_button',
        '#value' => t('Looking up latitude/longitude'),
        '#weight' => 40,
        '#ajax' => array(
            'url' => $a,
            'progress' => array(
                'type' => 'throbber',
                'message' => t('Looking up geo information...'),
            'event' => 'mousedown',
            'keypress' => TRUE
        '#suffix' => '<span class="geo-valid-message"></span>'


function netbyte_locator_form_node_locator_edit_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id)
    netbyte_locator_form_node_locator_form_alter($form, $form_state, $form_id);


locator.geoip is my backend service. and inside that service , I have added following code:

public function getGeoInformation($data)
    $address = $this->getAddress($data);
    $infor = \Drupal::service('netbyte_locator.geoip')->lookup($address);
    $ajax_response = new AjaxResponse();

    $lat = new InvokeCommand('#edit-field-latitude-0-value','val' , array($infor['lat']));

    $lng = new InvokeCommand('#edit-field-ongitude-0-value','val' , array($infor['lng']));

    return $ajax_response->addCommand($lng);

that 'val' is a jQuery method, equivalent to $("#edit-field-latitude-0-value").val("your value")

#edit-field-latitude-0-value (Latitude) is form input element. like below:



Leave a comment

Auto save url alias – Drupal 8

Drupal 8: Implement hook_node_insert()/update(),
call \Drupal::service(‘path.alias_storage’)->save($entity->urlInfo()->getInternalPat‌​h(), $alias, $entity->language()->getId())

1 Comment

adding category to Page

function add_taxonomies_to_pages() {
register_taxonomy_for_object_type( ‘post_tag’, ‘page’ );
register_taxonomy_for_object_type( ‘category’, ‘page’ );
add_action( ‘init’, ‘add_taxonomies_to_pages’ );

1 Comment

insert value to WordPress Post editor

v is value.


for example:

$(‘#my_id’).on(‘change’, function(){
var v = ‘my value’

Leave a comment