Remove the Core/Any stylesheets or JavaScript from a theme in Drupal 8

 If you developing a Drupal 8 custom theme and notice the following CSS and JavaScript files are added automatically by Drupal, and you want to remove it .

CSS file

<link rel="stylesheet" href="/core/themes/stable/css/system/components/ajax-progress.module.css?owah24" media="all" />

<link rel="stylesheet" href="/core/themes/stable/css/system/components/align.module.css?owah24" media="all" />

<link rel="stylesheet" href="/core/themes/stable/css/system/components/autocomplete-loading.module.css?owah24" media="all" />

<link rel="stylesheet" href="/core/themes/stable/css/system/components/fieldgroup.module.css?owah24" media="all" />

<link rel="stylesheet" href="/core/themes/stable/css/system/components/container-inline.module.css?owah24" media="all" />

<link rel="stylesheet" href="/core/themes/stable/css/system/components/clearfix.module.css?owah24" media="all" />

<link rel="stylesheet" href="/core/themes/stable/css/system/components/details.module.css?owah24" media="all" />

<link rel="stylesheet" href="/core/themes/stable/css/system/components/hidden.module.css?owah24" media="all" />

<link rel="stylesheet" href="/core/themes/stable/css/system/components/item-list.module.css?owah24" media="all" />

<link rel="stylesheet" href="/core/themes/stable/css/system/components/js.module.css?owah24" media="all" />

<link rel="stylesheet" href="/core/themes/stable/css/system/components/nowrap.module.css?owah24" media="all" />

<link rel="stylesheet" href="/core/themes/stable/css/system/components/position-container.module.css?owah24" media="all" />

<link rel="stylesheet" href="/core/themes/stable/css/system/components/progress.module.css?owah24" media="all" />

<link rel="stylesheet" href="/core/themes/stable/css/system/components/reset-appearance.module.css?owah24" media="all" />

<link rel="stylesheet" href="/core/themes/stable/css/system/components/resize.module.css?owah24" media="all" />

<link rel="stylesheet" href="/core/themes/stable/css/system/components/sticky-header.module.css?owah24" media="all" />

<link rel="stylesheet" href="/core/themes/stable/css/system/components/system-status-counter.css?owah24" media="all" />

<link rel="stylesheet" href="/core/themes/stable/css/system/components/system-status-report-counters.css?owah24" media="all" />

<link rel="stylesheet" href="/core/themes/stable/css/system/components/system-status-report-general-info.css?owah24" media="all" />

<link rel="stylesheet" href="/core/themes/stable/css/system/components/tabledrag.module.css?owah24" media="all" />

<link rel="stylesheet" href="/core/themes/stable/css/system/components/tablesort.module.css?owah24" media="all" />

<link rel="stylesheet" href="/core/themes/stable/css/system/components/tree-child.module.css?owah24" media="all" />

JavaScript File

<script src="https://use.fontawesome.com/releases/v5.13.1/js/all.js'"></script>

<script src="core/misc/progress.js"></script>

<script src="core/misc/displace.js"></script>

Use below code for removing Stylesheet and JavaScript File

in custom_theme.info.yml add below line

For removing Stylesheet

libraries-override:

  system/base: false

OR

stylesheets-remove:

  - core/modules/system/css/components/ajax-progress.module.css

  - core/modules/system/css/components/align.module.css

  - modules/ajax_loader/css/throbber-general.css

  - core/modules/system/css/components/autocomplete-loading.module.css

  - core/modules/system/css/components/fieldgroup.module.css

  - core/modules/system/css/components/clearfix.module.css

  - core/modules/system/css/components/details.module.css

  - core/modules/system/css/components/item-list.module.css

  - core/modules/system/css/components/js.module.css

  - core/modules/system/css/components/nowrap.module.css

  - core/modules/system/css/components/container-inline.module.css

  - core/modules/system/css/components/position-container.module.css

  - core/modules/system/css/components/progress.module.css

  - core/modules/system/css/components/reset-appearance.module.css

  - core/modules/system/css/components/resize.module.css

  - core/modules/system/css/components/sticky-header.module.css

  - core/modules/system/css/components/system-status-counter.css

  - core/modules/system/css/components/system-status-report-counters.css

  - core/modules/system/css/components/tabledrag.module.css

  - core/modules/system/css/components/tree-child.module.css

  - core/modules/contextual/css/contextual.module.css

  - modules/select2boxes/css/select2boxes.theme.css

  - core/modules/views/css/views.module.css

  - core/modules/system/css/components/system-status-report-general-info.css

  - core/modules/system/css/components/tablesort.module.css

  - core/assets/vendor/jquery.ui/themes/base/core.css

  - core/assets/vendor/jquery.ui/themes/base/checkboxradio.css

  - core/assets/vendor/jquery.ui/themes/base/controlgroup.css

  - core/assets/vendor/jquery.ui/themes/base/resizable.css

  - core/assets/vendor/jquery.ui/themes/base/button.css

  - core/assets/vendor/jquery.ui/themes/base/dialog.css

  - core/modules/contextual/css/contextual.theme.css

  - core/modules/contextual/css/contextual.icons.theme.css

  - core/assets/vendor/jquery.ui/themes/base/theme.css

