Search This Blog

Friday, 18 May 2018

Set Module priority

Setting module weights:
Drupal 7:
<?php
  // Set a module's weight.
  db_update('system')
    ->fields(array('weight' => $weight))
    ->condition('name', $mymodule)
    ->execute();
?>


Drupal 8:
<?php
  module_set_weight($mymodule, $weight);
?>
To set a module's weight relative to another, a module_get_weight function is planned.

Friday, 11 May 2018

Drupal 8 basic Custom work



  • To get the current path or arg(1) etc.
     $request = \Drupal::request();
$current_path = $request->getPathInfo(); $path_args = explode('/', $current_path); $zero_argument = $path_args[0]; $first_argument = $path_args[1]; $second_argument = $path_args[2]; $third_argument = $path_args[3];

  • TO Get Node pathalias.
use Drupal\node\Entity\Node;
function bootstrap_preprocess_node(&$variables) { $node = $variables['elements']['#node'];
$node_detail = $node->toArray(); $node_detail['path'][0]['alias'];
}




Monday, 7 May 2018

Simple Login with Session

File index.php :

<?php
include "config.php";
?>

<form action="submit.php" method="post">
<label>Username</label>
<input type="text" name="username">
<label>Password</label>
<input type="password" name="password">
<input type="submit" name="submit" value="Submit">
</form>

File config.php:

<?php
session_start();
$host = "localhost";
$username = "root";
$password = "";
$database = "loading";

$con = new mysqli($host, $username, $password, $database);
if($con->connect_error){
die("Connection failed:" . $con->connect_error);
}
?>

File submit.php:

<?php
include "config.php";
$username = $_POST['username'];
$password = $_POST['password'];
if(isset($_POST['submit'])){
$sql = "SELECT * FROM userlogin WHERE username = '".$username."' AND password = '".$password."'";
$result = $con->query($sql);
if($result->num_rows == 1){
   $_SESSION['username'] = $username;
   $_SESSION['password'] = $password;
    header("location: loginform.php");
}else{
echo "credentials not matched";
}
}
?>

File loginform.php:

<?php
include 'config.php';
$u = $_SESSION['username'];
echo "Welcome " . $u;
if(isset($_POST['logout_submit'])){
session_destroy();
header('location: index.php');
}
?>
<form action="" method="post">
<input type="submit" name="logout_submit" value="Logout">
</form>

File authentic.php:

<?php
include 'config.php';
$username = $_SESSION['username'];
$password = $_SESSION['password'];
echo "Cridential are - <br/>Username: " . $username . " <br/> Password: " . $password;
if($_SESSION['username'] == '' AND $_SESSION['password'] == ''){
header('location: index.php');
}
if(isset($_POST['logout_submit'])){
session_destroy();
header('location: index.php');
}
?>
<form action="" method="post">
<input type="submit" name="logout_submit" value="Logout">
</form>

First HTML blog

Hello there


echo 'dddd';
?>

Js to show Hide Content

Js: var showChar = 250;  // How many characters are shown by default     var ellipsestext = "...";     var moretext = "Sh...