Latest posts

Browse topics

Simple FB connect Drupal 8 Mapping custom fields from Facebook

Simple FB Connect Drupal module  allows users to register and login to your Drupal site with their Facebook account.

Indeed, as the modules name suggests, its one of the easiest ways how to connect Facebook to Drupal. And as I had already worked with this module a few years ago (see: Drupal Simple FB connect + User Form Theming ) now, when working on idea about possible Drupal Dating portal,  I decided to implement Simple FB Connect. In this article I'll write down my notes on how to map custom Facebook fields to Drupal 8 using this module.

I should note that I was working on Drupal 8.4.2 minimal profile installed. 

Before proceeding to the technical part, make sure you have created:

For the sake of ease for this tutorial I will cover details on how to map fields from Facebook's person's public profile only (for enabling additional fields you will need to make Facebook review for your app)

The following properties on the user object are enabled by default: (See: Permissions Reference - Facebook Login)

  • id
  • cover
  • name
  • first_name
  • last_name
  • age_range
  • link
  • gender
  • locale
  • picture
  • timezone
  • updated_time
  • verified

Now, once we are all set up, let's do two things:

  • Create fields for Drupal user profiles
  • Creating a custom module for mapping Facebook fields to Drupal fields using Simple FB connect.

Adding custom fields for Drupal user profiles

For this example I created following fields:

  • First name field_first_name Text (plain)
  • Last name field_last_name Text (plain)
  • Gender field_gender Text (plain)
  • Age Range field_age_range Text (plain)
  • Locale field_locale Text (plain)

Your setup might differ, but hopefully you got the picture.

Custom module for mapping FB fields

A great reading and tutorial is already provided on modules page, see: EventSubscriber example. Here I will just reproduce what's already written and some minor changes for mapping fields from Facebook.

mymodule/mymodule.info.yml

name: My Module
description: 'Example module demonstrating interaction with Simple FB Connect.'
package: Custom
type: module
core: 8.x
dependencies:
  - simple_fb_connect

mymodule/mymodule.services.yml

services:
  mymodule.subscriber:
    class: Drupal\mymodule\EventSubscriber\MyModuleSubscriber
    arguments:
      - @simple_fb_connect.fb_factory
    tags:
      - {name: event_subscriber}

Pay attention when copy-pasting the content of the services file. The intendation must be exactly like it is here (indent does NOT use tabulators but two space bars). If you get a white screen of death (PHP fatal error), please fix the indents, clear Drupal caches and try again.

mymodule/src/EventSubscriber/MyModuleSubscriber.php

A slightingly modified file already, please see EventSubscriber example for original. Inspired by themes mania