For JavaScript 

in theme.theme file use below code

function custometheme_js_alter(&$js) {

unset($js['https://use.fontawesome.com/releases/v5.13.1/js/all.js']);

unset($js['core/misc/progress.js']);

  unset($js['core/misc/displace.js']);

  //unset($js['themes/aeg/js/core.js']);

//echo "<pre>";

//print_r($js); die;

}

Explain how Drupal database system works

 Database server requirements

Required MySQL 5.5.3/MariaDB 5.5.20/Percona Server 5.5.8 or higher with InnoDB as the primary storage engine, and requires the PDO database extension.

Drupal 9 requires MariaDB 10.3+ or MySQL/Percona 5.7.8+.

Environment requirements of Drupal 9

If you are running Drupal 9 on Nginx, at least version 0.7.x is required.

If you are running Drupal 9 on Apache, at least version 2.4.7 is required.

Drupal 9 requires at least PHP 7.3. PHP 7.4 is also supported but not required. PHP 8 is supported from Drupal 9.1.0

Database backend requirements

If using Drupal 9 with MySQL or Percona, version 5.7.8+ is required.

If using Drupal 9 with MariaDB, version 10.3.7+ is required.

If using Drupal 9 with SQLite, version 3.26+ is required. (PHP 7.4 does not use the system provided SQLite, so take extra care to make sure your PHP is compiled with at least this version).

If using Drupal 9 with PostgreSQL, version 10 is required with the pg_trgm extension. 

Drupal Database

Drupal stores information in a database, each type of information has its own database table. For example the basic information about the nodes of your site are stored in the Node table, and if you use the CCK module to add fields to your content type, the field information is stored in separate tables . Comments and Users also have their own database tables, and roles, permissions, and other settings are also stored in database tables.




















Database abstraction layer

Drupal's database abstraction layer provides a unified database query API that can query different underlying databases. It is built upon PHP's PDO (PHP Data Objects) database API, and inherits much of its syntax and semantics.

The Drupal database layer is built on top of the PHP's PDO library. 

Because different databases require different sorts of interaction, the Drupal database layer requires a driver for each database type. A driver consists of a series of files located in includes/database/driver, where driver is a string representing the unique key for that driver. In most cases the driver key is the lowercase version of the database name, such as "mysql", "pgsql", or "mycustomdriver".

Connections

A connection is an object of class DatabaseConnection, which inherits from the PDO class. 

To access (and open if necessary) a connection object, use:

$database = \Drupal::database();

// Or

$database = \Drupal::service('database');

If services are not yet available, \Drupal\Core\Database\Database::getConnection() can get a database connection.

Database Configuration

Database connection is via the $databases array in settings.php.

The $databases array is a nested array of at least three levels. The first level defines the database keys. The second defines the database targets. The value of each target is the connection information for that key/target. Some examples should make that clearer.

$databases['default']['default'] = array(

  'driver' => 'mysql',

  'database' => 'drupaldb',

  'username' => 'username',

  'password' => 'secret',

  'host' => 'localhost',

);

Instantiating a Database Connection Object

Database interaction should be done via a database connection object.

The best way to instantiate a database connection object is via the Service Container.

Example:

$database = \Drupal::database();

// Or

$database = \Drupal::service('database');




Twig Filters

 Filters in Twig can be used to modify variables. Filters are separated from the variable by a pipe symbol. They may have optional arguments in parentheses. Multiple filters can be chained. The output of one filter is applied to the next.

Example:

{{ content|safe_join(", ")|lower }}

You may have to render an item before you filter it:

{{ item|render|filter }}

#Translation filters

This filter (alternatively, t) will run the variable through the Drupal t() function, which will return a translated string. This filter should be used for any interface strings manually placed in the template that will appear for users.

