Search This Blog

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"}

Thursday, 15 March 2018

Dependency Injection Understanding

Lets read the following post for understanding Dependency Injection in real life:
http://www.theserverside.com/news/1321158/A-beginners-guide-to-Dependency-Injection

Dependency Injection in PHP:
http://krasimirtsonev.com/blog/article/Dependency-Injection-in-PHP-example-how-to-DI-create-your-own-dependency-injection-container

Wednesday, 7 March 2018

Useful Modules and theme From Drupal Case studies





  1. Share buttons for Drupal including the AddToAny universal share button, Facebook, Twitter, Google+, Pinterest, WhatsApp and many more. :   https://www.drupal.org/project/addtoany

  2. Provides the ability to use external files with file fields without saving the files to your local files directory. Also provides a 'Remote URL' browser plugin for Mediahttps://www.drupal.org/project/remote_stream_wrapper
  3. Accelerated Mobile Pages (AMP)

  4. Aegan Theme based on Bootstrap https://www.drupal.org/project/aegan 
  5. Twitter Block Twitter Block is a lightweight module which allows administrators to create 
  6. HSTS: HSTS (HTTP Strict Transport Security) is a standard used by HTTP client applications to enforce the use of SSL communication between a site and the client. 
  7.      security modules
    https://www.valuebound.com/resources/blog/implement-these-modules-make-your-drupal-site-more-secure .


Drupal7 to Drupal 8 changes


Drupal 7: example.info
name = Example
description = An example module.
core = 7.x
files[] = example.test
dependencies[] = user


 Drupal 8: example.info.yml
name: Example
description: An example module.
core: 8.x
dependencies: - user
# Note: New property required as of Drupal 8!
type: module

Creating MENU


Drupal 7: hook_menu()

example.module
<?php
/**
 * Implements hook_menu().
 */
function example_menu() {
 $items['hello'] = array(
 'title' => 'Hello world',
 'page callback' => '_example_page',
 'access callback' => 'user_access',
 'access arguments' => 'access content',
 'type' => MENU_CALLBACK,
 );
 return $items;
}
/**
 * Page callback: greets the user.
 */
function _example_page() {
 return array('#markup’ => t('Hello world.'));
}

?>


Drupal 8: Routes + Controllers

example.routing.yml

/* note: modulename.filepurpose , modulename is required next purpose can be anything which is understandable  */
example.controller:                   
 path: '/hello'                                          /* the path which will be used to display output  */
 defaults:
 _content: '\Drupal\example\Controller\Hello::content'     /* controller with class hello and method content  */
 requirements:
 _permission: 'access content'


Note: In route file 


src/Controller/Hello.php              /* the file name has to be same as class name used */

<?php
namespace Drupal\example\Controller;                 /* same as defined in yml _content */
use Drupal\Core\Controller\ControllerBase;         /* required to use controller */
/
**
 * Greets the user.
 */

class Hello extends ControllerBase {

 public function content() {                                        /* function name defined in yml */
 return array('#markup' => $this->t('Hello world.'));
 }
}
?>


Creating MENU with argument in url


route yml

modulename.controller_argument:
  path: '/example/{nodeID}'
  defaults:
    _controller: 'Drupal\modulename\Controller\Hello::getargument'
  requirements:
    _permission: 'access content'




<?php
namespace Drupal\example\Controller;                 /* same as defined in yml _content */
use Drupal\Core\Controller\ControllerBase;         /* required to use controller */
/
**
 * Greets the user.
 */

class Hello extends ControllerBase {

  public function getargument($nodeID) {
   return array(
      '#markup' => $nodeID,
    );

  }
}
?>


Monday, 5 March 2018

New Features in Drupal 8

#1. New Fields

There are five completely new field types in the Drupal 8 core:
  • Date
  • Email
  • Link
  • Reference
  • Telephone
There have also been some smaller changes too:
  • The English used for field names is more straightforward. For example, "Integer" is now simply "Number".
  • Comments is now available as a field, rather than a setting.

#2. Fields are everywhere

Not only are there new fields, but you can now add fields in many more places.
You can add fields to nodes, blocks, comments, contact forms, taxonomy terms and users.

#3. CKEditor

Previous versions of Drupal did not provide a text editor.
Drupal 8 ships with CKEditor, one of the very best text editors on the market.

#4. Quick Edit

Thanks to the "Quick Edit" module, if you're logged into Drupal and looking at content, you'll be able to edit text directly from the front-end of your site.

#5. Responsive Images

Drupal 8 allows you to choose different styles for individual images. The various styles will be used for different device sizes.

#6. Views


 Views is now in the Drupal 8 core. Not only is it available by default, but most of the Drupal administration screens now use Views, which makes them easy to customize.


#7. Multilingual

The process is much smoother in Drupal 8, with 4 key modules in the core.
Once those modules are enabled, you can almost immediately start translating your site.

#8. Configuration Manager

The new Configuration Manager module in Drupal 8 makes it much easier to export and import the features that you build.
For example, if you create a new content type, you can export it from your test site and easily import it into a live site.


#9. Webservices


Enable the four Web Services modules, go to Views, and you'll immediately be able to create a REST export.

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