Commit a4d9be3e authored by Rajab Natshah's avatar Rajab Natshah
Browse files

Issue #3400506: Refactor updates for Varbase Layout Builder by moving hook...

Issue #3400506: Refactor updates for Varbase Layout Builder by moving hook updates to include/updates with load Include based on major branches
parent b7b79807
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
# Varbase Layout Builder

Provides default configuration and enhancements to utilize Drupal core's Layout Builder.
Provides default configuration and enhancements to utilize
 Drupal core's Layout Builder.

Utilizing the [Bootstrap Layout Builder](https://www.drupal.org/project/bootstrap_layout_builder) module. Optimized for Varbase standard layouts and styling configurations. Having custom Layout options, and custom styling plugins.

## Varbase Landing Page (Layout Builder)
Having a Landing page (Layout Builder) content type and related configuration. To be used for building pages with custom sections and layouts to display content in a modern way.
Having a Landing page (Layout Builder) content type and related configuration.

To be used for building pages with custom sections and layouts to display
 content in a modern way.

## Ready Block Types:
### Varbase Heading block
A heading block is used to add headings to your page or sections. Headings help structure your page making your content easier to read by humans and search engines.
A heading block is used to add headings to your page or sections.
Headings help structure your page making your content easier to
read by humans and search engines.

### Varbase Rich text block
A rich text block contains a title and a body with a rich text format.
@@ -27,7 +33,9 @@ A gallery block contains a title and a gallery of images and videos.
## Use With [Varbase](https://www.drupal.org/project/varbase) Distribution:
This module is best used with [Varbase](https://www.drupal.org/project/varbase) distribution.

Varbase Layout Builder can be installed with any Drupal 8/9 site. Even if installed with the Minimal or Standard profile.
Varbase Layout Builder can be installed with any Drupal 8/9/10 site.
Even if installed with the Minimal or Standard profile.

However, using it with [Varbase](https://www.drupal.org/project/varbase) gives you way much more cool stuff!

# [Varbase documentation](https://docs.varbase.vardot.com/dev-docs/understanding-varbase/core-components/varbase-layout-builder)
@@ -36,6 +44,4 @@ Check out Varbase documentation for more details.
Join Our Slack Team for Feedback and Support
Join now: http://slack.varbase.vardot.com/

This module is sponsored and developed by [Vardot](https://www.drupal.org/vardot).

Sponsored and developed by [Vardot](https://www.drupal.org/vardot).
+11 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Contains List of all varbase_layout_builder updates.
 */

\Drupal::moduleHandler()->loadInclude('varbase_layout_builder', 'inc', 'include/updates/v8');
\Drupal::moduleHandler()->loadInclude('varbase_layout_builder', 'inc', 'include/updates/v9');
\Drupal::moduleHandler()->loadInclude('varbase_layout_builder', 'inc', 'include/updates/v10-0');
\Drupal::moduleHandler()->loadInclude('varbase_layout_builder', 'inc', 'include/updates/v10-1');
+139 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Contains varbase_layout_builder_update_100###(s) hook updates.
 */

use Symfony\Component\Yaml\Yaml;
use Drupal\Core\Config\InstallStorage;
use Vardot\Installer\ModuleInstallerFactory;

/**
 * Issue #3210657: Add Boxed options ( Wide, Medium, Narrow, Tiny )
 */
function varbase_layout_builder_update_10001() {
  $module_path = Drupal::service('module_handler')->getModule('varbase_layout_builder')->getPath();

  // Install configs path.
  $install_path = $module_path . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY;
  if (is_dir($install_path)) {

    // Have forced configs import.
    $forced_configs_import = [
      'varbase_layout_builder.layout_defaults',
    ];

    foreach ($forced_configs_import as $config_name) {

      $config_path = $install_path . '/' . $config_name . '.yml';
      if (file_exists($config_path)) {
        $config_content = file_get_contents($config_path);
        $config_data = (array) Yaml::parse($config_content);
        $config_factory = \Drupal::configFactory()->getEditable($config_name);
        $config_factory->setData($config_data)->save(TRUE);
      }
    }
  }
}

/**
 * Issue #3218194: Add Vertical and Horizontal alignments.
 *
 * To section styling settings.
 */
function varbase_layout_builder_update_10002() {
  $config_factory = \Drupal::configFactory()->getEditable('bootstrap_styles.settings');
  $config_factory->set('horizontal_alignment', "justify-content-start|Align start\r\njustify-content-center|Align center\r\njustify-content-end|Align end");
  $config_factory->set('vertical_alignment', "align-items-start|Align top\r\nalign-items-center|Align middle\r\nalign-items-end|Align bottom");
  $config_factory->save();
}

/**
 * Issue #3244849: Fix border color (side) variation classes.
 *
 * In Bootstrap Styles for Varbase Layout Builder default configs.
 */
function varbase_layout_builder_update_10003() {
  $config_factory = \Drupal::configFactory()->getEditable('bootstrap_styles.settings');

  // Only update if the border_left_color current config
  // value is not changed from the old config.
  $current_border_left_color = $config_factory->get('border_left_color');
  $old_border_left_color = "border-start border-primary|Primary\r\nborder-start border-secondary|Secondary\r\nborder-start border-success|Success\r\nborder-start border-danger|Danger\r\nborder-start border-warning|Warning\r\nborder-start border-info|Info\r\nborder-start border-light|Light\r\nborder-start border-dark|Dark\r\nborder-start border-white|White";
  $new_border_left_color = "border-start border-start-primary|Primary\r\nborder-start border-start-secondary|Secondary\r\nborder-start border-start-success|Success\r\nborder-start border-start-danger|Danger\r\nborder-start border-start-warning|Warning\r\nborder-start border-start-info|Info\r\nborder-start border-start-light|Light\r\nborder-start border-start-dark|Dark\r\nborder-start border-start-white|White";
  if ($current_border_left_color === $old_border_left_color) {
    $config_factory->set('border_left_color', $new_border_left_color);
    $config_factory->save();
  }

  // Only update if the border_top_color current config
  // value is not changed from the old config.
  $current_border_top_color = $config_factory->get('border_top_color');
  $old_border_top_color = "border-top border-primary|Primary\r\nborder-top border-secondary|Secondary\r\nborder-top border-success|Success\r\nborder-top border-danger|Danger\r\nborder-top border-warning|Warning\r\nborder-top border-info|Info\r\nborder-top border-light|Light\r\nborder-top border-dark|Dark\r\nborder-top border-white|White";
  $new_border_top_color = "border-top border-top-primary|Primary\r\nborder-top border-top-secondary|Secondary\r\nborder-top border-top-success|Success\r\nborder-top border-top-danger|Danger\r\nborder-top border-top-warning|Warning\r\nborder-top border-top-info|Info\r\nborder-top border-top-light|Light\r\nborder-top border-top-dark|Dark\r\nborder-top border-top-white|White";
  if ($current_border_top_color === $old_border_top_color) {
    $config_factory->set('border_top_color', $new_border_top_color);
    $config_factory->save();
  }

  // Only update if the border_right_color current
  // config value is not changed from the old config.
  $current_border_right_color = $config_factory->get('border_right_color');
  $old_border_right_color = "border-end border-primary|Primary\r\nborder-end border-secondary|Secondary\r\nborder-end border-success|Success\r\nborder-end border-danger|Danger\r\nborder-end border-warning|Warning\r\nborder-end border-info|Info\r\nborder-end border-light|Light\r\nborder-end border-dark|Dark\r\nborder-end border-white|White";
  $new_border_right_color = "border-end border-end-primary|Primary\r\nborder-end border-end-secondary|Secondary\r\nborder-end border-end-success|Success\r\nborder-end border-end-danger|Danger\r\nborder-end border-end-warning|Warning\r\nborder-end border-end-info|Info\r\nborder-end border-end-light|Light\r\nborder-end border-end-dark|Dark\r\nborder-end border-end-white|White";
  if ($current_border_right_color === $old_border_right_color) {
    $config_factory->set('border_right_color', $new_border_right_color);
    $config_factory->save();
  }

  // Only update if the border_bottom_color current
  // config value is not changed from the old config.
  $current_border_bottom_color = $config_factory->get('border_bottom_color');
  $old_border_bottom_color = "border-bottom border-primary|Primary\r\nborder-bottom border-secondary|Secondary\r\nborder-bottom border-success|Success\r\nborder-bottom border-danger|Danger\r\nborder-bottom border-warning|Warning\r\nborder-bottom border-info|Info\r\nborder-bottom border-light|Light\r\nborder-bottom border-dark|Dark\r\nborder-bottom border-white|White";
  $new_border_bottom_color = "border-bottom border-bottom-primary|Primary\r\nborder-bottom border-bottom-secondary|Secondary\r\nborder-bottom border-bottom-success|Success\r\nborder-bottom border-bottom-danger|Danger\r\nborder-bottom border-bottom-warning|Warning\r\nborder-bottom border-bottom-info|Info\r\nborder-bottom border-bottom-light|Light\r\nborder-bottom border-bottom-dark|Dark\r\nborder-bottom border-bottom-white|White";
  if ($current_border_bottom_color === $old_border_bottom_color) {
    $config_factory->set('border_bottom_color', $new_border_bottom_color);
    $config_factory->save();
  }
}

/**
 * Issue #3272216: Switch to use the Module Installer Factory.
 *
 * In the Varbase Layout Builder module.
 */
function varbase_layout_builder_update_10004() {
  // Set the weight of the module after installation of list of modules.
  // To make sure that any hook or event subscriber works after
  // all used modules.
  ModuleInstallerFactory::setModuleWeightAfterInstallation('varbase_layout_builder');
}

/**
 * Issue #3272221: Prevent anonymous users from accessing.
 *
 * The Sections Library page.
 */
function varbase_layout_builder_update_10005() {
  if (\Drupal::service('module_handler')->moduleExists('section_library')) {
    $viewSectionLibrary = \Drupal::service('config.factory')->getEditable('views.view.section_library');
    $permission = $viewSectionLibrary->get('display.default.display_options.access.options.perm');

    if ($permission === 'access content') {
      $viewSectionLibrary->set('display.default.display_options.access.options.perm', 'view section library templates')->save(TRUE);
    }
  }
}

/**
 * Issue #3337351: Fix empty/missing box shadow configs.
 *
 * For the Bootstrap Styles.
 */
function varbase_layout_builder_update_10006() {
  if (\Drupal::service('module_handler')->moduleExists('bootstrap_styles')) {
    $bootstrap_styles_settings = \Drupal::service('config.factory')->getEditable('bootstrap_styles.settings');
    $bootstrap_styles_settings->set('box_shadow', "shadow-sm|Small\r\nshadow|Regular\r\nshadow-lg|Large")->save(TRUE);
  }
}
+25 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Contains varbase_layout_builder_update_101###(s) hook updates.
 */

/**
 * Issue #3383937: Remove the remaining optional config.
 *
 * For layout_builder_iframe_modal.settings config.
 */
function varbase_layout_builder_update_10102() {

  // Install Layout Builder Modal module if it was not enabled.
  if (!\Drupal::moduleHandler()->moduleExists('layout_builder_modal')) {
    \Drupal::service('module_installer')->install(['layout_builder_modal'], FALSE);
  }

  // Remove the leftover optional layout_builder_iframe_modal.settings
  // config if the module was uninstalled.
  if (!\Drupal::moduleHandler()->moduleExists('layout_builder_iframe_modal')) {
    \Drupal::configFactory()->getEditable('layout_builder_iframe_modal.settings')->delete();
  }
}

include/updates/v8.inc

0 → 100644
+47 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Contains varbase_layout_builder_update_8###(s) hook updates.
 */

/**
 * Issue #3104761: Add and enable [Entity Blocks] module ( ~1.0 )
 */
function varbase_layout_builder_update_8101() {
  if (!\Drupal::moduleHandler()->moduleExists('entity_block')) {
    \Drupal::service('module_installer')->install(['entity_block'], FALSE);
  }
}

/**
 * Issue #3169416: Theme Layout Builder Modal and Media Library to look like.
 *
 * Claro admin theme.
 */
function varbase_layout_builder_update_8102() {

  if (!version_compare(\Drupal::VERSION, '8.8.0', 'lt')) {
    if (!\Drupal::service('theme_handler')->themeExists('claro')) {

      // Install Claro theme.
      \Drupal::service('theme_installer')->install(['claro'], FALSE);
    }

    if (\Drupal::moduleHandler()->moduleExists('media_library_theme_reset')) {
      \Drupal::service('module_installer')->uninstall(['media_library_theme_reset'], FALSE);
    }

    $config_factory = \Drupal::service('config.factory')->getEditable('varbase_layout_builder.settings');
    $config_factory->set('use_claro', 1)->save(TRUE);
  }
}

/**
 * Issue #3170980: Add Layout Builder Component Attributes module.
 */
function varbase_layout_builder_update_8103() {
  if (!\Drupal::moduleHandler()->moduleExists('layout_builder_component_attributes')) {
    \Drupal::service('module_installer')->install(['layout_builder_component_attributes'], FALSE);
  }
}
Loading