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

PHP

By editor , 8 July, 2023

Install PHP 8.1

Tags

  • Drupal 10
  • Linux
  • Server
  • PHP

Example for Debian:

Enable sury/php repository

apt-get install php8.1-{cgi,cli,fpm,pdo,gd,mbstring,mysqlnd,opcache,curl,xml,zip}

 

Install additional PHP packages

apt-get install php8.1-{cgi,cli,fpm,pdo,gd,mbstring,mysqlnd,opcache,curl,xml,zip}

By editor , 30 September, 2021

Translation API - PHP Twig JavaScript

Tags

  • Drupal 8
  • Drupal 9
  • Translation
  • JavaScript
  • Twig
  • PHP

PHP Class using StringTranslationTrait

StringTranslationTrait allow to get t() and formatPlural() methods
Example:
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
class MyClass {

By editor , 11 October, 2019

Run PHP script using drupal bootstarp on drupal site

Tags

  • Drupal 8
  • Code
  • PHP

This is usefull if you want to do some actions just one time.

The drush comman is php-script alias src

On drupal 8 with drush

Example :
drush --uri=drupal.loc scr /modules/custom/mymodule/scripts/test-script.php

By nuwantha , 20 September, 2019

PHP RegEx Replace accents of each selected word

Tags

  • PHP
  • Code

Example :

$stopwords = ['toto', 'Pied', 'the'];
$str = 'bla bla toto bla bla Toto bla bla Tôtô bla bla totô bla bla bla bla the thé pied pïed pîéd';

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 October, 2017

PHP Tips for easy development

Tags

  • PHP
  • Code

Generate a random key.

$random_key = str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'); // 62 characters
$random_key = substr($random_key, 0, 10); // 10 characters

 

By editor , 10 June, 2017

PHP : Get Class Name

Tags

  • Module
  • Code
  • PHP

The structure of the examples are like:
namespace Drupal\mymodule\Tools;
class MyTools extends MyToolsBase {
...
}
...
class MyToolsBase {
  public function showClass() {
    $class_name = ....

By editor , 28 March, 2017

Php OOP - Examples and Tips

Tags

  • PHP

Different between self:: and static (Late Static Bindings)

Static references to the current class like self:: or __CLASS__ are resolved using the class in which the function belongs, as in where it was defined.

By editor , 16 March, 2017

Avoid Spam form submissions - (Easy way of form Anti-Spam)

Tags

  • Drupal 8
  • Code
  • PHP
  • Form
By editor , 13 February, 2017

Avoid email send by Php/Drupal mark as spam

Tags

  • PHP
  • Server
  • Linux

An email is classified as spam or not spam on the receiving end, not the sending end. But you can improve

Pagination

  • 1
  • Next page
PHP

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