Drupal - sgml/signature GitHub Wiki

Backdrop CMS

YAD7

Search Queries

  • project references resources field overview roadmap -issues domain:www.drupal.org
  • title:faq site:www.drupal.org
  • dependencies composer d7 d8 development project site:drupal.org
  • drupal apply career site:org -site:drupal.org

Core Modules

  • kernel module
  • node module
  • JSON-API module
  • path module
  • dblog module
  • search module
  • taxonomy module
  • dynamic page cache module
  • contact module
  • field ui module
  • user module
  • path module

Licensing

Community Lead Documentation

Terminology

Data Modeling

The fact that taxonomy and localization are baked into Drupal's content model, gives a huge advantage over other systems that have a more limited concept of content.

Changelog

Deprecated Things / Breaking Changes

API Tools

EOL

Blog

Kernel

RDF

JSON-API

REST API

FTP

SOAP / WSDL

GraphQL

HTTPClient

JavaScript APIs

PHP Classes and Services API

PHP Upgrade

Composer API

Graceful Degradation

Script

Low code

Roadmap

Commercial Tools

Privacy

Release Cycle

Symfony

Laravel

Dependency Injection

Services

Controllers

Middleware

Users Table

User Auth

User Logout

Contact Forms

Notifications

Database APIs

Schema API

Redirects

Dates

Digital Asset Manager

Forum

Fundraising

Projects

Type System

Annotations

Utility APIs

Field Validation

Field UI

Field API

XSLT Integration

Custom Module Directory and File Structure

drupal-project/
└── modules/
    └── custom/
        └── xslt_processor/
            ├── src/
            │   ├── Controller/
            │   ├── Plugin/
            │   │   └── Field/
            │   │       └── Formatter/
            │   └── StackMiddleware/
            │       └── XmlMiddleware.php
            ├── xslt_processor.info.yml
            ├── xslt_processor.services.yml
            └── xslt_processor.module

XML Middleware

// src/StackMiddleware/XmlMiddleware.php
// Reference: https://www.drupal.org/docs/8/api/services-and-dependency-injection/middleware-api
namespace Drupal\xslt_processor\StackMiddleware;

use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernel;

class XmlMiddleware implements HttpKernelInterface {
  protected $httpKernel;

  public function __construct(HttpKernelInterface $httpKernel) {
    $this->httpKernel = $httpKernel;
  }

  public function handle(Request $request, int $type = HttpKernel::MAIN_REQUEST, bool $catch = true): Response {
    $response = $this->httpKernel->handle($request, $type, $catch);

    if ($response->headers->get('Content-Type') === 'application/xml') {
      $xslt = new \XSLTProcessor();
      $xsl = new \DOMDocument();
      $xsl->load('modules/custom/xslt_processor/identity_stylesheet.xsl');

      $xslt->importStylesheet($xsl);
      $xml = new \DOMDocument();
      $xml->loadXML($response->getContent());

      $xslt_version = $xsl->documentElement->getAttribute('version');
      $xslt->setParameter('', 'xslt_processor_version', $xslt_version);

      $transformed = $xslt->transformToXML($xml);
      $response->setContent($transformed);
      $response->headers->set('Content-Length', strlen($transformed));

      \Drupal::logger('xslt_processor')->info('XSLT Processor Version: @version', ['@version' => $xslt_version]);
    }

    return $response;
  }
}

XSLTProcessor

php_xsltprocessor:
  description: "The XSLTProcessor class in PHP allows setting parameters programmatically, which can be useful for command-line scripts."
  usage: |
    $xsltProcessor = new XSLTProcessor();
    $xsltProcessor->setParameter('name', 'value');
  params:
    - xsl:param
    - xsl:value-of
  reference: "https://www.php.net/manual/en/class.xsltprocessor.php"

XSLT Processor Service YAML Config

# xslt_processor.services.yml
services:
  xslt_processor.middleware:
    class: Drupal\xslt_processor\StackMiddleware\XmlMiddleware
    arguments: ['@http_kernel']
    tags:
      - { name: http_middleware, priority: 100 }

XSLT Processor Module Information Declaration

