Saturday 21 May 2016

How to check if current page is frontpage in drupal 8 - drupal_is_front_page drupal 8

How to check if current page is frontpage in drupal 8 

During the Drupal 8 development cycle a path.matcher was introduced which deprecated most procedural functions in path.inc
Drupal 7:
$path_matches = drupal_match_path($path, $patterns);
$is_front = drupal_is_front_page();
Drupal 8:
$path_matches = \Drupal::service('path.matcher')->matchPath($path, $patterns) ;
$is_front = \Drupal::service('path.matcher')->isFrontPage();
 
 
reff links: 
 
https://www.drupal.org/node/2274675 
 
Deprecated by path.matcher service.
https://www.drupal.org/node/2274675

How to check if current path is admin path in drupal 8 ?- path_is_admin druapl 8

if (path_is_admin(current_path())) {
  // Do stuff.
}

To check the path of the current page:
$is_admin = \Drupal::service('router.admin_context')->isAdminRoute();
to check an arbitrary path, you need to create a Request object and obtain its matching Route:
use Symfony\Component\HttpFoundation\Request;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;

$path = '/node/1';
$request = Request::create($path);

$route_match = \Drupal::service('router.no_access_checks')->matchRequest($request);
$route = $route_match[RouteObjectInterface::ROUTE_OBJECT];
$is_admin = \Drupal::service('router.admin_context')->isAdminRoute($route); 
 

Drupal 7:
$is_admin = path_is_admin($path);
  Drupal 8:
$is_admin = \Drupal::service('router.admin_context')->isAdminRoute(\Symfony\Component\Routing\Route $route); // In order to get the $route you probably should use the $route_match $route = \Drupal::routeMatch()->getRouteObject(); $is_admin = \Drupal::service('router.admin_context')->isAdminRoute($route); * Omit the $path (Drupal 7) or $route (Drupal 8) parameter to check if the current page is an admin page.
 
 
Source : https://api.drupal.org/api/drupal/includes!path.inc/function/path_is_admin/7.x  

Monday 1 February 2016

git patch create new files

Steps to add new files to patch : 

User@AMX-554 /C/xampp/htdocs
$ git clone --branch 8.x-1.x https://git.drupal.org/project/autologout.git
Cloning into 'autologout'...
remote: Counting objects: 1648, done.
remote: Compressing objects: 100% (1179/1179), done.
remote: Total 1648 (delta 982), reused 706 (delta 408) eceiving objects:  96% (1583/1648), 340.00 KiB | 19.00 KiB/s
Receiving objects: 100% (1648/1648), 362.41 KiB | 18.00 KiB/s, done.
Resolving deltas: 100% (982/982), done.
Checking connectivity... done.

User@AMX-554 /C/xampp/htdocs
$ cd autologout/



User@AMX-554 /C/xampp/htdocs/autologout (8.x-1.x)
$ git status
On branch 8.x-1.x
Your branch is up-to-date with 'origin/8.x-1.x'.

nothing to commit, working directory clean

User@AMX-554 /C/xampp/htdocs/autologout (8.x-1.x)

$ git add -N README.txt INSTALL.txt

User@AMX-554 /C/xampp/htdocs/autologout (8.x-1.x)

$ git add -p
warning: LF will be replaced by CRLF in INSTALL.txt.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in README.txt.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in INSTALL.txt.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in INSTALL.txt.
The file will have its original line endings in your working directory.
diff --git a/INSTALL.txt b/INSTALL.txt
index e69de29..7df4980 100644
--- a/INSTALL.txt
+++ b/INSTALL.txt
@@ -0,0 +1,16 @@
+INSTALL.txt file
+================
+$Id: INSTALL.txt,v 1.2 2009/04/17 14:05:51 jvandervort Exp $
+
+1. Place the autologout folder in your drupal/modules folder (or if multisite and this
+  module is meant to be available to just one site in drupal/sites/www.YOURSITE.com/modules)
+
+2. Enable the autologout module at administer > modules
+
+3. Ensure the correct admin users have permissions to administer the autologout module at
+  administer > people > permissions
+
+4. Set-up the module at administer > configure > people > autologout
+
+
+

Stage this hunk [y,n,q,a,d,/,e,?]? y
<stdin>:10: trailing whitespace.
1. Place the autologout folder in your drupal/modules folder (or if multisite and this
<stdin>:19: new blank line at EOF.
+
warning: 2 lines add whitespace errors.

warning: LF will be replaced by CRLF in README.txt.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in README.txt.
The file will have its original line endings in your working directory.
diff --git a/README.txt b/README.txt
index e69de29..2ed76d2 100644
--- a/README.txt
+++ b/README.txt
@@ -0,0 +1,20 @@
+/* $Id:
+
+Description
+===========
+After a given timeout has passed, users are given a configurable session expired prompt. They can reset the timeout, logout, or ignore it in which case they'll be logged out a
fter a the padding time has elapsed. This is all backed up by a server side logout if js is disable or bypassed.
+
+Features
+========
+* Configurable Global timeout and timeout padding. The latter determines how much time a user has to respond to the prompt and when the server side timeout will occur.
+* Configurable messaging.
+* Configurable redirect url, with the destination automatically appended.
+* Configure which roles will be automatically logged out.
+* Configure if a logout will occur on admin pages.
+* Integration with ui.dialog if available. This makes for attractive and more functional dialogs.
+* Configurable timeout based on role
+* Configurable timeout based on User
+* Configurable maximum timeout. Primarily used when a user has permission to change their timeout value, this will be a cap or maximum value they can use.
+* Order of presidence is, user timeout -> lowest role timeout -> global timeout
+* So if a user has a user timeout set, that is their timeout threshold, if none is set the lowest timeout value based on all the roles the user belongs to is used, if none is
set the global timeout is used
+* Roles with the proper permission setting can change their timeout value

Stage this hunk [y,n,q,a,d,/,e,?]? y

User@AMX-554 /C/xampp/htdocs/autologout (8.x-1.x)

$ git diff --cached --binary > add-readme-file-to-module-2658672-2.patch
warning: LF will be replaced by CRLF in INSTALL.txt.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in README.txt.
The file will have its original line endings in your working directory.

 
Reff links
 
http://stackoverflow.com/questions/14491727/git-add-patch-to-include-new-files