LogoLogo
9.0.x
9.0.x
  • Overview
    • About Varbase
    • Roadmap
    • Release Cycle and Supported Versions
    • How to Get Support
  • Developers
    • Getting Started
    • Installing Varbase
      • Requirements
      • Installing Varbase with DDEV
      • Installing Varbase with Lando
    • Understanding Varbase
      • Basic Concepts
      • Core Components
        • Varbase Core
          • Varbase Admin
          • Varbase Page
          • Varbase Security
          • Varbase Webform
          • Varbase Default Content
          • Varbase Tour
        • Varbase Media
        • Varbase Editor
        • Varbase Email
        • Varbase SEO
        • Varbase Workflow
        • Varbase Layout Builder
          • Varbase Landing page (Layout Builder)
          • Varbase Heading Block
          • Varbase Rich Text Block
          • Varbase HTML Code Block
          • Varbase Media (Image/Video) Block
          • Varbase Gallery Block
        • Varbase Total Control Dashboard
        • Vartheme Claro
        • Vartheme BS4
      • Optional Components
        • Varbase API
        • Varbase Internationalization
        • Varbase Media Hero Slider
        • Varbase Carousels
        • Varbase Blog
        • Varbase Search
        • Varbase Social Single Sign-On
        • Varbase Media Twitter
        • Varbase Media Instagram
        • Varbase Content Planner
        • Varbase Bootstrap Paragraphs
          • Varbase Bootstrap Paragraphs Text and Image
        • Varbase Landing Page (Paragraphs)
      • Additional Components
        • Varbase Media Header
        • Varbase FAQs
        • Varbase Reports
        • Varbase Commerce
        • Varbase YouTube Import
      • Development Components
        • Varbase Development
        • Varbase Style Guide
        • Reroute Email
        • Varbase Updates Helper
    • Configuring a Varbase Site
      • Navigation
        • Defining Active Menu Trail Using Menu Position
      • Using View Modes Inventory
      • Content Moderation and Workflows
      • URL Aliases in Varbase/Drupal
        • Configuring URL Aliases
        • Managing URL Aliases
      • Managing URL Patterns for Multilingual Websites
      • Managing Date and Time Formats to Display Across the Site
      • Using Varbase Layout Builder
        • Creating a Landing Page With Varbase Layout Builder
        • Activating Varbase Layout Builder for Content Types
      • Configuring Pathologic When Going Live
      • Configuring SEO Features
        • Disallow Oembed Media Links
      • Configuring Security Features
        • Spam Protection
        • Password Policies
        • Other Security Kits
        • Flood Contorl
        • Enable HTTP Password Authentication
      • Configuring JSON:API Features
      • Configure Varbase Media Hero Slider
      • Configuring Varbase Media Header
      • Configuring Varbase Mailer Settings
        • Configure Symfony Mailer
        • Configure Swift Mailer
        • Switch From Swift Mailer to Symfony Mailer
      • Entity Definition Update Manager Class
      • Module Installer Factory Class
    • Theme Development with Varbase
      • Understanding The Vartheme Base Theme
      • Creating Your Own Theme
      • Local Tasks and Moderation Sidebar
      • Add Preloaded Fonts in Vartheme
      • Switch From Node SASS to Dart SASS for Old Sub-Themes
    • Launching a Varbase Site to Production
    • Updating a Varbase Site
      • Understanding Varbase Updater Package
      • Handling Patches When Updating
      • Handling Configuration Updates
      • Updating Varbase to work with Composer 2.0
      • Updating Drush to the Latest Stable Version
      • Version Update Guides
        • Updating Varbase ~9.0 to Drupal 10
        • Switch from CKEditor 4 to CKEditor 5 in Varbase ~9.1.0
        • Updating from Varbase 8.x to 9.x
    • Varbase Patches
    • Frequently Asked Questions (FAQs)
    • Extending Varbase
      • Overriding Varbase
      • Creating Your Own Feature
      • Creating A Sub Profile From Varbase
        • Varbase Sub Profile Generator
        • Varbase Sub Profile Basic Template
        • Varbase Sub Profile Basic Project Template
      • Install Needed YARN and Gulp Tools
      • Compiling Provided Component Styles
      • Check Standards/Practice Coding And Linting
  • Content Designers
    • Terminology
    • Accessing the Administration Area
      • Website Environments
    • User Management
      • Allow Email/Username Login & Registration
      • Default Roles and Site Personas
        • Edit Roles' Permissions
        • Managing Roles
      • Add User
      • Edit User
      • Masquerading as another user
    • Dashboard
      • Reports
    • Content Structure
      • EntityQueues
      • Menu Management
        • Add Menu Items
        • Update Menu Items
        • Adding a Page to the Menu
      • Taxonomies
        • Manage Vocabulary
        • Edit Vocabulary
        • List Terms
        • Add Terms
        • Reorder and Edit Terms
      • Webforms
        • Setting up Emails Handler Conditions
        • Setting up Confirmations Message Settings Types
    • Content Management
      • Create Content
        • Add a Basic page
        • Add a Landing page
        • Add Blog
        • Add Media
          • Image
          • Remote video
          • Video
      • Modify Content
      • Delete Content
      • Preview Content
      • Bulk Edit Content
      • Content Moderation
      • Publish Content
      • URL Alias
    • About Layout Builder
      • Section
      • Custom Blocks
        • Heading Block
        • Basic Block
        • Media Block(Image/Video)
        • Rich-Text Editor “WYSIWYG”
      • Managing Blocks
    • Search Engine Optimization
      • XML Sitemap
      • Meta Tags in Varbase
      • URL Redirects
      • Domain Redirects
      • Prevent a Single Content From Being Indexed
    • Site Configuration
      • System
        • Clearing Varbase Cache
        • Google analytics
        • Mail templates
      • User interface
      • Development
      • Varbase settings
      • Web services
    • Common Error Handling Tips
  • Contributing
    • Contributing to Documentation
