Skip to main content
Drupal 8

Main navigation

  • Home
    • Question And Answer
    • NEWS
    • Projects
  • Tutorials - Drupal
    • Android
    • Other
User account menu
  • Log in

Breadcrumb

  1. Home

Code

By editor , 28 March, 2018

Increment or Decrement number of Fields Dynamically using Form API and Ajax

Tags

  • Drupal 8
  • Code
  • Form
  • JavaScript

In this example, we will use a field to get tags list, the number of tags dynamic.

By editor , 26 March, 2018

Taxonomy form autocomplete, Create taxonomy term field with FAPI

Tags

  • Drupal 8
  • Code
  • Taxonomy
  • Form

Simple taxonomy autocomplete field.

Example:
$form['tagtest'] = [
  '#type' => 'entity_autocomplete',
  '#target_type' => 'taxonomy_term',
  '#title' => 'Taxonomy Term',
];

By editor , 21 March, 2018

Completely reset GIT repository

Tags

  • Git
  • Code

Completely reset

Delete the .git directory locally.

Recreate the git repository:

$ cd (project-directory)
$ git init
$ (add some files)
$ git add .
$ git commit -m 'Initial commit'

By editor , 2 March, 2018

Create a Pagination with PHP

Tags

  • PHP
  • Code

Example of a pager (pagination) on php:

function showpager($currentIndex = 0, $buttons = 5, $totalPages = 50) {
  $currentPage = $lowerLimit = $upperLimit = min($currentIndex, $totalPages);
  //Search boundaries

By editor , 13 February, 2018

JavaScript Events on Drupal 8.

Tags

  • Drupal 8
  • Code
  • JavaScript
  • Module

Note : On drupal the best practice is use drupal behaviors but not JS or Jquery codes such as:
<button onclick='myFunction()'>Click</button>

By editor , 9 February, 2018

Save a temporary data - Key Value Expirable.

Tags

  • Drupal 8
  • Code

 

keyvalue.expirable service allow to save Key / Value variable in the database.

Example:

// Save without date limit.
\Drupal::service('keyvalue.expirable')->get('my_module')->set('my_var', 123);

By editor , 23 January, 2018

JavaScript useful tips and examples

Tags

  • JavaScript
  • Code

Get HTTP Header information From JavaScript

Note : It's not possible to read the current headers. You could make another request to the same URL and read its headers, but there is no guarantee that the headers are exactly equal to the current.

By editor , 22 January, 2018

FormattableMarkup : Add parameters, links to a text, table cell data.

Tags

  • Drupal 8
  • Code
  • Theming

Create a customizable text.

Example :
use Drupal\Component\Render\FormattableMarkup;
$text = new FormattableMarkup('My name is @name', ['@name' => "The name"]);

By editor , 19 January, 2018

Event dispatcher. Create event, Dispatch and Subscribe.

Tags

  • Drupal 8
  • Code
  • Module
  • Services
  • Hook

Drupal's event system allow to create triggers when an event has been happened like create a custom hook on drupal 7.

By editor , 19 January, 2018

Event Subscriber to replace hook_boot and hook_init

Tags

  • Drupal 8
  • Code
  • Services
  • Hook

Use Event Subscriber service.

The EventSubscriber allow to execute an action on boot as hook_boot or hook_init of drupal 7.

Example.

Pagination

  • Previous page
  • 3
  • Next page
Code

Links

  • Drupal.org
  • Drupal core release cycle
  • Drupal events with ease
  • Unit test with Drupal using PHPUnit (Drupal 10)
  • Tokens for file upload url
  • Tips for Docker
  • CKEditor inline image files usage for custom forms.
  • Install Docker on Linux Mint
  • Install PHP 8.1
  • Drupal Security Best Practices
  • Order and sort items with tabledrag
  • Add a custom service YAML container
  • Apply a patch with composer