facebook = $fb_factory->getFbService();
    $this->persistentDataHandler = $fb_factory->getPersistentDataHandler();
  }

  /**
   * Returns an array of event names this subscriber wants to listen to.
   *
   * @return array
   *   The event names to listen to
   */
  static function getSubscribedEvents() {
    $events = array();
    $events['simple_fb_connect.scope'][] = array('modifyPermissionScope');
    $events['simple_fb_connect.user_created'][] = array('userCreated');
    $events['simple_fb_connect.user_login'][] = array('userLogin');
    return $events;
  }

  /**
   * Adds Facebook permissions to the scope array.
   *
   * Facebook permissions can be found at
   * https://developers.facebook.com/docs/facebook-login/permissions
   *
   * Note that most permissions require that Facebook will review your app
   * so only add those permissions that you really need. In this example we
   * add 'public_profile' which you don't have to do since this permission
   * is always granted.
   */
  public function modifyPermissionScope(GenericEvent $event) {
    $scope = $event->getArgument('scope');
    // Add the permission here. In this example we add 'public_profile'.
    $scope[] = 'public_profile';
    $event->setArgument('scope', $scope);
  }

  /**
   * Reacts to the event when new user is created via Simple FB Connect.
   *
   */
  public function userCreated(GenericEvent $event) {
    $user = $event->getArgument('account');

    // Enter your own code here. Remember to save the user with $user->save()
    // if you modify the user object.
    drupal_set_message("Debug: user created. This message is from mymodule!");
  }
  /**
   * Reacts to the event when user logs in via Simple FB Connect.
   *
   * This example adds role 'facebook' to the user if the user
   * didn't have that role already. You have to create the role manually.
   *
   * This function also demonstrates how you can get the access token for the
   * current user and how to make your own API calls using Facebook service.
   */
  public function userLogin(GenericEvent $event) {
    $user = $event->getArgument('account');

    // Enter your code here. Remember to save the user with $user->save()
    // if you modify the user object.
    drupal_set_message("Debug: user logged in. This message is from mymodule!");

    // Let's add a role 'facebook' for the user if she didn't have it already.
    // The role itself must obviously be first created manually.
	
    $user->addRole('facebook');
    $user->save();


    // Let's see how we can get make our own API calls to Facebook. We need
    // user's Facebook access token, which SimpleFbConnect has stored to session
    // for other modules.
    $access_token = $this->persistentDataHandler->get('access_token');
    if ($access_token) {
      try {
       $graph_node = $this->facebook->get('/me?fields=name,first_name,last_name,gender,age_range,locale', $access_token)->getGraphNode();
        $name = $graph_node->getField('name');
        $first_name = $graph_node->getField('first_name');
        $last_name = $graph_node->getField('last_name');
        $gender = $graph_node->getField('gender');
        $age_range = $graph_node->getField('age_range');
        $locale = $graph_node->getField('locale');
        drupal_set_message("We were able to retreive following data from Facebook: " . $name . $first_name . $last_name . $gender . $age_range . $locale );
		$user->set("field_first_name", $first_name);
		$user->set("field_last_name", $last_name);
		$user->set("field_gender", $gender);
		$user->set("field_age_range", $age_range);
		$user->set("field_locale", $locale);
	    $user->save();
      }

      catch (FacebookRequestException $ex) {
        // Add exception handling here for FacebookRequestExceptions.
      }
      catch (FacebookSDKException $ex) {
        // Add exception handling here for all other exceptions.
      }
    }
    else {
      drupal_set_message("No FB access token found for current user!");
    }
  }

}

Now once configured and enabled, after login with Facebook connect, here is the result and data I was able to store in Drupal:

Mapping Facebook user fields to Drupal user fields

Mapping Facebook user fields to Drupal user fields

Hope it helps, and as usual if you have any questions or comments - please share bellow in the comments section.

How To Hide Tabs On Drupal 8 Content and User Pages

In Drupal 8 there is a quite easy way to to hide tabs view both on content and user pages. The best there are no hook, modules or complicated theme rewrites involved.

In today's short Drupal tutorial series I will provide a simple workaround out of the box on how to hide tabs both on content and user pages in Drupal 8.

Also see: Theming Drupal 8: How to Hide Site Name

What at start seems like a simple issue, might turn out to be a imminent problem. The truth is - it's super simple, but still a little bit complicated if you come with a Drupal 7 background. 

For hiding tabs in Drupal 8, we will need to go to the block layout page:

Search for a block Tabs , click on Configure button and from the bottom click on Remove block.

That simple. Hope it helps!

Hurma Cafe Shop in Tbilisi

Hurma cafe shop is a recently opened hipster style coffee house serving not only great coffee lattes, but also smoothies, delicious brunch and all day breakfast for a very affordable prices.