Powered by GitBook
On this page
  • How to use the Module Installer Factory Class
  • 1. Require the Package in your root composer.json file
  • 2. Add Needed Namespace
  • Use the following methods in your custom install events
  • Install a list of modules
  • Arguments for installList method:
  • Set the weight of the module after installation of the list of modules
  • Arguments for setModuleWeightAfterInstallation:
  • Import configuration from scaned directory
  • Example 1: Import all field storage configs
  • Example 2: Import all custom settings files from a managed folder in the module.
  • Import configuration from array list of config files
  • Example 1: Import configs from a managed config folder
  • Arguments for importConfigsFromList method:
  • Example 2: In Use Import of Configs
  1. Developers
  2. Configuring a Varbase Site

Module Installer Factory Class

PreviousEntity Definition Update Manager ClassNextTheme Development with Varbase

Last updated 1 year ago

Provides developers with a class for modules installer factory.

This class is working with module_name.info.yml file with any modules key.

Let us have the module_name.info.yml with the following items under install key for example:

name: "Module Name"
description: "Module description."
type: module
core_version_requirement: ^9
dependencies:
  - drupal:node
  - drupal:editor
  - drupal:ckeditor
  - drupal:filter
install:
  - extlink
  - linkit
  - anchor_link

So that the installed modules could be disabled in some projects without the need to disable the used module.

It's installed only not a dependency.

How to use the Module Installer Factory Class

1. Require the Package in your root composer.json file

  "vardot/module-installer-factory": "~1.0"

Or require the Package in your Project with a command

$ composer require vardot/module-installer-factory:~1.0

2. Add Needed Namespace

Add the following namespace in custom modules or custom installation profiles.

use Vardot\Installer\ModuleInstallerFactory;

Use the following methods in your custom install events

Install a list of modules

Install the list of module in the varbase_core.info.yml

  ModuleInstallerFactory::installList('varbase_core');

