Search This Blog

Monday, 13 August 2018

Js to show Hide Content

Js:
var showChar = 250;  // How many characters are shown by default
    var ellipsestext = "...";
    var moretext = "Show more >";
    var lesstext = "Show less";
 

    $('.rd-more').each(function() {
        var content = $(this).html();

        if(content.length > showChar) {

            var c = content.substr(0, showChar);
            var h = content;
             var html = '<div style="display:block">' + c + '<span class="moreellipses">' + ellipsestext+ '</span></div><div class="more content" style="display:none">' + h + '</div><a href="" class="morelink">' + moretext + '</a></span>';

            $(this).html(html);
        }

    });

    $(".morelink").click(function(){
        if($(this).hasClass("less")) {
            $(this).removeClass("less");
            $(this).html(moretext);
        } else {
            $(this).addClass("less");
            $(this).html(lesstext);
        }
        $(this).prev('.content').prev().toggle();
        $(this).prev().toggle();
        return false;
    });

CSS:

.morecontent span {
    display: none;
}
.morelink {
    display: block;
}

html:

<div class= "rd-more">Content >/div>



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>

Wednesday, 25 April 2018

How to get language code of Current page and it's translated content

$lang_code = \Drupal::service('language_manager')->getCurrentLanguage()->getId();
$node = \Drupal::routeMatch()->getParameter('node');

// Paragraphs/referencedEntities
$paras = $node->get('entity_fiedld_name')->referencedEntities();
foreach ($paras as $para) {
  // Remember to check if translation exists
  if ($para->hasTranslation($lang_code)) {
    $para = $para->getTranslation($lang_code);
  }
   $goodValue = $para->get('field_of_the_entity')->getValue();
}


File for functions of entity:
core/lib/Drupal/Core/Entity ContentEntityBase.php

Tuesday, 20 March 2018

Creating Custom Block in DRUPAL 8

Code:
FILE NAME: LanguageSwitcher.php same as Class name
Path : custom_module/src/Plugin/Block


<?php
namespace Drupal\custom_modulename\Plugin\Block;

use Drupal\Core\Block\BlockBase;
/**
* Provides custom block
*
* @Block(
* id = "language_switcher",
* admin_label = @Translation("LanguageSwitcher"),
* category = @Translation("Custom Plugin"),
* )
*/

class LanguageSwitcher extends BlockBase {


public function build() {

$custom_switcher = "<ul><li>Hello</li></ul>";

return array(
      '#markup' => $this->t($custom_switcher),
    );
}
}

Friday, 16 March 2018

To creating web-services in PHP

Create a PHP file like services.php Inside it just write few codes as follow:

<?php
$arr = array('name'=>'Test Name', 'company'=>'Test Company', 'designation'=>'Test Dev', 'profile'=>'PHP');
json_encode($arr);
print json_encode($arr);
?>

See the result in browser, you will find result as follow:
{"name":"Arti","company":"Sparx","designation":"Drupal Dev","profile":"PHP"}

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...