Example

<a href="{{ url('<front>') }}" title="{{ 'Home'|t }}" rel="home" class="site-logo"></a>

{% set name = '@label Introduction' |t({'@label': node.title.value}) %}

#placeholder

This filter escapes content to HTML and formats it using drupal_placeholder(), which makes it display as emphasized text.

Example

{% trans %}Submitted on {{ date|placeholder }}{% endtrans %}

#abs

The abs filter returns the absolute value.

Example 

{# number = -5 #}

{{ number|abs }}

{# outputs 5 #}

#batch

The batch filter "batches" items by returning a list of lists with the given number of items. A second parameter can be provided and used to fill in missing items:

{% set items = ['a', 'b', 'c', 'd'] %}

<table>

    {% for row in items|batch(3, 'No item') %}

        <tr>

            {% for column in row %}

                <td>{{ column }}</td>

            {% endfor %}

        </tr>

    {% endfor %}

</table>

The above example will be rendered as:

<table>

    <tr>

        <td>a</td>

        <td>b</td>

        <td>c</td>

    </tr>

    <tr>

        <td>d</td>

        <td>No item</td>

        <td>No item</td>

    </tr>

</table>

#date

The date filter formats a date to a given format:

{{ post.published_at|date("m/d/Y") }}

to display the current date, filter the word "now"

{{ "now"|date("m/d/Y") }}

#join

The join filter returns a string which is the concatenation of the items of a sequence

{{ [1, 2, 3]|join }}

{# returns 123 #}

The separator between elements is an empty string per default, but you can define it with the optional first parameter:

{{ [1, 2, 3]|join('|') }}

{# outputs 1|2|3 #}

A second parameter can also be provided that will be the separator used between the last two items of the sequence:

{{ [1, 2, 3]|join(', ', ' and ') }}

{# outputs 1, 2 and 3 #}

List of Main twig filter are below

abs

batch

capitalize

column

convert_encoding

date

date_modify

first

keys

lower

split

title

trim

upper

Difference between UNIQUE and PRIMARY key

MySQL Primary Keys

In MySQL, a primary key is a single field or combination of fields that uniquely defines a record. None of the fields that are part of the primary key can contain a NULL value. A table can have only one primary key.

In MySQL, a primary key is created using either a CREATE TABLE statement or an ALTER TABLE statement.

You use the ALTER TABLE statement in MySQL to drop, disable or enable a primary key.

MySQL Unique Key

A unique key in MySQL is a single field or combination of fields that ensure all values going to store into the column will be unique. It means a column cannot stores duplicate values. For example, the email addresses and roll numbers of students in the "student_info" table or contact number of employees in the "Employee" table should be unique.

MySQL allows us to use more than one column with UNIQUE constraint in a table. It can accept a null value, but MySQL allowed only one null value per column. It ensures the integrity of the column or group of columns to store different values into a table.

Needs of Unique Key

It is useful in preventing the two records from storing identical values into the column.

It stores only distinct values that maintain the integrity and reliability of the database for accessing the information in an organized way.

It also works with a foreign key in preserving the uniqueness of a table.

It can contain null value into the table.

Difference between Primary Key and Unique Key

Primary Key

Unique identifier for rows of a table

Cannot be NULL

Only one primary key can be present in a table

present in a table

Selection using primary key creates clustered index

Unique Key

Unique identifier for rows of a table when primary key is not present

Can be NULL

Multiple Unique Keys can be present in a table

present in a table

Selection using unique key creates non-clustered index


The syntax to create a primary key using the CREATE TABLE statement in MySQL is:

CREATE TABLE contacts

( contact_id INT(11) NOT NULL AUTO_INCREMENT,

  last_name VARCHAR(30) NOT NULL,

  first_name VARCHAR(25),

  birthday DATE,

  CONSTRAINT contacts_pk PRIMARY KEY (contact_id)

);

Create Primary Key - Using ALTER TABLE statement

ALTER TABLE contacts

  ADD CONSTRAINT contacts_pk 

    PRIMARY KEY (contact_id);

The following syntax is used to create a unique key in MySQL.

CREATE TABLE table_name(  

    col1 datatype,  

    col2 datatype UNIQUE,  

    ...  

);  

for creating more than one Unique Key

CREATE TABLE table_name(  

  col1 col_definition,  

  col2 col_definition,  

  ...  

  [CONSTRAINT constraint_name]  

  UNIQUE(column_name(s))  

);  


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)   {   $...