# xslt_processor.info.yml
name: 'XSLT Processor'
type: module
description: 'Integrate XSLTProcessor with Drupal 11 for XML transformations.'
core_version_requirement: ^8 || ^9 || ^10 || ^11
package: Custom
dependencies:
  - drupal:field
  - drupal:twig_tweak

Custom Preprocessor Module

// mymodule.module
function mymodule_preprocess_node(&$variables) {
  $node = $variables['node'];

  // Convert node to XML
  $xml = new \DOMDocument();
  $xml_node = $xml->createElement("node");
  $xml->appendChild($xml_node);

  $title = $xml->createElement("title", htmlspecialchars($node->title->value));
  $xml_node->appendChild($title);

  $body = $xml->createElement("body", htmlspecialchars($node->body->value));
  $xml_node->appendChild($body);

  // Add XSLT processor version
  $xslt_processor_version = '1.0'; // Static value for demonstration, replace with actual logic
  $version = $xml->createElement("xslt_processor_version", htmlspecialchars($xslt_processor_version));
  $xml_node->appendChild($version);

  $variables['node_xml'] = $xml->saveXML();
}

Identity Stylesheet

<!-- path/to/identity_stylesheet.xsl -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

Theme YAML

# mymodule.theme.yml
# Reference: https://www.drupal.org/docs/8/theming/twig/create-and-register-a-theme-suggestion-in-a-module
theme:
  node__content:
    variables:
      node_xml: NULL
    template: node--content
    base hook: page  # Reference to the default theme base hook for Drupal 11

Theme Hook

// mymodule.module
// mymodule.module
/**
 * Implements hook_theme().
 */
function mymodule_theme() {
  return [
    'node__content' => [
      'variables' => ['node_xml' => NULL],
      'template' => 'node--content',
      'base hook' => 'page',  // Reference to the default theme base hook for Drupal 11
    ],
  ];
}

/**
 * Preprocess function for nodes.
 */
// Reference: https://www.drupal.org/docs/8/theming/twig/create-and-register-a-theme-suggestion-in-a-module
function mymodule_preprocess_node(&$variables) {
  $node = $variables['node'];

  // Convert node to XML
  $xml = new \DOMDocument();
  $xml_node = $xml->createElement("node");
  $xml->appendChild($xml_node);

  $title = $xml->createElement("title", htmlspecialchars($node->title->value));
  $xml_node->appendChild($title);

  $body = $xml->createElement("body", htmlspecialchars($node->body->value));
  $xml_node->appendChild($body);

  // Add XSLT processor version
  $xslt_processor_version = '1.0'; // Static value for demonstration
  $version = $xml->createElement("xslt_processor_version", htmlspecialchars($xslt_processor_version));
  $xml_node->appendChild($version);

  $variables['node_xml'] = $xml->saveXML();
}

Template File Output

// node--content.tpl.php
// Reference: https://www.drupal.org/docs/8/theming/twig/create-and-register-a-theme-suggestion-in-a-module
<?php
  // Load the XML content
  $xml = new DOMDocument();
  $xml->loadXML($node_xml);

  // Initialize the XSLT processor
  $xslt = new XSLTProcessor();
  $xsl = new DOMDocument();
  $xsl->load('path/to/identity_stylesheet.xsl');

  // Import the stylesheet
  $xslt->importStylesheet($xsl);

  // Transform the XML
  $transformed = $xslt->transformToXML($xml);

  // Use heredoc for HTML content
  $html = <<<HTML
  <h1>XSLT Processor Version: {$xml->getElementsByTagName('xslt_processor_version')->item(0)->nodeValue}</h1>
  <h2>Title: {$xml->getElementsByTagName('title')->item(0)->nodeValue}</h2>
  <p>Body: {$xml->getElementsByTagName('body')->item(0)->nodeValue}</p>
  HTML;

  // Output the transformed content
  echo $html;
?>

References

Twig Templates

Plugins and Decorators

Symfony Plugins vs Events vs Tagged Services

Presentations

Deployment

Service Workers

Caching

Render

Major and Minor Version Updgrades