Arguments for installList method:

  • String $moduleName: The machine name for the module.

  • String $modulesListKey: Optional list key which to get the list of modules from. Default 'install'. It can be changed on managed cases like (managed, when_module_name_enabled)

  • Boolean $setModuleWeight: A flag to auto set the weight of the module after installation of a list of modules.

which is equivalent to:

  ModuleInstallerFactory::installList('varbase_core', 'install', TRUE);

Set the weight of the module after installation of the list of modules

To make sure that any hook or event subscriber works after all used modules.

  ModuleInstallerFactory::setModuleWeightAfterInstallation('varbase_core', 'install');

Arguments for setModuleWeightAfterInstallation:

  • String $moduleName: The machine name for the module.

  • String $modulesListKey: Optional list key which to get the list of modules from. Default

  • Array $modules: Optional list of modules in an array.

To set the weight of the module after listed modules with a selected set of modules for example: If the varbase_core.info.yml file had

set_weight_after:
  - ctools
  - token
  - block_class

even tho if the module did not enable them.

  ModuleInstallerFactory::setModuleWeightAfterInstallation('varbase_core', 'set_weight_after');

or can be passed as an array as follows:

  ModuleInstallerFactory::setModuleWeightAfterInstallation('varbase_core', '', ['ctools', 'token', 'block_class']);

At this point any hook or event subscriber will be processed after the listed modules.

Import configuration from scaned directory

Example 1: Import all field storage configs

  ModuleInstallerFactory::importConfigsFromScanedDirectory('varbase_core', '/^field.storage.*\\.(yml)$/i', 'config/optional');

Example 2: Import all custom settings files from a managed folder in the module.

  ModuleInstallerFactory::importConfigsFromScanedDirectory('varbase_security', '/^.*(settings.yml)$/i', 'config/managed');

Import configuration from array list of config files

Example 1: Import configs from a managed config folder

  ModuleInstallerFactory::importConfigsFromList('varbase_admin', 
  [
    'views.view.content',
    'views.view.user_admin_people',
  ],
  'config/managed');

Arguments for importConfigsFromList method:

  • String $moduleName: The machine name for the module.

  • Array $listOfConfigFiles: The list of config files.

  • String $configDirectory: The config directory which to partial import the list from.

It could be used in some cases to change the default View for the Content or People with multilingual sites or extra filters by other modules. It is important which manage the Assemble components and install installation step.

Example 2: In Use Import of Configs

Having a custom config for a disabled module, which will be Enabled and Disabled many times with development and deployments, but they need to have the basic extra change for config over the default settings or configs for the used module.

/**
 * Implements hook_modules_installed().
 */
function varbase_security_modules_installed($modules, $is_syncing) {
  if (in_array('security_review', $modules)) {
    // The module will be Enabled and Disabled many times
    // with development and deployments to production sites.
    // But the need to have the basic extra change for config over
    // the Security Review default configs.
    // -------------------------------------------------
    // Managed configs for the Security Review module.
    $managed_configs = [
      'security_review.settings',
      'security_review.check.security_review-admin_permissions',
      'security_review.check.security_review-error_reporting',
      'security_review.check.security_review-executable_php',
      'security_review.check.security_review-failed_logins',
      'security_review.check.security_review-field',
      'security_review.check.security_review-file_perms',
      'security_review.check.security_review-input_formats',
      'security_review.check.security_review-private_files',
      'security_review.check.security_review-query_errors',
      'security_review.check.security_review-temporary_files',
      'security_review.check.security_review-trusted_hosts',
      'security_review.check.security_review-upload_extensions',
      'security_review.check.security_review-views_access',
    ];

    // Import managed configs to the site active configs.
    ModuleInstallerFactory::importConfigsFromList('varbase_security', $managed_configs, 'config/managed/security_review');

    // Entity updates to clear up any mismatched entity and/or field definitions
    // And Fix changes were detected in the entity type and field definitions.
    \Drupal::classResolver()
      ->getInstanceFromDefinition(EntityDefinitionUpdateManager::class)
      ->applyUpdates();
  }
}
GitHub - Vardot/module-installer-factory: Module Installer FactoryGitHub
Logo