Located close to the Tbilisi Philharmony on Petre Melikishvili street 21 on the opposite side to the Tbilisi Hard Rock Cafe. This place is run by Russian/Ukrainian girls (at least that's what I understood). Despite being opened just recently, I noticed mostly foreign visitors here. Yeah, who I'm to complain, right?

That said, welcome to another great Tbilisi restaurant - Hurma cafe shop!

Menu at Hurma Cafe shop in Tbilisi

Menu at Hurma Cafe shop in Tbilisi

One of the rare places in Tbilisi offering Breakfast all day. Although I should mention that in recent years there have been a lot of improvement with brunch offer in Tbilisi. Prices for a brunch menu here are really low compared to other brunch places in Tbilisi. The prices will probably grow in the future, but for right now - enjoy!

Hipster style interior at Hurma Cafe shop

Hipster style interior at Hurma Cafe shop

Looking for a rustic, industrial, kitschy place in Tbilisi? Come to Hurma Cafe shop. Ukrainian/Russian entrepreneurs have thought about all possible details. Indeed, it's a kitschy place!

Goodies at Hurma Cafe Shop

Goodies at Hurma Cafe Shop

October 2017 Dividend Income Report - $72.97

Welcome to the sixth (#6) dividend income report, covering earnings I've made from dividend-paying stocks, peer to peer lending (both fiat and cryptocurrencies) in October 2017. 

October was a very sad month - my dear granny passed away at the age of 87. Grandmother was like a mother to me taking care and giving advice in my childhood, teenage years and adult life.  My granny gave me first lessons in the finance world when I was like age  6 or something, she taught me about compound interests, deposits, bonds, and stocks. She was one of the smartest persons I ever know. I miss you a lot, our distant phone conversations in 3:00 in the morning...I miss you, and I know one day we will meet and play checkers again. Rest in Peace!

October, in terms of a passive income, turned out better, as I thought before, and generated me a dividend income of total $72.97. In fact, October now is the second best after the month of July.

Unexpected dividend payment from Estonian Nordecon (which I thought as one of the worst investments in 2017, just a couple of months before) helped to boost total dividend income.

As usual, I was doing nothing much, just investing in great companies, playing a little bit with cryptocurrencies and lending out money via peer to peer marketplace. Most of the October was on autopilot, just at the start of the month I deposited some chunk of money to Mintos.com peer to peer lending marketplace, and at the end of the month - purchased additional shares of Linas Agro Group on Nasdaq Baltics.

From the crypto-investments, there was a Bitcoin fork for which I kind of prepared, but due to the circumstances missed to cash in free Bitcoin Gold coins. See: Another Bitcoin Hard Fork Planned (Bitcoin Gold) - My Approach to Survive It, also it should be noted (though it's not covered in the dividend income report series) - Altcoin Market was literally bleeding, see: Bitcoin Price Increases Altcoin Market Bleeding. 

Despite another turbulent month in crypto investments, all the hype with Bitcoin forks helped to boost my investments by 28.53%. 

Affiliate link here: If you are just planning to acquire your first bitcoin, consider to register at coinbase.com with this link, once you buy or sell $100 (€85) of digital currency or more, we will both get $10 (€8) of free bitcoin.

About Portfolio October 2017

At the end of October, I've invested a total of $10,830.08 what already greatly exceeds my initial plan for investments in 2017 and equals to 126.50% from this year's planned investments. Also, I've reached 1.12% from my ultimate one million dollar goal by the time I will turn 60 (in 2045). October was the first month when the total net worth reached $10,000. Isn't it just amazing, in just 10 months I've built a pretty decent portfolio worth now more than ten thousand. Sure, 10K is nothing much for a wealthy retirement plan, but it is a good starting point. And you know what? It just generated me a passive income of $72.97.

For the sake of this and all future dividend income articles, I've converted all final/total currencies to the US dollar, though I've investments in GEL, EUR and USD currencies.

Net Worth October 2017

Net Worth October 2017

For the past 10 months, it has been a steady value growth resulting in a total of +3.42% value growth for the entire portfolio at the end of October. Here is the breakdown by positions:

  • Mintos.com peer to peer lending: -2.38%
  • Stocks: +4.07%
  • Mutual funds: +6.22%
  • Crypto investments: +28.53%

Despite mintos.com being the top performer in terms of dividend growth (loan repayments) in October, the total value of it has decreased for the third month in a row, and here is why - Georgian Lari currency lost its value against EUR. This is the thing that worries me a lot, as Lari has been a troubled currency for the last 3 years already (at least). For the first time, GEL/EUR rate climbed above 3. (as of writing this 1 EUR = 3.04). As I have investments more than 5,000 in GEL such rates push down the total value. I feel very troubled regarding next Winter months.

Both individuals and entities can invest through Mintos. Individual investors must be at least 18 years old, have a bank account in the European Union or third countries currently considered to have AML/CFT systems equivalent to the EU, and have their identity successfully verified by Mintos. At the moment, US citizens or taxpayers cannot register as investors at Mintos.

Affiliate link here: Sign up to Mintos.com here. By using this affiliate link for registration both you and I will receive — 1% of our average daily balance which should be paid in 3 installments for the first 90 days.

Having a diversified portfolio helps, and it definitely helped me last October. Despite negative returns in some of the portfolio positions, the total value growth is with a positive +3.42% sign. Awesome.

Investment portfolio October 2017

Investment portfolio October 2017

I keep investing in - stocks, peer-to-peer lending, mutual funds, cash, and cryptocurrencies. The vast majority remains invested in Nasdaq Baltics and Mintos.com peer to peer lending loans (in EUR and GEL currencies)

About Investments in October 2017

Last month I invested additional:

  • Nasdaq Baltics stock market: EUR 375
  • Cash: EUR 402.45
  • Cryptocurrencies: EUR 175 
  • Mintos.com: EUR 236.33

Total investments in October: EUR 1188.78

From money invested in Baltic equity market I bought following shares:

  • Linas Agro Group  (LNA1L ) - 550 Shares

This, Lithuanian company promises dividend payment in November. Actually, I planned to participate in Madara Cosmetics IPO this month, but after a fundamental and technical analysis, I decided to not, instead choosing Linas Agro Group. See: Why I'm not investing in Madara Cosmetics (MDRAUC)

Interest income in October 2017

From investments in stocks, peer to peer lending marketplace Mintos.com and from cryptocurrency lending on Poloniex.com I got following income last month:

  • Energijos skirstymo operatorius: EUR 13.68
  • Nordecon: EUR 11.70
  • Mintos.com: EUR 35.94
  • Poloniex.com: EUR 1.98

Total: EUR 63.30 / USD 72.97

Monthly income to the date

During the past 10 months, dividend income from my portfolio have produced a whopping $439.61, or 4.05% year to the date yield

Monthly income chart by October 2017

Monthly income chart by October 2017

Right now it looks I won't crack $100 anytime soon and if, then most probably in December, as I already hold few stocks with historical dividend payments in December.

Goals for October 2018 Dividend income

A year from now I'm looking for a humble  $120 dividend income in October 2018

Audio & Video Transcription Service by Caucasus Translations

Caucasus Translations is a professional translation and localization agency located in Tbilisi, capital of Georgia. The leader in the translation and content localization business in Caucasus and Central Asia. Agency employs more than 300 translators across the globe to provide cost-effective, accurate and native translation solutions for companies in almost all industry verticals in about 40 countries.

Today I'm glad to announce that here at Caucasus Translations Tbilisi department, there have been established audio & video transcription department.

As for the last couple of weeks, I've been involved in building office's infrastructure, configuring servers and setting up transcription software,  I decided to share few photos from this new department:

Caucasus Translations ready to assist with audio&video transcription service

Caucasus Translations ready to assist with audio&video transcription service

The team of highly experienced transcription professionals works with the latest and top-notch software here. Confidentiality and data security are among top priorities here.

Lobby hall at Caucasus Translations

Lobby hall at Caucasus Translations

24/7 guarded building, with restricted access to the office

Panoramic view

Panoramic view

As always, I couldn't resist and made a panoramic photo here. See: How To Stitch Panoramic Photos with Adobe Photoshop (Photomerge)

Caucasus Translations provides high quality and affordable translation and localization services between English and other major languages to clients worldwide. Our capabilities in Caucasus region languages, especially Georgian, Armenian and Azerbaijan are well-known in the language services industry. Learn more at https://www.caucasustranslations.com