Drupal 8

Drupal 7 global variables vs. Drupal 8 services

Several Drupal 7 global values like global $language and global $user are also now accessed via services in Drupal 8 (and not global variables).

Drupal::languageManager()->getCurrentLanguage() and Drupal::currentUser()

Two ways to get the currentUser data:

1) Procedural code
$user = \Drupal::currentUser();
ksm($user->id());

(or)

2) OO code access the @current_user service, via dependency injection (DI)
$service = \Drupal::service('thirstysix.ex');
ksm($service->DisplayUserId());

Services and dependency injection in Drupal 8

Dependency Injection enables us to decouple reusable functionality by injecting it, rather than creating it inside of a class.

Drupal 8 introduces the concept of services to decouple reusable functionality and makes these services pluggable and replaceable by registering them with a service container.

Dependency injection is an alternative to the static \Drupal::service

There are, at least, two widely spread patterns in Drupal 8 in order to inject services into your objects. The first uses a service to inject services. The second uses a factory method that receives Drupal's container.

For Example:

modules/custom/thirstysix/thirstysix.info.yml

How do I add my own custom Javascript in Drupal 8?

 Save your custom script in themes/THEMENAME/js/script.js


 Declare your script in themes/THEMENAME/THEMENAME.libraries.yml:
 ts-corescripts:
   version: VERSION
   js:
     js/script.js: {}


 In THEMENAME.theme
 <?php
      /**
         * Add custom scripts
         */
        function THEMENAME_page_alter(&$page) {
          $page['#attached']['library'][] = 'thirstysix/ts-corescripts';
          //$page['#attached']['library'][] = 'core/jquery';
        }
    ?>


 

Translate a JS string from Drupal interface translations

Translate a JS string from Drupal interface translations

Drupal.t()

Drupal.t("My String");

Clear the Drupal Cache.

This string appear in /admin/config/regional/translate

if not then check your libraries.yml file 
And add the corresponding dependencies THEME.libraries.yml:
dependencies:
  - core/jquery
  - core/drupal

Enjoy :)

Drupal Bartik Admin - Drupal Super Admin theme as a Batrik theme

Drupal Bartik Admin-Super admin theme forever.

It's just an emerging product. As a bartik, we have to always configure the superadmin. The software settings may be overridden if you need to. It will only be open to the superadmin useruid 1.

The admin pages will be overridden by super admin theme as batrik. Drupal lets you identify a specific Admin Pages theme.

URL: https://www.drupal.org/project/bartik_admin

Admin pages are in English Drupal?

All Admin pages are in English and admin menu always in LTR?

1) First go to Administration -> Configuration -> Regional and language -> Languages -> Detection and selection tab and make sure to have “Account administration pages“ enabled.

2) Then go to People and edit your user. Admin -> Edit Profile -> Edit

Go down to the Language settings section. You should now see a Administration pages language dropdown. 

Select and save.

3) Go to the administration language using the following settings:

url: /admin/config/regional/language/detection

"Account administration pages" - Enabled

"Follow the user's language preference." - Enable

and drag and drop to the top position.

Drupal Multisite Setup on a XAMPP with Localhost

Install a XAMPP on your local machine.  Followed recommendations to not install in program files as there is some firewall problems. (e.g., c:\xampp)

Install a Drupal 8 instance that will act as the root site for our multisite instance. In our example, the root site will be called drupal8multisite, will be reachable at drupal8multisite.com, and will be installed at /xampp/htdocs/drupal8multisite