The good news about upgrading to Drupal 8 is that it looks a lot like Symfony, the bad news is that upgrading to Drupal 8 looks a lot like Symfony.  I guess it’s just your perspective but if you have a lot of sites steeped deeply in D7, it’s quite a transition.  However, if most of your code is a Symfony or other MVC-based framework based web dev shop without much invested in prior versions of Drupal, this transition will not only be easy, you will find your web team able to already recognize, find, and be completely familiar with all the essential organizational patterns under D8’s hood.

Red Crackle has a good list for those looking to transition from Drupal 7 to Drupal 8, just click here to read their list.

Information about migrating from Drupal 7 to Drupal 8 can be found here.

Here’s a useful video/overview of the transition and the major pros and cons.

 

 


I created this page as a running repository of useful, miscellaneous web notes for later reference.


Javascript & JQuery

How to get the latest version of JQuery:

alert('JQuery: '+$.fn.jquery);   // Outputs JQuery: x.x.x

Useful info about Javascript and JQuery source maps — an explanation about what they are and how they are used:

http://elijahmanor.com/the-magic-of-the-jquery-1-9-source-map/

Parsley — A reliable and easy Javascript form validation library:

http://parsleyjs.org/

Get hostname in Javascript:

// For the host name only, use:

window.location.hostname

Server Notes, LAMP/WAMP

Latest WAMP install instructions — in less than 5 minutes you can deploy WAMP with MySQL server on localhost.  Not bad for quick local dev server.

http://forum.wampserver.com/read.php?2,123606


Symfony

A utility for Symfony to convert those awful annotations to YML files:

https://packagist.org/packages/sed/route-exporter-bundle


Helpful Symfony 3.0 base commit, to start new PHP Symfony projects:

https://github.com/itrascastro/Symfony-3-Base-Project
https://github.com/keefekwan/symfony2_forms

Best example of a form collection at work I think is here (many thanks to the programmers making these publicly accessible!)

https://github.com/sevnekish/user_manager


Symfony 2 performance tips:

http://labs.octivi.com/mastering-symfony2-performance-internals/

Form Type setDefaultOptions weird error:

http://stackoverflow.com/questions/31659102/symfony2-error-on-submitting-form-with-a-collection-of-forms-warning-spl-obj?rq=1


General Web Notes & Utilities

Free OST file viewer worked well, allows you to save a person’s Microsoft Exchange mailbox email file and open and view the contents without messing with the .ost file in Outlook!

http://www.ostviewer.com/

Waka Time — Free web development time tracking utility:

https://wakatime.com

Websites that show the latest hiring trends in the tech industry:
https://news.ycombinator.com/item?id=11202954

https://whoishiring.io/#!/stats/

A good simplified explanation and list about HTTP 2:

https://www.keycdn.com/support/http2/

Good article about the anatomy of a URL:

http://www.skorks.com/2010/05/what-every-developer-should-know-about-urls/

Steps for setting up DNS on a Ubuntu server:

http://mixeduperic.com/ubuntu/seven-easy-steps-to-setting-up-an-interal-dns-server-on-ubuntu.html


PHP/MySQL

PHP SQL injection – good article:

http://phpdelusions.net/sql_injection



Aaron Belchamber
22 years experience in marketing and building businesses

Senior PHP & Symfony Web Developer, Business Analyst, Marketing Director
Belchamber.us / TopDocsTalk.com
(904) 294-0803 • Jacksonville, Florida


This is a very useful Twig that I use in a lot of different forms.  I attach a listener and when they click “Update” it will redirect the user by appending the URL with the /year/month to hook nice and cleanly in built-in routes to pass the year and month into different controllers.

<form id="yearMonthWidget" name="newDate1" method="get" action="">

   <select name="month">
      {% for mo in 1..12 %}
         <option value="{{ mo }}">{{ ('2012-' ~mo~'-01')|date("M") }}</option>
      {% endfor %}

   </select>

   <select name="year">
      {% for yr in "now"|date("Y")+1..2010 %}
         <option value="{{ yr }}">{{ yr }}</option>
      {% endfor %}
   </select>
   <input type="submit" value="Update"/>
</form>

 


In Symfony using Doctrine, if no association is available for two entities, you can still join them and treat them like they have a relationship.  To do so, you have to use the “Join: WITH” method.  Here’s an example query to illustrate, notice the “a.user = u.id”.

public function getHistory($users) {

    $qb = $this->entityManager->createQueryBuilder();
    $qb ->select('a', 'u')
        ->from('Credit\Entity\UserHistory', 'a')
        ->leftJoin(
            'User\Entity\User',
            'u',
            \Doctrine\ORM\Query\Expr\Join::WITH,
            'a.user = u.id'
        )
        ->where('u = :user')
        ->setParameter('user', $users)
        ->orderBy('a.created_at', 'DESC');

    return $qb->getQuery()->getResult();
}

Some other helpful links on Stack Overflow:

http://stackoverflow.com/questions/15087933/how-to-do-left-join-in-doctrine

http://stackoverflow.com/questions/19185587/left-join-on-condition-and-other-condition-syntax-in-doctrine/19189240#19189240

Here’s a great reference for advanced Doctrine queries:

http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/query-builder.html#high-level-api-methods


Integrating a WordPress user login with Symfony is pretty painless if you need to share user sessions.  Just don’t rely solely on that WordPress cookie, but cross reference a randomly assigned hash that can reference back to the WordPress user’s table.  When you get your system to authenticate a user and you find your FOS User Bundle session expired and forces the user to log back in, you can save them the trouble by “synchronizing” the WordPress user session by logging them in automatically in the FOS User Bundle like so:

$user=$userManager->findUserByEmail($userEmail);

if($user){
   $token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
   $this->get('security.context')->setToken($token);
   $this->get('session')->set('_security_main',serialize($token));
}

Be sure to add this “use statement” up top in your controller/repo:

use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;