Commit 13c8a916 authored by Balint Pekker's avatar Balint Pekker Committed by Brian Osborne
Browse files

Issue #3297503 by balintpekker, bkosborne, Project Update Bot, mglaman,...

Issue #3297503 by balintpekker, bkosborne, Project Update Bot, mglaman, andregp, S3b0uN3t, marciaibanez: Automated Drupal 10 compatibility fixes
parent f7ca0425
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
name: Layout Builder Styles
description: Apply styles to blocks in Layout Builder.
core_version_requirement: ^8.7.7 || ^9
core_version_requirement: ^8.7.7 || ^9 || ^10
type: module
package: Layout Builder
dependencies:
+2 −0
Original line number Diff line number Diff line
@@ -136,6 +136,7 @@ function layout_builder_styles_update_8003() {
    ->loadByProperties([
      'type' => LayoutBuilderStyleInterface::TYPE_COMPONENT,
    ]);
  /** @var \Drupal\layout_builder_styles\Entity\LayoutBuilderStyle $style */
  foreach ($styles as $style) {
    $restrictions = $style->getBlockRestrictions();
    foreach ($restrictions as $key => $allowed) {
@@ -166,6 +167,7 @@ function layout_builder_styles_update_8004() {
    ->getStorage('layout_builder_style')
    ->loadByProperties();
  $weight = 0;
  /** @var \Drupal\layout_builder_styles\Entity\LayoutBuilderStyle $style */
  foreach ($styles as $style) {
    // Re-save styles with weight value.
    $style->set('weight', $weight);
+4 −5
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ function _layout_builder_styles_submit_block_form(array $form, FormStateInterfac
 * Modify the configuration form for layout builder sections (layouts).
 */
function layout_builder_styles_form_layout_builder_configure_section_alter(&$form, FormStateInterface $form_state, $form_id) {
  /** @var \Drupal\layout_builder_styles\Form\ConfigureSectionForm $formObject */
  $formObject = $form_state->getFormObject();
  $layout_id = $formObject->getLayout()->getPluginId();
  $allStyles = _layout_builder_styles_retrieve_by_type(LayoutBuilderStyleInterface::TYPE_SECTION);
@@ -136,6 +137,7 @@ function _layout_builder_styles_retrieve_by_type($type) {
 * storage.
 */
function _layout_builder_styles_submit_section_form(array $form, FormStateInterface $formState) {
  /** @var \Drupal\layout_builder_styles\Form\ConfigureSectionForm $formObject */
  $formObject = $formState->getFormObject();
  $config = $formObject->getLayout()->getConfiguration();
  if (!$config) {
@@ -176,6 +178,7 @@ function _layout_builder_styles_add_style_selection_form_elements(array &$form,

  foreach ($groups as $group) {
    // Group ID to group.
    /** @var \Drupal\layout_builder_styles\Entity\LayoutBuilderStyleGroup $group */
    $group = $group_storage->load($group);

    // Since we reference $style->$group by $group->$id, let's shortcut this.
@@ -268,7 +271,6 @@ function layout_builder_styles_preprocess_layout(&$variables) {
  // Apply a configured style to a layout by adding the style's CSS classes.
  if (isset($variables['settings']['layout_builder_styles_style'])) {
    $selected = $variables['settings']['layout_builder_styles_style'];
    /** @var \Drupal\layout_builder_styles\LayoutBuilderStyleInterface $style */

    // Convert single selection to an array for consistent processing.
    if (!is_array($selected)) {
@@ -285,6 +287,7 @@ function layout_builder_styles_preprocess_layout(&$variables) {
        continue;
      }
      if ($layout_style = \Drupal::entityTypeManager()->getStorage('layout_builder_style')->load($stylename)) {
        /** @var \Drupal\layout_builder_styles\LayoutBuilderStyleInterface $layout_style */
        $classes = \preg_split('(\r\n|\r|\n)', $layout_style->getClasses());
        $grouped_classes = array_merge($grouped_classes, $classes);
        $variables['#cache']['tags'][] = 'config:layout_builder_styles.style.' . $layout_style->id();
@@ -305,10 +308,6 @@ function layout_builder_styles_preprocess_layout(&$variables) {
 *
 * This is necessary to groom submitted styles where multiple styles are allowed
 *
 *
 * @param string|array $submittedStyles
 *   The submitted style(s).
 *
 * @return string|array
 *   The submitted style(s), now formatted correctly for saving.
 */
+6 −6
Original line number Diff line number Diff line
<?php

use \Drupal\layout_builder_styles\LayoutBuilderStyleInterface;
use \Drupal\layout_builder_styles\Entity\LayoutBuilderStyleGroup;
use \Drupal\layout_builder_styles\LayoutBuilderStyleGroupInterface;


/**
 * @file
 * Post-update functions for Layout Builder Styles module.
 */

use Drupal\layout_builder_styles\LayoutBuilderStyleInterface;
use Drupal\layout_builder_styles\Entity\LayoutBuilderStyleGroup;

/**
 * Add newly-available layout restriction value to existing style entities.
 */
@@ -17,6 +15,7 @@ function layout_builder_styles_post_update_update_add_layout_restrictions() {
  $styles = \Drupal::entityTypeManager()
    ->getStorage('layout_builder_style')
    ->loadByProperties();
  /** @var \Drupal\layout_builder_styles\Entity\LayoutBuilderStyle $style */
  foreach ($styles as $style) {
    // Re-save existing styles with empty layout restrictions.
    if ($style->getType() === LayoutBuilderStyleInterface::TYPE_SECTION) {
@@ -98,6 +97,7 @@ function layout_builder_styles_post_update_add_group() {
    $styles = \Drupal::entityTypeManager()
      ->getStorage('layout_builder_style')
      ->loadByProperties();
    /** @var \Drupal\layout_builder_styles\Entity\LayoutBuilderStyle $style */
    foreach ($styles as $style) {
      if (empty($style->getGroup())) {
        $style->set('group', $group->id());
+2 −2
Original line number Diff line number Diff line
@@ -134,14 +134,14 @@ class LayoutBuilderStyle extends ConfigEntityBase implements LayoutBuilderStyleI
   * {@inheritdoc}
   */
  public function getBlockRestrictions() {
    return isset($this->block_restrictions) ? $this->block_restrictions : [];
    return $this->block_restrictions ?? [];
  }

  /**
   * {@inheritdoc}
   */
  public function getLayoutRestrictions() {
    return isset($this->layout_restrictions) ? $this->layout_restrictions : [];
    return $this->layout_restrictions ?? [];
  }

}
Loading