Drupal 8 and Drupal 9 set cookie and get cookie example with symphony HttpFoundation Component

Setting Cookies

The response cookies can be implemented through the headers public attribute:

use Symfony\Component\HttpFoundation\Cookie;

$response->headers->setCookie(Cookie::create('foo', 'bar'));

The setCookie() method takes an instance of Cookie as an argument.

You can clear a cookie via the clearCookie() method.

In addition to the Cookie::create() method, you can create a Cookie object from a raw header value using fromString() method. You can also use the with*() methods to change some Cookie property (or to build the entire Cookie using a fluent interface). Each with*() method returns a new object with the modified property:

$cookie = Cookie::create('foo')
    ->withValue('bar')
    ->withExpires(strtotime('Fri, 20-May-2011 15:25:52 GMT'))
    ->withDomain('.example.com')
    ->withSecure(true);
n addition to the Cookie::create() method, you can create a Cookie object from a raw header value using fromString() method. You can also use the with*() methods to change

Drupal 8 cookies can be set using ResponseHeaderBag from the Symfony\Component\HttpFoundation\Response object.
Set new cookie value 
 use Symfony\Component\HttpFoundation\Cookie; 
 $cookie = new use Cookie('cookie_name', TRUE); 
$response->headers->setCookie($cookie); 
return $response; 
Get cookies value 
 $request->cookies->get('cookie_name');

Pathauto Module functionalities and usage

The Pathauto module automatically generates URL/path aliases for various kinds of content (nodes, taxonomy terms, users) without requiring the user to manually specify the path alias. This allows you to have URL aliases like /category/my-node-title instead of /node/123. The aliases are based upon a "pattern" system that uses tokens which the administrator can change.

What are the functionalities and usage of the Paragraph Module


The Drupal 8+ Paragraphs module is a complete rewrite of the D7 module. Although based on the Entity Reference module in core, Paragraphs requires the Entity Reference Revisions module .

The Drupal Paragraphs module can make processes like these much more manageable for non-technical users while also giving developers the ability to control the formatting and appearance of such specially formatted elements at the theme level.

In practice, Paragraphs allows us to insert elements much like content fields, but instead of adding these around the body of any given piece of content, they are effectually inserted throughout the body.

Paragraphs defines

  • A selection method for the Entity Reference field
  • A widget for the Entity Reference Revisions field
  • Paragraph types

Features

This module has some overlapping functionality with field_collection, but this module has some advantages over field_collection.

  • Different fields per paragraph bundle
  • Using different paragraph bundles in a single paragraph field
  • Displays per paragraph bundle
  • Bundles are exportable with features.
  • Entities, so: exportable field bases/instances, usable in Search API, usable in View
Theming Paragraphs in Drupal 8

Paragraphs uses template naming suggestions like core Drupal modules. The default paragraphs template is provided in paragraphs/templates/paragraph.html.twig.

The following suggestions are available, from most specific (used first) to least specific:

  1. paragraph--[type]--[view-mode].html.twig  (e.g. paragraph--image--default.html.twig)
  2. paragraph--[type].html.twig (e.g. paragraph--image.html.twig)
  3. paragraph--[view-mode].html.twig (e.g. paragraph--default.html.twig)
  4. paragraph.html.twig

After adding a template, you must rebuild the cache in order for Drupal to discover your new template.

It is possible to create custom template name suggestions using the hook_theme_suggestions_HOOK_alter() function.

How to Create Directory in Drupal 8 and Drupal 9

Drupal 8

function drupal_mkdir

drupal_mkdir($uri, $mode = NULL, $recursive = FALSE, $context = NULL)

Creates a directory, optionally creating missing components in the path to the directory.

Code

function drupal_mkdir($uri, $mode = NULL, $recursive = FALSE, $context = NULL) {

  return \Drupal::service('file_system')->mkdir($uri, $mode, $recursive, $context);
}

Deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0. Use \Drupal\Core\File\FileSystem::mkdir().

Drupal 9

public function FileSystem::mkdir

public FileSystem::mkdir($uri, $mode = NULL, $recursive = FALSE, $context = NULL)

Creates a directory, optionally creating missing components in the path to the directory.

When PHP's mkdir() creates a directory, the requested mode is affected by the process's umask. This function overrides the umask and sets the mode explicitly for all directory components created.

@todo Update with open_basedir compatible recursion logic from \Drupal\Component\PhpStorage\FileStorage::ensureDirectory().

Parameters

string $uri: A URI or pathname.

int $mode: Mode given to created directories. Defaults to the directory mode configured in the Drupal installation. It must have a leading zero.

bool $recursive: Create directories recursively, defaults to FALSE. Cannot work with a mode which denies writing or execution to the owner of the process.

resource $context: Refer to http://php.net/manual/ref.stream.php

Return value

bool Boolean TRUE on success, or FALSE on failure.

Overrides FileSystemInterface::mkdir 

Drupal 7

function drupal_mkdir

Creates a directory, optionally creating missing components in the path to the directory.

When PHP's mkdir() creates a directory, the requested mode is affected by the process's umask. This function overrides the umask and sets the mode explicitly for all directory components created.

Parameters

$uri: A URI or pathname.

$mode: Mode given to created directories. Defaults to the directory mode configured in the Drupal installation. It must have a leading zero.

$recursive: Create directories recursively, defaults to FALSE. Cannot work with a mode which denies writing or execution to the owner of the process.

$context: Refer to http://php.net/manual/ref.stream.php

Return value

Boolean TRUE on success, or FALSE on failure.



Write a program in PHP to reverse a number

A number can be written in reverse order. For example 12345 = 54321 <?php   $ num = 23456;   $ revnum = 0;   while ($ num > 1)   {   $...