Skip to content

Instantly share code, notes, and snippets.

View inoryy's full-sized avatar
:octocat:

Roman Ring inoryy

:octocat:
View GitHub Profile

Keybase proof

I hereby claim:

  • I am inoryy on github.
  • I am inoryy (https://keybase.io/inoryy) on keybase.
  • I have a public key whose fingerprint is AE1C 94AE 75A4 4DF3 C4EA 99BE 981B B6DB 559A 2267

To claim this, I am signing this object:

--- core/modules/book/book.services.yml
+++ core/modules/book/book.services.yml
@@ -2,3 +2,7 @@
book.manager:
class: Drupal\book\BookManager
arguments: ['@database']
+ access_check.book.removable:
+ class: Drupal\book\Access\BookNodeIsRemovableAccessCheck
+ tags:
+ - { name: access_check }
@inoryy
inoryy / database_dump.sh
Created August 16, 2012 17:54
Simple database backup & email script
#!/bin/bash
mysqldump <db_name> | gzip > /path/to/backups/<db_name>_`date +'%H-%M_%d-%m-%Y'`.sql.gz
echo "<Project name> database backup" | mutt -s "[Backup] `date +'%H:%M %d-%m-%Y'`" <email@email.com> -a /path/to/backups/$(ls /path/to/backups/ -tr | tail -n 1)
@inoryy
inoryy / gist:2151792
Created March 21, 2012 19:34
sortable ex
/**
*
* @Gedmo\SortableGroup
* @ORM\Column(name="fieldName", type="integer")
*/
protected $field;
/**
* @var integer
* @Gedmo\SortablePosition

Redirecting to last visited page after registration.

Imagine this scenario: A user on your webpage finds an awesome link, but it's only open to registered users.

Normally our user will be redirected to login page and if they already have an account, they can login and get redirected to the page they were looking for. This is possible thanks to Symfony2 Authentication listener where a session parameter is set to what the last page was before firewall was hit and then purged the moment you login.

But what if they're a new user? After clicking another link to register and filling out the form, how can you redirect them back to the page they're actually looking for?

Redirecting to last visited page after registration.

Imagine this scenario: A new user on your awesome webpage finds an awesome link, but it's only open to registered users, so he's automatically redirected to login form, then he goes to a register page (or fills embedded form right there) and then gets redirected back to a homepage. Somewhat frustrating experience, don't you think?

Well, let's solve this little problem with some help from [symfony2 authentication listener] (https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php). More specifically, by exploiting [already existing feature] (https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php#L270) for login form. This feature is actually a simple session parameter that is set the moment