Upgrade

Drush

Static Site Generation

Offloading to serverless

Boilerplate

Issues

Sitemap

Search

Integrations

CiviCRM

Data sources

Opportunities to Contrib

Importing/Exporting to/from Wordpress

Symfony Customization

Configuration

Docker

Deployment

Routing

Paths

Theming

NPM + Decoupled Drupal

Views RSS

Tutorials

Message Bus

Endpoints

Media

Security

Installation

Database Connection Troubleshooting

Constants

DevOps

Customization

Directory Structure

Directory Definitions

   - `/core`: Contains all files required by Drupal's out-of-the-box usage (core), except for files explicitly included in the base directory.
   - `/libraries`: Holds third-party external libraries used by Drupal (e.g., WYSIWYG editors).
   - `/modules`: Houses custom and contributed modules (split into `contrib` and `custom` subdirectories).
   - `/profile`: Contains contributed and custom installation profiles.
   - `/themes`: Stores contributed and custom themes and subthemes (subthemes require the base theme to be installed here).

   - `sites/[domain OR default]` folder:
     - `/modules` and `/themes`: Site-specific modules and themes.
     - `/files`: Stores site-specific files, including user-uploaded content and configuration.
   
   - `/core` directory:
     - `/assets`: External libraries used by core (e.g., jQuery, underscore).
     - `/includes`: Base-level functionality used throughout Drupal.
     - `/lib`: Drupal core classes.
     - `/misc`: Frontend code dependencies.
     - `/modules`: Drupal's core modules.
     - `/profiles`: Core installation profiles (e.g., Minimal, Standard).
     - `/scripts`: Command-line interface (CLI) scripts for developers.
     - `/tests`: Drupal core tests.
     - `/themes`: Drupal core themes.

   - `/vendor`: External PHP packages managed by Composer.
   - `/web`: Parent directory for base-level and core directories.

Event Handling

Text Editing

Batch / ETL

Testing

Serialization

Database Logging (dblog)

Error Handling

Exception Handling

High Availability

Administration

Semantic URLs

Taxonomy

i18N

Tables

Certification

Industry Boards

Consultants

Standards Compliance

Example Domains

Sponsors

Export/Backup

Localhost

Simplytest

Repos

Wordpress vs Drupal

Drupal Wiki Module

Vs Drupal

Non-Profits

Drupal Module Upgrader

drupal_module_upgrader_installation:
  steps:
    - step: "Install Drush"
      description: "Ensure you have a modern version of Drush installed. Check the installation documentation on the Drush website for guidance."
      url: "https://www.drush.org/latest/install/"

    - step: "Install Composer"
      description: "DMU requires Composer. Make sure you have Composer installed on your system."
      url: "https://getcomposer.org/download/"

    - step: "Download DMU"
      command: "drush dl drupalmoduleupgrader"
      description: "Navigate to your Drupal 8 web root and run the command to download the DMU module."
      url: "https://www.drupal.org/project/drupalmoduleupgrader"

    - step: "Install Dependencies"
      command: "cd drupalmoduleupgrader && composer install"
      description: "Navigate to the DMU directory and run Composer to install the required dependencies."

    - step: "Enable DMU"
      command: "drush en drupalmoduleupgrader -y"
      description: "Enable the DMU module using Drush."

    - step: "Analyze or Upgrade"
      description: "Move your Drupal 7 module into the Drupal 8 modules directory."
      analyze_command: "drush dmu -analyze MODULE_NAME"
      upgrade_command: "drush dmu -upgrade MODULE_NAME"
      analyze_description: "To analyze the module and generate a report."
      upgrade_description: "To upgrade the module."

    - step: "Set Environment Variables for DMU"
      description: "Configure the necessary environment variables for Drupal Module Upgrader."
      environment_variables:
        - name: "DMU_ROOT"
          value: "The root directory of the Drupal installation."
        - name: "DMU_MODULES"
          value: "The directory containing the Drupal modules to be upgraded."
        - name: "DMU_BACKUP"
          value: "The directory where backups of the modules will be stored."
⚠️ **GitHub.com Fallback** ⚠️